Browse Source

Only create stats once for a room and clear room stats first

tags/v0.1.2
Fen Dweller 6 years ago
parent
commit
1518d2c6eb
2 changed files with 7 additions and 3 deletions
  1. +3
    -1
      game.js
  2. +4
    -2
      world.js

+ 3
- 1
game.js View File

@@ -18,7 +18,9 @@ function initGame(story, state) {
} }


function createStatDisplays(stats, statType) { function createStatDisplays(stats, statType) {
const holder = document.querySelector("#" + statType + "-info")
const holder = document.querySelector("#" + statType + "-info");
holder.innerHTML = "";

Object.entries(stats).forEach(([key, val]) => { Object.entries(stats).forEach(([key, val]) => {


if (val.type == "meter") { if (val.type == "meter") {


+ 4
- 2
world.js View File

@@ -111,6 +111,8 @@ function moveToRoom(src, exit, dest, state) {


resetControls(state); resetControls(state);


createStatDisplays(room.data.stats, "area");

refresh(); refresh();
} }


@@ -136,14 +138,14 @@ function goToRoom(dest, state) {


resetControls(state); resetControls(state);


createStatDisplays(room.data.stats, "area");

refresh(); refresh();
} }


function updateRoom(state) { function updateRoom(state) {
const name = state.player.location; const name = state.player.location;
const room = state.world[name]; const room = state.world[name];
createStatDisplays(room.data.stats, "area");


if (!state.player.rooms[room.id]) { if (!state.player.rooms[room.id]) {
state.player.rooms[room.id] = {}; state.player.rooms[room.id] = {};


Loading…
Cancel
Save