From db1121d9898ce644d13eab8b776ca316d7abf796 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sun, 6 Jan 2019 13:01:16 -0600 Subject: [PATCH] Audio information is included with each game. Reorganized a bit. --- audio.js | 12 ++-- satiate.js | 2 +- world.js | 162 ++++++++++++++++++++++++++++------------------------- 3 files changed, 94 insertions(+), 82 deletions(-) diff --git a/audio.js b/audio.js index 1736666..327e1f0 100644 --- a/audio.js +++ b/audio.js @@ -169,13 +169,15 @@ function checkCache(type, name, hit, miss) { } } -function initAudio() { - audioContext = new (window.AudioContext || window.webkitAudioContext)(); - - console.log("Initialized audio context"); - console.log(audioContext); +function initAudio(game, state) { + if (!audioContext) + audioContext = new (window.AudioContext || window.webkitAudioContext)(); createCache(); + + games[game].sounds.forEach(sound => { + loadAudio(sound); + }); } // caching stuff here diff --git a/satiate.js b/satiate.js index 8de413f..ecce3c5 100644 --- a/satiate.js +++ b/satiate.js @@ -30,7 +30,7 @@ function print(lines) { function init() { initWorld("demo", state); - initAudio(); + initAudio("demo", state); goToRoom("Home", state); } diff --git a/world.js b/world.js index d09c617..47cb080 100644 --- a/world.js +++ b/world.js @@ -12,12 +12,11 @@ dirs = { } function initWorld(worldChoice, state) { - state.world = worlds[worldChoice]; + state.world = games[worldChoice]["world"]; initRoomState(state); } function initRoomState(state) { - console.log(state.world); state.player.rooms = {}; Object.entries(state.world).forEach(([key, val]) => { state.player.rooms[key] = {}; @@ -37,7 +36,6 @@ function removeActionDescription() { } function moveToRoom(src, exit, dest, state) { - console.log(state) const room = state.world[dest]; if (exit.hooks) { @@ -181,85 +179,97 @@ function updateRoom(dest, state) { } -worlds = { +games = { "demo": { - "Home": { - "id": "Home", - "name": "Home", - "desc": "Where the wifi autoconnects", - "move": (room, state) => { - print(["You go back to your living room"]); - }, - "actions": [ - { - "name": "Squint", - "desc": "Squint in a very aggressive manner", - "execute": (room, state) => { - state.player.rooms[room.id].squinted = true; - print(["You stare at the wall and notice a secret door. But where is the key?"]); - } + "id": "demo", + "sounds": [ + "sfx/oof.ogg" + ], + "world": { + "Home": { + "id": "Home", + "name": "Home", + "desc": "Where the wifi autoconnects", + "move": (room, state) => { + print(["You go back to your living room"]); }, - { - "name": "Find Keys", - "desc": "Find your keys", - "execute": (room, 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": (room, state) => { + state.player.rooms[room.id].squinted = true; + print(["You stare at the wall and notice a secret door. But where is the key?"]); + } }, - "show": [ - (room, state) => { - return state.player.rooms[room.id].squinted; + { + "name": "Find Keys", + "desc": "Find your keys", + "execute": (room, state) => { + state.player.items.keys.push("Locked Room"); + print(["You found your keys under the couch cushions"]); }, - (room, state) => { - return !state.player.items.keys.includes("Locked Room"); - } - ] - } - ], - "exits": { - "up": { - "target": "Locked Room", - "desc": "It's locked!", - "conditions": [ - (room, state) => { - return state.player.items.keys.includes("Locked Room"); - } - ], - "show": [ - (room, state) => { - console.log(room); - return state.player.rooms[room.id].squinted; - } - ] - } - }, - "hooks": [ - (room, state) => { - print(["This is a test of the hooks"]); - return true; - } - ] - }, - "Locked Room": { - "id": "Locked Room", - "name": "Locked Room", - "desc": "Super seecret", - "move": (room, state) => { - print(["You enter the locked room. wowie!"]); + "show": [ + (room, state) => { + return state.player.rooms[room.id].squinted; + }, + (room, state) => { + return !state.player.items.keys.includes("Locked Room"); + } + ] + } + ], + "exits": { + "up": { + "target": "Locked Room", + "desc": "It's locked!", + "conditions": [ + (room, state) => { + return state.player.items.keys.includes("Locked Room"); + } + ], + "show": [ + (room, state) => { + return state.player.rooms[room.id].squinted; + } + ] + } + }, + "hooks": [ + (room, state) => { + print(["This is a test of the hooks"]); + return true; + } + ] }, - "exits": { - "down": { - "target": "Home", - "desc": "Back to home", - "hooks": [ - (room, exit, state) => { - print(["Potato"]); - console.log(room); - console.log(exit); - console.log(state); - return true; + "Locked Room": { + "id": "Locked Room", + "name": "Locked Room", + "desc": "Super seecret", + "move": (room, state) => { + print(["You enter the locked room. wowie!"]); + }, + "actions": [ + { + name: "Oof", + desc: "Oof", + execute: (room, state) => { + print(["Oof"]); + playSfx("sfx/oof.ogg"); } - ] + } + ], + "exits": { + "down": { + "target": "Home", + "desc": "Back to home", + "hooks": [ + (room, exit, state) => { + print(["Potato"]); + return true; + } + ] + } } } }