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] = {};