diff --git a/game.js b/game.js index e2fbabc..1041ee5 100644 --- a/game.js +++ b/game.js @@ -34,6 +34,18 @@ function initGamePostSetup(state) { field.appendChild(label); 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); } @@ -76,6 +88,9 @@ function updatePlayerInfo(state) { if (val.type == "meter") { const field = document.querySelector("#player-info-" + key + " > .stat-bar"); 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; } }); diff --git a/stories/demo.js b/stories/demo.js index 0648c9f..eef332d 100644 --- a/stories/demo.js +++ b/stories/demo.js @@ -9,6 +9,7 @@ stories.push({ "setup": state => { state.info.time = 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 => { print(["don't fall down the stairs ok"]);