浏览代码

Consolidate info update into one function; add area info

tags/v0.1.2
Fen Dweller 6 年前
父节点
当前提交
6810672d2d
共有 4 个文件被更改,包括 21 次插入23 次删除
  1. +5
    -20
      game.js
  2. +3
    -2
      satiate.js
  3. +11
    -1
      stories/demo.js
  4. +2
    -0
      world.js

+ 5
- 20
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);
}

});
}



+ 3
- 2
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)


+ 11
- 1
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": {
}
}
}
}


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


正在加载...
取消
保存