|
|
@@ -11,13 +11,15 @@ dirs = { |
|
|
"descend": "Down" |
|
|
"descend": "Down" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function initWorld(state) { |
|
|
|
|
|
|
|
|
function initWorld(worldChoice, state) { |
|
|
|
|
|
state.world = worlds[worldChoice]; |
|
|
initRoomState(state); |
|
|
initRoomState(state); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function initRoomState(state) { |
|
|
function initRoomState(state) { |
|
|
|
|
|
console.log(state.world); |
|
|
state.player.rooms = {}; |
|
|
state.player.rooms = {}; |
|
|
Object.entries(world).forEach(([key, val]) => { |
|
|
|
|
|
|
|
|
Object.entries(state.world).forEach(([key, val]) => { |
|
|
state.player.rooms[key] = {}; |
|
|
state.player.rooms[key] = {}; |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
@@ -34,8 +36,8 @@ function removeActionDescription() { |
|
|
descHolder.textContent = ""; |
|
|
descHolder.textContent = ""; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function moveToRoom(dest, state) { |
|
|
|
|
|
const room = world[dest]; |
|
|
|
|
|
|
|
|
function moveToRoom(dest, state, announce=true) { |
|
|
|
|
|
const room = state.world[dest]; |
|
|
|
|
|
|
|
|
console.log(room); |
|
|
console.log(room); |
|
|
|
|
|
|
|
|
@@ -47,11 +49,14 @@ function moveToRoom(dest, state) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (announce) |
|
|
|
|
|
state.world[dest].move(state.world[dest], state); |
|
|
|
|
|
|
|
|
updateRoom(dest, state); |
|
|
updateRoom(dest, state); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function updateRoom(dest, state) { |
|
|
function updateRoom(dest, state) { |
|
|
const room = world[dest]; |
|
|
|
|
|
|
|
|
const room = state.world[dest]; |
|
|
|
|
|
|
|
|
if (!state.player.rooms[dest.id]) { |
|
|
if (!state.player.rooms[dest.id]) { |
|
|
state.player.rooms[dest.id] = {}; |
|
|
state.player.rooms[dest.id] = {}; |
|
|
@@ -80,7 +85,7 @@ function updateRoom(dest, state) { |
|
|
if (room.exits) { |
|
|
if (room.exits) { |
|
|
Object.entries(room.exits).forEach(([dir, exit]) => { |
|
|
Object.entries(room.exits).forEach(([dir, exit]) => { |
|
|
const button = document.querySelector("#move-" + dir); |
|
|
const button = document.querySelector("#move-" + dir); |
|
|
const dest = world[exit.target]; |
|
|
|
|
|
|
|
|
const dest = state.world[exit.target]; |
|
|
|
|
|
|
|
|
// don't even show an exit if this fails! |
|
|
// don't even show an exit if this fails! |
|
|
|
|
|
|
|
|
@@ -156,71 +161,78 @@ function updateRoom(dest, state) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
world = { |
|
|
|
|
|
"Home": { |
|
|
|
|
|
"id": "Home", |
|
|
|
|
|
"name": "Home", |
|
|
|
|
|
"desc": "Where the wifi autoconnects", |
|
|
|
|
|
"actions": [ |
|
|
|
|
|
{ |
|
|
|
|
|
"name": "Squint", |
|
|
|
|
|
"desc": "Squint in a very aggressive manner", |
|
|
|
|
|
"execute": (self, state) => { |
|
|
|
|
|
state.player.rooms[self.id].squinted = true; |
|
|
|
|
|
print(["You stare at the wall and notice a secret door. But where is the key?"]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
worlds = { |
|
|
|
|
|
"demo": { |
|
|
|
|
|
"Home": { |
|
|
|
|
|
"id": "Home", |
|
|
|
|
|
"name": "Home", |
|
|
|
|
|
"desc": "Where the wifi autoconnects", |
|
|
|
|
|
"move": (self, state) => { |
|
|
|
|
|
print(["You go back to your living room"]); |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
|
|
|
"name": "Find Keys", |
|
|
|
|
|
"desc": "Find your keys", |
|
|
|
|
|
"execute": (self, state) => { |
|
|
|
|
|
state.player.items.keys.push("Locked Room"); |
|
|
|
|
|
print(["You found your keys under the couch cushions"]); |
|
|
|
|
|
|
|
|
"actions": [ |
|
|
|
|
|
{ |
|
|
|
|
|
"name": "Squint", |
|
|
|
|
|
"desc": "Squint in a very aggressive manner", |
|
|
|
|
|
"execute": (self, state) => { |
|
|
|
|
|
state.player.rooms[self.id].squinted = true; |
|
|
|
|
|
print(["You stare at the wall and notice a secret door. But where is the key?"]); |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
"show": [ |
|
|
|
|
|
(self, state) => { |
|
|
|
|
|
return state.player.rooms[self.id].squinted; |
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
"name": "Find Keys", |
|
|
|
|
|
"desc": "Find your keys", |
|
|
|
|
|
"execute": (self, state) => { |
|
|
|
|
|
state.player.items.keys.push("Locked Room"); |
|
|
|
|
|
print(["You found your keys under the couch cushions"]); |
|
|
}, |
|
|
}, |
|
|
(self, state) => { |
|
|
|
|
|
return !state.player.items.keys.includes("Locked Room"); |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
], |
|
|
|
|
|
"exits": { |
|
|
|
|
|
"up": { |
|
|
|
|
|
"target": "Locked Room", |
|
|
|
|
|
"desc": "It's locked!", |
|
|
|
|
|
"move": "You enter the secret locked room", |
|
|
|
|
|
"conditions": [ |
|
|
|
|
|
(self, state) => { |
|
|
|
|
|
return state.player.items.keys.includes("Locked Room"); |
|
|
|
|
|
} |
|
|
|
|
|
], |
|
|
|
|
|
"show": [ |
|
|
|
|
|
(self, state) => { |
|
|
|
|
|
console.log(self); |
|
|
|
|
|
return state.player.rooms[self.id].squinted; |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
"show": [ |
|
|
|
|
|
(self, state) => { |
|
|
|
|
|
return state.player.rooms[self.id].squinted; |
|
|
|
|
|
}, |
|
|
|
|
|
(self, state) => { |
|
|
|
|
|
return !state.player.items.keys.includes("Locked Room"); |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
], |
|
|
|
|
|
"exits": { |
|
|
|
|
|
"up": { |
|
|
|
|
|
"target": "Locked Room", |
|
|
|
|
|
"desc": "It's locked!", |
|
|
|
|
|
"conditions": [ |
|
|
|
|
|
(self, state) => { |
|
|
|
|
|
return state.player.items.keys.includes("Locked Room"); |
|
|
|
|
|
} |
|
|
|
|
|
], |
|
|
|
|
|
"show": [ |
|
|
|
|
|
(self, state) => { |
|
|
|
|
|
console.log(self); |
|
|
|
|
|
return state.player.rooms[self.id].squinted; |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
"hooks": [ |
|
|
|
|
|
(self, state) => { |
|
|
|
|
|
print(["This is a test of the hooks"]); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
}, |
|
|
}, |
|
|
"hooks": [ |
|
|
|
|
|
(self, state) => { |
|
|
|
|
|
print(["This is a test of the hooks"]); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
|
|
|
}, |
|
|
|
|
|
"Locked Room": { |
|
|
|
|
|
"id": "Locked Room", |
|
|
|
|
|
"name": "Locked Room", |
|
|
|
|
|
"desc": "Super seecret", |
|
|
|
|
|
"exits": { |
|
|
|
|
|
"down": { |
|
|
|
|
|
"target": "Home", |
|
|
|
|
|
"desc": "Back to home", |
|
|
|
|
|
"move": "You dab" |
|
|
|
|
|
|
|
|
"Locked Room": { |
|
|
|
|
|
"id": "Locked Room", |
|
|
|
|
|
"name": "Locked Room", |
|
|
|
|
|
"desc": "Super seecret", |
|
|
|
|
|
"move": (self, state) => { |
|
|
|
|
|
print(["You enter the locked room. wowie!"]); |
|
|
|
|
|
}, |
|
|
|
|
|
"exits": { |
|
|
|
|
|
"down": { |
|
|
|
|
|
"target": "Home", |
|
|
|
|
|
"desc": "Back to home", |
|
|
|
|
|
"move": "You dab" |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|