diff --git a/game.js b/game.js index b8c1b4e..5183331 100644 --- a/game.js +++ b/game.js @@ -77,31 +77,16 @@ function renderTime(time) { return hours + ":" + minutes + ":" + seconds + " " + ampm; } -function updateWorldInfo(state) { - Object.entries(state.info).forEach(([key, val]) => { - - if (val.type == "meter") { - const field = document.querySelector("#world-info-" + key + " > .stat-bar"); - field.style.width = (val.value / val.max * 100) + "%"; - } else if (val.type == "counter") { - const field = document.querySelector("#world-info-" + key); - field.innerText = val.name + ": " + val.render; - } - - }); -} - -function updatePlayerInfo(state) { - Object.entries(state.player.stats).forEach(([key, val]) => { +function updateStatDisplay(stats, statType) { + Object.entries(stats).forEach(([key, val]) => { if (val.type == "meter") { - const field = document.querySelector("#player-info-" + key + " > .stat-bar"); + const field = document.querySelector("#" + statType + "-info-" + key + " > .stat-bar"); field.style.width = (val.value / val.max * 100) + "%"; } else if (val.type == "counter") { - const field = document.querySelector("#player-info-" + key); - field.innerText = val.name + ": " + val.value; + const field = document.querySelector("#" + statType + "-info-" + key); + field.innerText = val.name + ": " + (val.render !== undefined ? val.render : val.value); } - }); } diff --git a/satiate.js b/satiate.js index 3d9d5ae..74d2b9f 100644 --- a/satiate.js +++ b/satiate.js @@ -24,8 +24,9 @@ function print(lines) { function refresh() { updateRoom(state); - updateWorldInfo(state); - updatePlayerInfo(state); + updateStatDisplay(state.info, "world"); + updateStatDisplay(state.player.stats, "player"); + updateStatDisplay(state.world[state.player.location].data.stats, "area"); if (refreshHook) { refreshHook(state) diff --git a/stories/demo.js b/stories/demo.js index 0187dac..447d182 100644 --- a/stories/demo.js +++ b/stories/demo.js @@ -36,9 +36,25 @@ stories.push({ }, "enter": (room, state) => { print(["*sound of you entering your house*"]); + + startTimer({ + id: "room-counter", + func: state => { + state.world["Home"].data.stats.number.value += 1; + return true; + }, + delay: 1000, + loop: true, + classes: [ + + ], + room: "Home", + }, state); }, "exit": (room, state) => { print(["You are exiting your house"]); + + stopRoomTimers("Home", state); }, "actions": [ { @@ -95,9 +111,15 @@ stories.push({ "hooks": [ (room, state) => { print(["This is a test of the hooks"]); + return true; } - ] + ], + "data": { + "stats": { + number: {name: "Seconds In Room", type: "counter", value: 0, color: "rgb(255,0,0)"} + } + } }, "Locked Room": { "id": "Locked Room", @@ -134,6 +156,11 @@ stories.push({ } ] } + }, + "data": { + "stats": { + + } } } } diff --git a/stories/fen-snack.js b/stories/fen-snack.js index 60bc376..1c78d11 100644 --- a/stories/fen-snack.js +++ b/stories/fen-snack.js @@ -244,6 +244,11 @@ stories.push({ } ] } + }, + "data": { + "stats": { + + } } }, intestines: { @@ -344,7 +349,12 @@ stories.push({ ] } - ] + ], + "data": { + "stats": { + + } + } }, bowels: { id: "bowels", @@ -453,7 +463,12 @@ stories.push({ ] } - ] + ], + "data": { + "stats": { + + } + } }, "digested-stomach": { id: "digested-stomach", @@ -465,6 +480,11 @@ stories.push({ playSfx("sfx/bowels-churn-safe.ogg"); stopClassTimers("alive", state); print(["You slump down in the acidic pit, curling up as it begins to churn you down to chyme. Fen's stomach snarls and bubbles for the next few minutes...and then you're gone~",newline,"Nothing's left but a bit of padding on your predator's gut..."]); + }, + "data": { + "stats": { + + } } }, "digested-intestines": { @@ -477,6 +497,11 @@ stories.push({ playSfx("sfx/bowels-churn-safe.ogg"); stopClassTimers("alive", state); print(["Fen's intestines clench and squeeze, melting you down into slop and soaking you up like a sponge.",newline,"Nothing's left but a bit of padding on your predator's hips..."]); + }, + "data": { + "stats": { + + } } }, "digested-bowels": { @@ -489,6 +514,11 @@ stories.push({ playSfx("sfx/bowels-churn-danger.ogg"); stopClassTimers("alive", state); print(["A powerful ripple of muscle pins you in a vice-grip of flesh - and within seconds, you're part of Fen's bowels.",newline,"Nothing's left but a bit of padding on your predator's ass..."]); + }, + "data": { + "stats": { + + } } } } diff --git a/world.js b/world.js index 92a34b4..4d2cde0 100644 --- a/world.js +++ b/world.js @@ -142,6 +142,8 @@ function goToRoom(dest, state) { function updateRoom(state) { const name = state.player.location; const room = state.world[name]; + + createStatDisplays(room.data.stats, "area"); if (!state.player.rooms[room.id]) { state.player.rooms[room.id] = {};