|
- dirs = {
- "up-left": "Northwest",
- "up": "North",
- "up-right": "Northeast",
- "left": "West",
- "right": "East",
- "down-left": "Southwest",
- "down": "South",
- "down-right": "Southeast",
- "ascend": "Up",
- "descend": "Down"
- }
-
- function moveToRoom(dest, state) {
- updateRoom(dest, state);
- }
-
- function updateRoom(dest, state) {
- const room = world[dest];
-
- const areaName = document.querySelector("#area-name");
- const areaDesc = document.querySelector("#area-desc");
-
- areaName.innerText = room.name;
- areaDesc.innerText = room.desc;
-
- 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, 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.addEventListener("click", () => {
- // todo: log
- moveToRoom(exit.target, state);
- })
- });
- }
-
- world = {
- "Home": {
- "name": "Home",
- "desc": "Where the wifi autoconnects",
- "exits": {
- "up": {
- "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"
- }
- }
- }
- }
|