Browse Source

Add number stat type

tags/v0.1.2
Fen Dweller 6 years ago
parent
commit
03d7d17d1b
2 changed files with 16 additions and 0 deletions
  1. +15
    -0
      game.js
  2. +1
    -0
      stories/demo.js

+ 15
- 0
game.js View File

@@ -34,6 +34,18 @@ function initGamePostSetup(state) {
field.appendChild(label); field.appendChild(label);
field.appendChild(bar); field.appendChild(bar);


holder.appendChild(field);
} else if (val.type == "counter") {
const field = document.createElement("div");
field.id = "player-info-" + key;
field.setAttribute("max", val.max);
field.setAttribute("value", val.value);
field.classList.add("counter-holder");

const counter = document.createElement("div");
counter.classList.add("stat-counter");
field.appendChild(counter);

holder.appendChild(field); holder.appendChild(field);
} }


@@ -76,6 +88,9 @@ function updatePlayerInfo(state) {
if (val.type == "meter") { if (val.type == "meter") {
const field = document.querySelector("#player-info-" + key + " > .stat-bar"); const field = document.querySelector("#player-info-" + key + " > .stat-bar");
field.style.width = (val.value / val.max * 100) + "%"; field.style.width = (val.value / val.max * 100) + "%";
} else if (val.type == "counter") {
const field = document.querySelector("#player-info-" + key + " > .stat-counter");
field.innerText = val.name + ": " + val.value;
} }


}); });


+ 1
- 0
stories/demo.js View File

@@ -9,6 +9,7 @@ stories.push({
"setup": state => { "setup": state => {
state.info.time = 0; state.info.time = 0;
state.player.stats.oofs = {name: "Oofs", type: "meter", value: 0, max: 10, color: "rgb(255,0,0)"}; state.player.stats.oofs = {name: "Oofs", type: "meter", value: 0, max: 10, color: "rgb(255,0,0)"};
state.player.stats.number = {name: "Number", type: "counter", value: 0, max: 10, color: "rgb(255,255,255)"};
}, },
"intro": state => { "intro": state => {
print(["don't fall down the stairs ok"]); print(["don't fall down the stairs ok"]);


Loading…
Cancel
Save