Просмотр исходного кода

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

tags/v0.1.0
Fen Dweller 6 лет назад
Родитель
Сommit
b3cb1c60b8
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 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

function init() {


+ 19
- 5
world.js Просмотреть файл

@@ -21,8 +21,8 @@ function updateRoom(dest, state) {
const areaName = document.querySelector("#area-name");
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");

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

@@ -42,9 +42,18 @@ function updateRoom(dest, state) {
const button = document.querySelector("#move-" + dir);
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 (exit.conditions) {
console.log(exit.conditions);
if (!exit.conditions.every(cond => cond(state))) {
return;
}
@@ -52,7 +61,6 @@ function updateRoom(dest, state) {

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

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

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


Загрузка…
Отмена
Сохранить