From 18e8af98092ae3c232fdb60e9e1cd6974e916f68 Mon Sep 17 00:00:00 2001 From: jorsi Date: Sat, 30 May 2020 23:33:10 -0400 Subject: [PATCH] refactor audio-related code to use AudioLibrary module --- script/audioLibrary.js | 10 ++- script/events.js | 14 ++--- script/events/encounters.js | 20 +++--- script/events/global.js | 2 +- script/events/outside.js | 12 ++-- script/events/room.js | 20 +++--- script/events/setpieces.js | 26 ++++---- script/outside.js | 41 ++++++------ script/path.js | 9 +-- script/room.js | 122 ++++++++++++++++++------------------ script/ship.js | 12 ++-- script/space.js | 20 +++--- script/world.js | 30 ++++----- 13 files changed, 164 insertions(+), 174 deletions(-) diff --git a/script/audioLibrary.js b/script/audioLibrary.js index 39ceb6f..592c11e 100644 --- a/script/audioLibrary.js +++ b/script/audioLibrary.js @@ -124,5 +124,13 @@ var AudioLibrary = { CRASH: '/audio/crash.wav', REINFORCE_HULL: '/audio/reinforce-hull.wav', UPGRADE_ENGINE: '/audio/upgrade-engine.wav', - LIFT_OFF: '/audio/lift-off.wav' + LIFT_OFF: '/audio/lift-off.wav', + PUNCH: '/audio/punch.wav', + STAB: '/audio/stab.wav', + SWING: '/audio/swing.wav', + SLASH: '/audio/slash.wav', + THRUST: '/audio/thrust.wav', + SHOOT: '/audio/shoot.wav', + BLAST: '/audio/blast.wav', + TANGLE: '/audio/tangle.wav' }; \ No newline at end of file diff --git a/script/events.js b/script/events.js index f2cf6ab..6633eec 100644 --- a/script/events.js +++ b/script/events.js @@ -339,12 +339,12 @@ var Events = { eatMeat: function(btn) { Events.doHeal('cured meat', World.meatHeal(), btn); - AudioEngine.playSound(Events.SOUNDS['eat-meat']); + AudioEngine.playSound(AudioLibrary.EAT_MEAT); }, useMeds: function(btn) { Events.doHeal('medicine', World.medsHeal(), btn); - AudioEngine.playSound(Events.SOUNDS['use-meds']); + AudioEngine.playSound(AudioLibrary.USE_MEDS); }, useWeapon: function(btn) { @@ -447,7 +447,7 @@ var Events = { Events.updateFighterDiv(enemy); // play hit sound - AudioEngine.playSound(Events.SOUNDS['enemy-hit']); + AudioEngine.playSound(AudioLibrary.ENEMY_HIT); } } else { if(dmg == 'stun') { @@ -524,7 +524,7 @@ var Events = { clearTimeout(Events._enemyAttackTimer); Events.endEvent(); World.die(); - AudioEngine.playSound(Events.SOUNDS['lose-fight']); + AudioEngine.playSound(AudioLibrary.LOSE_FIGHT); } }); } @@ -542,7 +542,7 @@ var Events = { return; } Events.endFight(); - AudioEngine.playSound(Events.SOUNDS['win-fight']); + AudioEngine.playSound(AudioLibrary.WIN_FIGHT); $('#enemy').animate({opacity: 0}, 300, 'linear', function() { Engine.setTimeout(function() { var scene = Events.activeEvent().scenes[Events.activeScene]; @@ -1025,7 +1025,7 @@ var Events = { } else { var r = Math.floor(Math.random()*(possibleEvents.length)); Events.startEvent(possibleEvents[r]); - AudioEngine.playSound(Events.SOUNDS['trigger-event']); + AudioEngine.playSound(AudioLibrary.TRIGGER_EVENT); AudioEngine.playEventMusic(possibleEvents[r].audio); } } @@ -1047,7 +1047,7 @@ var Events = { // play audio only when fight is possible if (possibleFights.length > 0) { - AudioEngine.playSound(Events.SOUNDS['trigger-fight']); + AudioEngine.playSound(AudioLibrary.TRIGGER_FIGHT); AudioEngine.playEventMusic(possibleFights[r].audio); } }, diff --git a/script/events/encounters.js b/script/events/encounters.js index 9de0e86..61bc1b3 100644 --- a/script/events/encounters.js +++ b/script/events/encounters.js @@ -39,7 +39,7 @@ Events.Encounters = [ notification: _('a snarling beast leaps out of the underbrush') } }, - audio: '/audio/snarling-beast.wav' + audio: AudioLibrary.ENCOUNTER_SNARLING_BEAST }, { /* Gaunt Man */ title: _('A Gaunt Man'), @@ -77,7 +77,7 @@ Events.Encounters = [ notification: _('a gaunt man approaches, a crazed look in his eye') } }, - audio: '/audio/gaunt-man.wav' + audio: AudioLibrary.ENCOUNTER_GAUNT_MAN }, { /* Strange Bird */ title: _('A Strange Bird'), @@ -115,7 +115,7 @@ Events.Encounters = [ notification: _('a strange looking bird speeds across the plains') } }, - audio: '/audio/strange-bird.wav' + audio: AudioLibrary.ENCOUNTER_STRANGE_BIRD }, /* Tier 2*/ { /* Shivering Man */ @@ -159,7 +159,7 @@ Events.Encounters = [ notification: _('a shivering man approaches and attacks with surprising strength') } }, - audio: '/audio/shivering-man.wav' + audio: AudioLibrary.ENCOUNTER_SHIVERING_MAN }, { /* Man-eater */ title: _('A Man-Eater'), @@ -197,7 +197,7 @@ Events.Encounters = [ notification: _('a large creature attacks, claws freshly bloodied') } }, - audio: '/audio/man-eater.wav' + audio: AudioLibrary.ENCOUNTER_MAN_EATER }, { /* Scavenger */ title: _('A Scavenger'), @@ -240,7 +240,7 @@ Events.Encounters = [ notification: _('a scavenger draws close, hoping for an easy score') } }, - audio: '/audio/scavenger.wav' + audio: AudioLibrary.ENCOUNTER_SCAVENGER }, { /* Huge Lizard */ title: _('A Huge Lizard'), @@ -278,7 +278,7 @@ Events.Encounters = [ notification: _('the grass thrashes wildly as a huge lizard pushes through') } }, - audio: '/audio/huge-lizard.wav' + audio: AudioLibrary.ENCOUNTER_HUGE_LIZARD }, /* Tier 3*/ { /* Feral Terror */ @@ -317,7 +317,7 @@ Events.Encounters = [ notification: _('a beast, wilder than imagining, erupts out of the foliage') } }, - audio: '/audio/feral-terror.wav' + audio: AudioLibrary.ENCOUNTER_FERAL_TERROR }, { /* Soldier */ title: _('A Soldier'), @@ -361,7 +361,7 @@ Events.Encounters = [ notification: _('a soldier opens fire from across the desert') } }, - audio: '/audio/soldier.wav' + audio: AudioLibrary.ENCOUNTER_SOLDIER }, { /* Sniper */ title: _('A Sniper'), @@ -405,6 +405,6 @@ Events.Encounters = [ notification: _('a shot rings out, from somewhere in the long grass') } }, - audio: '/audio/sniper.wav' + audio: AudioLibrary.ENCOUNTER_SNIPER } ]; diff --git a/script/events/global.js b/script/events/global.js index d65afc1..8cefbf8 100644 --- a/script/events/global.js +++ b/script/events/global.js @@ -62,6 +62,6 @@ Events.Global = [ } } }, - audio: '/audio/thief.wav' + audio: AudioLibrary.EVENT_THIEF } ]; diff --git a/script/events/outside.js b/script/events/outside.js index 5239ce2..b0b5b15 100644 --- a/script/events/outside.js +++ b/script/events/outside.js @@ -64,7 +64,7 @@ Events.Outside = [ } } }, - audio: '/audio/ruined-trap.wav' + audio: AudioLibrary.EVENT_RUINED_TRAP }, { /* Hut fire */ title: _('Fire'), @@ -91,7 +91,7 @@ Events.Outside = [ } } }, - audio: '/audio/hut-fire.wav' + audio: AudioLibrary.EVENT_HUT_FIRE }, { /* Sickness */ title: _('Sickness'), @@ -149,7 +149,7 @@ Events.Outside = [ } } }, - audio: '/audio/sickness.wav' + audio: AudioLibrary.EVENT_SICKNESS }, { /* Plague */ @@ -221,7 +221,7 @@ Events.Outside = [ } } }, - audio: '/audio/plague.wav' + audio: AudioLibrary.EVENT_PLAGUE }, { /* Beast attack */ @@ -256,7 +256,7 @@ Events.Outside = [ } } }, - audio: '/audio/beast-attack.wav' + audio: AudioLibrary.EVENT_BEAST_ATTACK }, { /* Soldier attack */ @@ -291,7 +291,7 @@ Events.Outside = [ } } }, - audio: '/audio/soldier-attack.wav' + audio: AudioLibrary.EVENT_SOLDIER_ATTACK } ]; diff --git a/script/events/room.js b/script/events/room.js index a9878b3..6879458 100644 --- a/script/events/room.js +++ b/script/events/room.js @@ -48,7 +48,7 @@ Events.Room = [ } } }, - audio: '/audio/nomad.wav' + audio: AudioLibrary.EVENT_NOMAD }, { /* Noises Outside -- gain wood/fur */ title: _('Noises'), @@ -100,7 +100,7 @@ Events.Room = [ } } }, - audio: '/audio/noises-outside.wav' + audio: AudioLibrary.EVENT_NOISES_OUTSIDE }, { /* Noises Inside -- trade wood for better good */ title: _('Noises'), @@ -187,7 +187,7 @@ Events.Room = [ } } }, - audio: '/audio/noises-inside.wav' + audio: AudioLibrary.EVENT_NOISES_INSIDE }, { /* The Beggar -- trade fur for better good */ title: _('The Beggar'), @@ -259,7 +259,7 @@ Events.Room = [ } } }, - audio: '/audio/beggar.wav' + audio: AudioLibrary.EVENT_BEGGAR }, {/* The Shady Builder */ title: _('The Shady Builder'), @@ -316,7 +316,7 @@ Events.Room = [ } } }, - audio: '/audio/shady-builder.wav' + audio: AudioLibrary.EVENT_SHADY_BUILDER }, { /* Mysterious Wanderer -- wood gambling */ @@ -396,7 +396,7 @@ Events.Room = [ } } }, - audio: '/audio/mysterious-wanderer.wav' + audio: AudioLibrary.EVENT_MYSTERIOUS_WANDERER }, { /* Mysterious Wanderer -- fur gambling */ @@ -476,7 +476,7 @@ Events.Room = [ } } }, - audio: '/audio/mysterious-wanderer.wav' + audio: AudioLibrary.EVENT_MYSTERIOUS_WANDERER }, { /* The Scout -- Map Merchant */ @@ -519,7 +519,7 @@ Events.Room = [ } } }, - audio: '/audio/scout.wav' + audio: AudioLibrary.EVENT_SCOUT }, { /* The Wandering Master */ @@ -593,7 +593,7 @@ Events.Room = [ } } }, - audio: '/audio/wandering-master.wav' + audio: AudioLibrary.EVENT_WANDERING_MASTER }, { /* The Sick Man */ @@ -682,6 +682,6 @@ Events.Room = [ } } }, - audio: '/audio/sick-man.wav' + audio: AudioLibrary.EVENT_SICK_MAN } ]; diff --git a/script/events/setpieces.js b/script/events/setpieces.js index 522a52c..408d641 100644 --- a/script/events/setpieces.js +++ b/script/events/setpieces.js @@ -29,7 +29,7 @@ Events.Setpieces = { } } }, - audio: '/audio/friendly-outpost.wav' + audio: AudioLibrary.EVENT_FRIENDLY_OUTPOST }, "swamp": { /* Swamp */ title: _('A Murky Swamp'), @@ -87,7 +87,7 @@ Events.Setpieces = { } } }, - audio: '/audio/swamp.wav' + audio: AudioLibrary.EVENT_SWAMP }, "cave": { /* Cave */ title: _('A Damp Cave'), @@ -519,7 +519,7 @@ Events.Setpieces = { } } }, - audio: '/audio/cave.wav' + audio: AudioLibrary.EVENT_CAVE }, "town": { /* Town */ title: _('A Deserted Town'), @@ -1237,7 +1237,7 @@ Events.Setpieces = { } } }, - audio: '/audio/town.wav' + audio: AudioLibrary.EVENT_TOWN }, "city": { /* City */ title: _('A Ruined City'), @@ -2933,7 +2933,7 @@ Events.Setpieces = { } } }, - audio: '/audio/city.wav' + audio: AudioLibrary.EVENT_CITY }, "house": { /* Abandoned House */ title: _('An Old House'), @@ -3051,7 +3051,7 @@ Events.Setpieces = { } } }, - audio: '/audio/house.wav' + audio: AudioLibrary.EVENT_HOUSE }, "battlefield": { /* Discovering an old battlefield */ title: _('A Forgotten Battlefield'), @@ -3105,7 +3105,7 @@ Events.Setpieces = { } } }, - audio: '/audio/battlefield.wav' + audio: AudioLibrary.EVENT_BATTLEFIELD }, "borehole": { /* Admiring a huge borehole */ title: _('A Huge Borehole'), @@ -3135,7 +3135,7 @@ Events.Setpieces = { } } }, - audio: '/audio/borehole.wav' + audio: AudioLibrary.EVENT_BOREHOLE }, "ship": { /* Finding a way off this rock */ title: _('A Crashed Ship'), @@ -3159,7 +3159,7 @@ Events.Setpieces = { } } }, - audio: '/audio/crashed-ship.wav' + audio: AudioLibrary.EVENT_CRASHED_SHIP }, "sulphurmine": { /* Clearing the Sulphur Mine */ title: _('The Sulphur Mine'), @@ -3309,7 +3309,7 @@ Events.Setpieces = { } } }, - audio: '/audio/sulphurmine.wav' + audio: AudioLibrary.EVENT_SULPHUR_MINE }, "coalmine": { /* Clearing the Coal Mine */ title: _('The Coal Mine'), @@ -3452,7 +3452,7 @@ Events.Setpieces = { } } }, - audio: '/audio/coalmine.wav' + audio: AudioLibrary.EVENT_COAL_MINE }, "ironmine": { /* Clearing the Iron Mine */ title: _('The Iron Mine'), @@ -3529,7 +3529,7 @@ Events.Setpieces = { } } }, - audio: '/audio/ironmine.wav' + audio: AudioLibrary.EVENT_IRON_MINE }, "cache": { /* Cache - contains some of supplies from previous game */ @@ -3582,6 +3582,6 @@ Events.Setpieces = { } } }, - audio: '/audio/destroyed-village.wav' + audio: AudioLibrary.EVENT_DESTROYED_VILLAGE } }; diff --git a/script/outside.js b/script/outside.js index 7ebf415..9401325 100644 --- a/script/outside.js +++ b/script/outside.js @@ -587,14 +587,29 @@ var Outside = { Outside.updateVillage(true); Engine.moveStoresView($('#village'), transition_diff); - Outside.setMusic(); + + // set music + var numberOfHuts = $SM.get('game.buildings["hut"]', true); + if(numberOfHuts === 0) { + AudioEngine.changeMusic(AudioLibrary.MUSIC_SILENT_FOREST); + } else if(numberOfHuts == 1) { + AudioEngine.changeMusic(AudioLibrary.MUSIC_LONELY_HUT); + } else if(numberOfHuts <= 4) { + AudioEngine.changeMusic(AudioLibrary.MUSIC_TINY_VILLAGE); + } else if(numberOfHuts <= 8) { + AudioEngine.changeMusic(AudioLibrary.MUSIC_MODEST_VILLAGE); + } else if(numberOfHuts <= 14) { + AudioEngine.changeMusic(AudioLibrary.MUSIC_LARGE_VILLAGE); + } else { + AudioEngine.changeMusic(AudioLibrary.MUSIC_RAUCOUS_VILLAGE); + } }, gatherWood: function() { Notifications.notify(Outside, _("dry brush and dead branches litter the forest floor")); var gatherAmt = $SM.get('game.buildings["cart"]', true) > 0 ? 50 : 10; $SM.add('stores.wood', gatherAmt); - AudioEngine.playSound(Outside.SOUNDS['gather-wood']); + AudioEngine.playSound(AudioLibrary.GATHER_WOOD); }, checkTraps: function() { @@ -635,7 +650,7 @@ var Outside = { Notifications.notify(Outside, s); $SM.addM('stores', drops); - AudioEngine.playSound(Outside.SOUNDS['check-traps']); + AudioEngine.playSound(AudioLibrary.CHECL_TRAPS); }, handleStateUpdates: function(e){ @@ -678,25 +693,5 @@ var Outside = { scrollByX( $('#storesContainer'), momentum ); Outside._STORES_OFFSET += momentum; - }, - - setMusic: function () { - var numberOfHuts = $SM.get('game.buildings["hut"]', true); - var currentMusic = 0; - if(numberOfHuts === 0) { - currentMusic = 0; - } else if(numberOfHuts == 1) { - currentMusic = 1; - } else if(numberOfHuts <= 4) { - currentMusic = 2; - } else if(numberOfHuts <= 8) { - currentMusic = 3; - } else if(numberOfHuts <= 14) { - currentMusic = 4; - } else { - currentMusic = 5; - } - Outside.currentMusic = currentMusic; - AudioEngine.changeMusic(Outside.MUSIC[currentMusic]); } }; diff --git a/script/path.js b/script/path.js index 88fda22..21b3370 100644 --- a/script/path.js +++ b/script/path.js @@ -303,7 +303,8 @@ var Path = { Path.setTitle(); Path.updateOutfitting(); Path.updatePerks(true); - Path.setMusic(); + + AudioEngine.changeMusic(AudioLibrary.MUSIC_PATH); Engine.moveStoresView($('#perks'), transition_diff); }, @@ -319,7 +320,7 @@ var Path = { World.onArrival(); $('#outerSlider').animate({left: '-700px'}, 300); Engine.activeModule = World; - AudioEngine.playSound(Path.SOUNDS['embark']); + AudioEngine.playSound(AudioLibrary.EMBARK); }, handleStateUpdates: function(e){ @@ -358,9 +359,5 @@ var Path = { scrollByX( $('#storesContainer'), momentum ); Path._STORES_OFFSET += momentum; - }, - - setMusic: function () { - AudioEngine.changeMusic(Path.MUSIC[0]); } }; diff --git a/script/room.js b/script/room.js index e9af006..85b16cb 100644 --- a/script/room.js +++ b/script/room.js @@ -24,7 +24,7 @@ var Room = { 'wood': 10 + (n * 10) }; }, - audio: '/audio/build-trap.wav' + audio: AudioLibrary.BUILD_TRAP }, 'cart': { name: _('cart'), @@ -38,7 +38,7 @@ var Room = { 'wood': 30 }; }, - audio: '/audio/build-cart.wav' + audio: AudioLibrary.BUILD_CART }, 'hut': { name: _('hut'), @@ -54,7 +54,7 @@ var Room = { 'wood': 100 + (n * 50) }; }, - audio: '/audio/build-hut.wav' + audio: AudioLibrary.BUILD_HUT }, 'lodge': { name: _('lodge'), @@ -70,7 +70,7 @@ var Room = { meat: 5 }; }, - audio: '/audio/build-lodge.wav' + audio: AudioLibrary.BUILD_LODGE }, 'trading post': { name: _('trading post'), @@ -85,7 +85,7 @@ var Room = { 'fur': 100 }; }, - audio: '/audio/build-trading-post.wav' + audio: AudioLibrary.BUILD_TRADING_POST }, 'tannery': { name: _('tannery'), @@ -100,7 +100,7 @@ var Room = { 'fur': 50 }; }, - audio: '/audio/build-tannery.wav' + audio: AudioLibrary.BUILD_TANNERY }, 'smokehouse': { name: _('smokehouse'), @@ -115,7 +115,7 @@ var Room = { 'meat': 50 }; }, - audio: '/audio/build-smokehouse.wav' + audio: AudioLibrary.BUILD_SMOKEHOUSE }, 'workshop': { name: _('workshop'), @@ -131,7 +131,7 @@ var Room = { 'scales': 10 }; }, - audio: '/audio/build-workshop.wav' + audio: AudioLibrary.BUILD_WORKSHOP }, 'steelworks': { name: _('steelworks'), @@ -147,7 +147,7 @@ var Room = { 'coal': 100 }; }, - audio: '/audio/build-steelworks.wav' + audio: AudioLibrary.BUILD_STEELWORKS }, 'armoury': { name: _('armoury'), @@ -163,7 +163,7 @@ var Room = { 'sulphur': 50 }; }, - audio: '/audio/build-armoury.wav' + audio: AudioLibrary.BUILD_ARMOURY }, 'torch': { name: _('torch'), @@ -176,7 +176,7 @@ var Room = { 'cloth': 1 }; }, - audio: '/audio/craft-torch.wav' + audio: AudioLibrary.CRAFT_TORCH }, 'waterskin': { name: _('waterskin'), @@ -189,7 +189,7 @@ var Room = { 'leather': 50 }; }, - audio: '/audio/craft-waterskin.wav' + audio: AudioLibrary.CRAFT_WATERSKIN }, 'cask': { name: _('cask'), @@ -203,7 +203,7 @@ var Room = { 'iron': 20 }; }, - audio: '/audio/craft-cask.wav' + audio: AudioLibrary.CRAFT_CASK }, 'water tank': { name: _('water tank'), @@ -217,7 +217,7 @@ var Room = { 'steel': 50 }; }, - audio: '/audio/craft-water-tank.wav' + audio: AudioLibrary.CRAFT_WATER_TANK }, 'bone spear': { name: _('bone spear'), @@ -230,7 +230,7 @@ var Room = { 'teeth': 5 }; }, - audio: '/audio/craft-bone-spear.wav' + audio: AudioLibrary.CRAFT_BONE_SPEAR }, 'rucksack': { name: _('rucksack'), @@ -243,7 +243,7 @@ var Room = { 'leather': 200 }; }, - audio: '/audio/craft-rucksack.wav' + audio: AudioLibrary.CRAFT_RUCKSACK }, 'wagon': { name: _('wagon'), @@ -257,7 +257,7 @@ var Room = { 'iron': 100 }; }, - audio: '/audio/craft-wagon.wav' + audio: AudioLibrary.CRAFT_WAGON }, 'convoy': { name: _('convoy'), @@ -272,7 +272,7 @@ var Room = { 'steel': 100 }; }, - audio: '/audio/craft-convoy.wav' + audio: AudioLibrary.CRAFT_CONVOY }, 'l armour': { name: _('l armour'), @@ -285,7 +285,7 @@ var Room = { 'scales': 20 }; }, - audio: '/audio/craft-leather-armour.wav' + audio: AudioLibrary.CRAFT_LEATHER_ARMOUR }, 'i armour': { name: _('i armour'), @@ -298,7 +298,7 @@ var Room = { 'iron': 100 }; }, - audio: '/audio/craft-iron-armour.wav' + audio: AudioLibrary.CRAFT_IRON_ARMOUR }, 's armour': { name: _('s armour'), @@ -311,7 +311,7 @@ var Room = { 'steel': 100 }; }, - audio: '/audio/craft-steel-armour.wav' + audio: AudioLibrary.CRAFT_STEEL_ARMOUR }, 'iron sword': { name: _('iron sword'), @@ -325,7 +325,7 @@ var Room = { 'iron': 20 }; }, - audio: '/audio/craft-iron-sword.wav' + audio: AudioLibrary.CRAFT_IRON_SWORD }, 'steel sword': { name: _('steel sword'), @@ -339,7 +339,7 @@ var Room = { 'steel': 20 }; }, - audio: '/audio/craft-steel-sword.wav' + audio: AudioLibrary.CRAFT_STEEL_SWORD }, 'rifle': { name: _('rifle'), @@ -352,7 +352,7 @@ var Room = { 'sulphur': 50 }; }, - audio: '/audio/craft-rifle.wav' + audio: AudioLibrary.CRAFT_RIFLE } }, @@ -362,14 +362,14 @@ var Room = { cost: function () { return { fur: 150 }; }, - audio: '/audio/buy-scales.wav' + audio: AudioLibrary.BUY_SCALES }, 'teeth': { type: 'good', cost: function () { return { fur: 300 }; }, - audio: '/audio/buy-teeth.wav' + audio: AudioLibrary.BUY_TEETH }, 'iron': { type: 'good', @@ -379,7 +379,7 @@ var Room = { 'scales': 50 }; }, - audio: '/audio/buy-iron.wav' + audio: AudioLibrary.BUY_IRON }, 'coal': { type: 'good', @@ -389,7 +389,7 @@ var Room = { 'teeth': 50 }; }, - audio: '/audio/buy-coal.wav' + audio: AudioLibrary.BUY_COAL }, 'steel': { type: 'good', @@ -400,7 +400,7 @@ var Room = { 'teeth': 50 }; }, - audio: '/audio/buy-steel.wav' + audio: AudioLibrary.BUY_STEEL }, 'medicine': { type: 'good', @@ -409,7 +409,7 @@ var Room = { 'scales': 50, 'teeth': 30 }; }, - audio: '/audio/buy-medicine.wav' + audio: AudioLibrary.BUY_MEDICINE }, 'bullets': { type: 'good', @@ -418,7 +418,7 @@ var Room = { 'scales': 10 }; }, - audio: '/audio/buy-bullets.wav' + audio: AudioLibrary.BUY_BULLETS }, 'energy cell': { type: 'good', @@ -428,7 +428,7 @@ var Room = { 'teeth': 10 }; }, - audio: '/audio/buy-energy-cell.wav' + audio: AudioLibrary.BUY_ENERGY_CELL }, 'bolas': { type: 'weapon', @@ -437,7 +437,7 @@ var Room = { 'teeth': 10 }; }, - audio: '/audio/buy-bolas.wav' + audio: AudioLibrary.BUY_BOLAS }, 'grenade': { type: 'weapon', @@ -447,7 +447,7 @@ var Room = { 'teeth': 50 }; }, - audio: '/audio/buy-grenade.wav' + audio: AudioLibrary.BUY_GRENADES }, 'bayonet': { type: 'weapon', @@ -457,7 +457,7 @@ var Room = { 'teeth': 250 }; }, - audio: '/audio/buy-bayonet.wav' + audio: AudioLibrary.BUY_BAYONET }, 'alien alloy': { type: 'good', @@ -468,7 +468,7 @@ var Room = { 'teeth': 300 }; }, - audio: '/audio/buy-alien-alloy.wav' + audio: AudioLibrary.BUY_ALIEN_ALLOY }, 'compass': { type: 'special', @@ -480,7 +480,7 @@ var Room = { teeth: 10 }; }, - audio: '/audio/buy-compass.wav' + audio: AudioLibrary.BUY_COMPASS } }, @@ -601,7 +601,27 @@ var Room = { } Engine.moveStoresView(null, transition_diff); - Room.setMusic(); + + // set music based on fire level + var fireValue = $SM.get('game.fire.value'); + switch (fireValue) { + case 0: + AudioEngine.changeMusic(AudioLibrary.MUSIC_FIRE0); + break; + case 1: + AudioEngine.changeMusic(AudioLibrary.MUSIC_FIRE1); + break; + case 2: + AudioEngine.changeMusic(AudioLibrary.MUSIC_FIRE2); + break; + case 3: + AudioEngine.changeMusic(AudioLibrary.MUSIC_FIRE3); + break; + case 4: + AudioEngine.changeMusic(AudioLibrary.MUSIC_FIRE4); + break; + } + Room.currentMusic = fireValue; }, TempEnum: { @@ -682,7 +702,7 @@ var Room = { $SM.set('stores.wood', wood - 5); } $SM.set('game.fire', Room.FireEnum.Burning); - AudioEngine.playSound(Room.SOUNDS['light-fire']); + AudioEngine.playSound(AudioLibrary.LIGHT_FIRE); Room.onFireChange(); }, @@ -699,7 +719,7 @@ var Room = { if ($SM.get('game.fire.value') < 4) { $SM.set('game.fire', Room.FireEnum.fromInt($SM.get('game.fire.value') + 1)); } - AudioEngine.playSound(Room.SOUNDS['stoke-fire']); + AudioEngine.playSound(AudioLibrary.STOKE_FIRE); Room.onFireChange(); }, @@ -1214,27 +1234,5 @@ var Room = { } else if (e.stateName.indexOf('game.buildings') === 0) { Room.updateBuildButtons(); } - }, - - setMusic: function () { - var fireValue = $SM.get('game.fire.value'); - switch (fireValue) { - case 0: - AudioEngine.changeMusic(Room.MUSIC[fireValue]); - break; - case 1: - AudioEngine.changeMusic(Room.MUSIC[fireValue]); - break; - case 2: - AudioEngine.changeMusic(Room.MUSIC[fireValue]); - break; - case 3: - AudioEngine.changeMusic(Room.MUSIC[fireValue]); - break; - case 4: - AudioEngine.changeMusic(Room.MUSIC[fireValue]); - break; - } - Room.currentMusic = fireValue; } }; diff --git a/script/ship.js b/script/ship.js index a67a457..4187d41 100644 --- a/script/ship.js +++ b/script/ship.js @@ -90,7 +90,7 @@ var Ship = { Notifications.notify(Ship, _('somewhere above the debris cloud, the wanderer fleet hovers. been on this rock too long.')); $SM.set('game.spaceShip.seenShip', true); } - Ship.setMusic(); + AudioEngine.changeMusic(AudioLibrary.MUSIC_SHIP); Engine.moveStoresView(null, transition_diff); }, @@ -112,7 +112,7 @@ var Ship = { Button.setDisabled($('#liftoffButton', Ship.panel), false); } $('#hullRow .row_val', Ship.panel).text($SM.get('game.spaceShip.hull')); - AudioEngine.playSound(Ship.SOUNDS['reinforce-hull']); + AudioEngine.playSound(AudioLibrary.REINFORCE_HULL); }, upgradeEngine: function() { @@ -123,7 +123,7 @@ var Ship = { $SM.add('stores["alien alloy"]', -Ship.ALLOY_PER_THRUSTER); $SM.add('game.spaceShip.thrusters', 1); $('#engineRow .row_val', Ship.panel).text($SM.get('game.spaceShip.thrusters')); - AudioEngine.playSound(Ship.SOUNDS['upgrade-engine']); + AudioEngine.playSound(AudioLibrary.UPGRADE_ENGINE); }, getMaxHull: function() { @@ -168,14 +168,10 @@ var Ship = { $('#outerSlider').animate({top: '700px'}, 300); Space.onArrival(); Engine.activeModule = Space; - AudioEngine.playSound(Ship.SOUNDS['lift-off']); + AudioEngine.playSound(AudioLibrary.LIFT_OFF); }, handleStateUpdates: function(e){ - }, - - setMusic: function () { - AudioEngine.changeMusic(Ship.MUSIC[0]); } }; diff --git a/script/space.js b/script/space.js index 3791ca6..9740c1d 100644 --- a/script/space.js +++ b/script/space.js @@ -53,7 +53,7 @@ var Space = { Space.hull = Ship.getMaxHull(); Space.altitude = 0; Space.setTitle(); - AudioEngine.changeMusic(Space.MUSIC[0]); + AudioEngine.changeMusic(AudioLibrary.MUSIC_SPACE); Space.updateHull(); Space.up = @@ -74,22 +74,22 @@ var Space = { var t; if(Space.altitude < 10) { t = _("Troposphere"); - AudioEngine.changeMusic(Space.MUSIC[1]); + AudioEngine.changeMusic(AudioLibrary.MUSIC_TROPOSPHERE); } else if(Space.altitude < 20) { t = _("Stratosphere"); - AudioEngine.changeMusic(Space.MUSIC[2]); + AudioEngine.changeMusic(AudioLibrary.MUSIC_STRATOSPHERE); } else if(Space.altitude < 30) { t = _("Mesosphere"); - AudioEngine.changeMusic(Space.MUSIC[3]); + AudioEngine.changeMusic(AudioLibrary.MUSIC_MESOSPHERE); } else if(Space.altitude < 45) { t = _("Thermosphere"); - AudioEngine.changeMusic(Space.MUSIC[4]); + AudioEngine.changeMusic(AudioLibrary.MUSIC_THERMOSPHERE); } else if(Space.altitude < 60){ t = _("Exosphere"); - AudioEngine.changeMusic(Space.MUSIC[5]); + AudioEngine.changeMusic(AudioLibrary.MUSIC_EXOSPHERE); } else { t = _("Space"); - AudioEngine.changeMusic(Space.MUSIC[0]); + AudioEngine.changeMusic(AudioLibrary.MUSIC_SPACE); } document.title = t; } @@ -145,7 +145,7 @@ var Space = { // play random asteroid hit var r = Math.floor(Math.random() * 2) + 1; - AudioEngine.playSound(Space.SOUNDS['asteroid-hit-' + r]); + AudioEngine.playSound(AudioLibrary['ASTEROID_HIT' + r]); if(Space.hull === 0) { Space.crash(); @@ -369,7 +369,7 @@ var Space = { Ship.onArrival(); Button.cooldown($('#liftoffButton')); Engine.event('progress', 'crash'); - AudioEngine.playSound(Space.SOUNDS['crash']); + AudioEngine.playSound(AudioLibrary.CRASH); }, endGame: function() { @@ -392,7 +392,7 @@ var Space = { } delete Outside._popTimeout; - AudioEngine.changeMusic(Space.MUSIC[6]); + AudioEngine.changeMusic(AudioLibrary.MUSIC_ENDING); $('#hullRemaining', Space.panel).animate({opacity: 0}, 500, 'linear'); Space.ship.animate({ top: '350px', diff --git a/script/world.js b/script/world.js index 02915e8..51fd46f 100644 --- a/script/world.js +++ b/script/world.js @@ -46,35 +46,35 @@ var World = { type: 'unarmed', damage: 1, cooldown: 2, - audio: '/audio/punch.wav' + audio: AudioLibrary.PUNCH }, 'bone spear': { verb: _('stab'), type: 'melee', damage: 2, cooldown: 2, - audio: '/audio/stab.wav' + audio: AudioLibrary.STAB }, 'iron sword': { verb: _('swing'), type: 'melee', damage: 4, cooldown: 2, - audio: '/audio/swing.wav' + audio: AudioLibrary.SWING }, 'steel sword': { verb: _('slash'), type: 'melee', damage: 6, cooldown: 2, - audio: '/audio/slash.wav' + audio: AudioLibrary.SLASH }, 'bayonet': { verb: _('thrust'), type: 'melee', damage: 8, cooldown: 2, - audio: '/audio/thrust.wav' + audio: AudioLibrary.THRUST }, 'rifle': { verb: _('shoot'), @@ -82,7 +82,7 @@ var World = { damage: 5, cooldown: 1, cost: { 'bullets': 1 }, - audio: '/audio/shoot.wav' + audio: AudioLibrary.SHOOT }, 'laser rifle': { verb: _('blast'), @@ -90,7 +90,7 @@ var World = { damage: 8, cooldown: 1, cost: { 'energy cell': 1 }, - audio: '/audio/blast.wav' + audio: AudioLibrary.BLAST }, 'grenade': { verb: _('lob'), @@ -98,7 +98,7 @@ var World = { damage: 15, cooldown: 5, cost: { 'grenade': 1 }, - audio: '/audio/lob.wav' + audio: AudioLibrary.LOB }, 'bolas': { verb: _('tangle'), @@ -106,7 +106,7 @@ var World = { damage: 'stun', cooldown: 15, cost: { 'bolas': 1 }, - audio: '/audio/tangle.wav' + audio: AudioLibrary.TANGLE } }, @@ -358,7 +358,7 @@ var World = { // play random footstep var randomFootstep = Math.floor(Math.random() * 2) + 1; - AudioEngine.playSound(World.SOUNDS['footsteps-' + randomFootstep]); + AudioEngine.playSound(AudioLibrary['FOOTSTEPS' + randomFootstep]); if(World.checkDanger()) { if(World.danger) { @@ -478,7 +478,7 @@ var World = { $SM.addPerk('slow metabolism'); } World.die(); - AudioEngine.playSound(World.SOUNDS['death-starved']); + AudioEngine.playSound(AudioLibrary.DEATH_STARVED); return false; } } else { @@ -508,7 +508,7 @@ var World = { $SM.addPerk('desert rat'); } World.die(); - AudioEngine.playSound(World.SOUNDS['death-dehydrated']); + AudioEngine.playSound(AudioLibrary.DEATH_DEHYDRATED); return false; } } else { @@ -1022,7 +1022,7 @@ var World = { World.curPos = World.copyPos(World.VILLAGE_POS); World.drawMap(); World.setTitle(); - World.setMusic(); + AudioEngine.changeMusic(AudioLibrary.MUSIC_WORLD); World.dead = false; $('div#bagspace-world > div').empty(); World.updateSupplies(); @@ -1039,9 +1039,5 @@ var World = { handleStateUpdates: function(e){ - }, - - setMusic: function () { - AudioEngine.changeMusic(World.MUSIC[0]); } };