Преглед на файлове

Added print fn, replaced innerText w/ textContent, worked on more conditions

tags/v0.1.0
Fen Dweller преди 7 години
родител
ревизия
b3cb1c60b8
No known key found for this signature in database GPG Key ID: E80B35A6F11C3656
променени са 2 файла, в които са добавени 30 реда и са изтрити 5 реда
  1. +11
    -0
      satiate.js
  2. +19
    -5
      world.js

+ 11
- 0
satiate.js Целия файл

@@ -12,6 +12,17 @@ let state = {
} }
} }


function print(lines) {
(lines.concat([String.fromCharCode(160)])).forEach(line => {
const log = document.querySelector("#log");
const div = document.createElement("div");

div.textContent = line;

log.appendChild(div);
});
}

// setup the game // setup the game


function init() { function init() {


+ 19
- 5
world.js Целия файл

@@ -21,8 +21,8 @@ function updateRoom(dest, state) {
const areaName = document.querySelector("#area-name"); const areaName = document.querySelector("#area-name");
const areaDesc = document.querySelector("#area-desc"); const areaDesc = document.querySelector("#area-desc");


areaName.innerText = room.name;
areaDesc.innerText = room.desc;
areaName.textContent = room.name;
areaDesc.textContent = room.desc;


const holder = document.querySelector("#move-holder"); const holder = document.querySelector("#move-holder");


@@ -34,7 +34,7 @@ function updateRoom(dest, state) {
button.id = "move-" + dir; button.id = "move-" + dir;
button.classList.add("disabled"); button.classList.add("disabled");
button.setAttribute("disabled", "true"); button.setAttribute("disabled", "true");
button.innerText = dirs[dir];
button.textContent = dirs[dir];
holder.appendChild(button); holder.appendChild(button);
}); });


@@ -42,9 +42,18 @@ function updateRoom(dest, state) {
const button = document.querySelector("#move-" + dir); const button = document.querySelector("#move-" + dir);
const dest = world[exit.target]; const dest = world[exit.target];


// don't even show an exit if this fails!

if (exit.show) {
if (!exit.show.every(cond => cond(state))) {
return;
}
}

button.textContent = dest.name;

// if any condition fails, don't enable/add a listener // if any condition fails, don't enable/add a listener
if (exit.conditions) { if (exit.conditions) {
console.log(exit.conditions);
if (!exit.conditions.every(cond => cond(state))) { if (!exit.conditions.every(cond => cond(state))) {
return; return;
} }
@@ -52,7 +61,6 @@ function updateRoom(dest, state) {


button.classList.remove("disabled"); button.classList.remove("disabled");
button.removeAttribute("disabled"); button.removeAttribute("disabled");
button.innerText = dest.name;


button.addEventListener("click", () => { button.addEventListener("click", () => {
// todo: log // todo: log
@@ -74,6 +82,12 @@ world = {
state => { state => {
return state.player.items.keys.includes("Locked Room"); return state.player.items.keys.includes("Locked Room");
} }
],

"show": [
state => {
return state.player.items.keys.includes("Locked Room");
}
] ]
} }
} }


Loading…
Отказ
Запис