From 6810672d2d87920d71b9d490938dcac369afa8f8 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Thu, 8 Aug 2019 13:17:48 -0400 Subject: [PATCH 1/3] Consolidate info update into one function; add area info --- game.js | 25 +++++-------------------- satiate.js | 5 +++-- stories/demo.js | 12 +++++++++++- world.js | 2 ++ 4 files changed, 21 insertions(+), 23 deletions(-) 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..846033e 100644 --- a/stories/demo.js +++ b/stories/demo.js @@ -97,7 +97,12 @@ stories.push({ 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 +139,11 @@ stories.push({ } ] } + }, + "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] = {}; From f26e585db91466a7bb2ebe5d16fc24ffd77ac0b7 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Thu, 8 Aug 2019 13:31:54 -0400 Subject: [PATCH 2/3] Add simple example of room stats --- stories/demo.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/stories/demo.js b/stories/demo.js index 846033e..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,6 +111,7 @@ stories.push({ "hooks": [ (room, state) => { print(["This is a test of the hooks"]); + return true; } ], From 6411a3cd060d3ed696e53ae7c908e8274f3911ff Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Thu, 8 Aug 2019 13:36:56 -0400 Subject: [PATCH 3/3] Add missing data entries --- stories/fen-snack.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) 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": { + + } } } }