diff --git a/satiate.html b/satiate.html
index 9b99b37..907aa8d 100644
--- a/satiate.html
+++ b/satiate.html
@@ -36,27 +36,12 @@
-
-
-
-
this is a description of your action
- beep beep
-
-
-
-
-
-
-
-
-
-
diff --git a/satiate.js b/satiate.js
index d95f7c2..808dece 100644
--- a/satiate.js
+++ b/satiate.js
@@ -2,28 +2,22 @@
let audioContext;
+let state = {
+ player: {
+ items: {
+ keys: [
+ "Locked Room"
+ ]
+ }
+ }
+}
+
// setup the game
function init() {
initAudio();
- document.querySelector("#load").addEventListener("click", () => {
- loadAudio("sfx/test.ogg");
- loadAudio("loop/test.ogg");
- });
-
- document.querySelector("#sfx").addEventListener("click", () => {
- playSfx("sfx/test.ogg");
- });
-
- document.querySelector("#loop").addEventListener("click", () => {
- playLoop("loop/test.ogg");
- });
-
- document.querySelector("#stop").addEventListener("click", () => {
- stopLoop("loop/test.ogg");
- });
-
+ moveToRoom("Home", state);
}
window.addEventListener("load", init);
diff --git a/world.js b/world.js
index 0e4fd8c..2cf034e 100644
--- a/world.js
+++ b/world.js
@@ -11,7 +11,11 @@ dirs = {
"descend": "Down"
}
-function updateRoom(dest) {
+function moveToRoom(dest, state) {
+ updateRoom(dest, state);
+}
+
+function updateRoom(dest, state) {
const room = world[dest];
const areaName = document.querySelector("#area-name");
@@ -20,18 +24,40 @@ function updateRoom(dest) {
areaName.innerText = room.name;
areaDesc.innerText = room.desc;
- document.querySelectorAll(".move-button").forEach(button => {
- const dir = button.id.replace("move-", "");
+ const holder = document.querySelector("#move-holder");
+
+ holder.innerHTML = "";
+
+ Object.entries(dirs).forEach(([dir, name]) => {
+ const button = document.createElement("button");
+ button.classList.add("move-button")
+ button.id = "move-" + dir;
button.classList.add("disabled");
+ button.setAttribute("disabled", "true");
button.innerText = dirs[dir];
+ holder.appendChild(button);
});
- Object.entries(room.exits).forEach(([dir, val]) => {
+ Object.entries(room.exits).forEach(([dir, exit]) => {
const button = document.querySelector("#move-" + dir);
+ const dest = world[exit.target];
+
+ // 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;
+ }
+ }
button.classList.remove("disabled");
+ button.removeAttribute("disabled");
+ button.innerText = dest.name;
- button.innerText = val.target;
+ button.addEventListener("click", () => {
+ // todo: log
+ moveToRoom(exit.target, state);
+ })
});
}
@@ -41,8 +67,25 @@ world = {
"desc": "Where the wifi autoconnects",
"exits": {
"up": {
- "target": "Dennis",
- "desc": "The obvious exit, but better."
+ "target": "Locked Room",
+ "desc": "It's locked!",
+ "move": "You enter the secret locked room",
+ "conditions": [
+ state => {
+ return state.player.items.keys.includes("Locked Room");
+ }
+ ]
+ }
+ }
+ },
+ "Locked Room": {
+ "name": "Locked Room",
+ "desc": "Super seecret",
+ "exits": {
+ "down": {
+ "target": "Home",
+ "desc": "Back to home",
+ "move": "You dab"
}
}
}