diff --git a/audio/fire-0.wav b/audio/fire-0.wav new file mode 100644 index 0000000..c2046fc Binary files /dev/null and b/audio/fire-0.wav differ diff --git a/audio/fire-1.wav b/audio/fire-1.wav new file mode 100644 index 0000000..669f2c9 Binary files /dev/null and b/audio/fire-1.wav differ diff --git a/audio/fire-2.wav b/audio/fire-2.wav new file mode 100644 index 0000000..7698a1e Binary files /dev/null and b/audio/fire-2.wav differ diff --git a/audio/fire-3.wav b/audio/fire-3.wav new file mode 100644 index 0000000..6c6c999 Binary files /dev/null and b/audio/fire-3.wav differ diff --git a/audio/fire-4.wav b/audio/fire-4.wav new file mode 100644 index 0000000..8550291 Binary files /dev/null and b/audio/fire-4.wav differ diff --git a/audio/light-fire.wav b/audio/light-fire.wav new file mode 100644 index 0000000..138cbc4 Binary files /dev/null and b/audio/light-fire.wav differ diff --git a/audio/outside.wav b/audio/outside.wav deleted file mode 100644 index 91bfb5f..0000000 Binary files a/audio/outside.wav and /dev/null differ diff --git a/audio/room.wav b/audio/room.wav deleted file mode 100644 index fff4fe1..0000000 Binary files a/audio/room.wav and /dev/null differ diff --git a/audio/stoke-fire.wav b/audio/stoke-fire.wav new file mode 100644 index 0000000..ff3a0ce Binary files /dev/null and b/audio/stoke-fire.wav differ diff --git a/script/audio.js b/script/audio.js index 8d1776b..3a04dff 100644 --- a/script/audio.js +++ b/script/audio.js @@ -51,7 +51,7 @@ var AudioEngine = { } // fade in new track - var fadeTime = this.audioContext.currentTime + 5.0; + var fadeTime = this.audioContext.currentTime + 2.0; newTrack.connect(this.tracks[nextBackgroundChannel]); newTrack.start(0); this.tracks[nextBackgroundChannel].gain.setValueAtTime(0.0, this.audioContext.currentTime); @@ -60,7 +60,7 @@ var AudioEngine = { // fade out old track this.tracks[this.currentBackgroundChannel].gain.linearRampToValueAtTime(0.0, fadeTime); if (this.currentTrack) { - this.currentTrack.stop(fadeTime + 1.0); // make sure fade has completed + this.currentTrack.stop(fadeTime + 0.3); // make sure fade has completed } // switch background track diff --git a/script/engine.js b/script/engine.js index 45b4c36..961074f 100644 --- a/script/engine.js +++ b/script/engine.js @@ -72,10 +72,10 @@ options: { state: null, - debug: false, - log: false, + debug: true, + log: true, dropbox: false, - doubleTime: false + doubleTime: true }, init: function(options) { @@ -597,7 +597,6 @@ Engine.activeModule = module; module.onArrival(diff); Notifications.printQueue(module); - AudioEngine.changeMusic(module.music); } }, diff --git a/script/outside.js b/script/outside.js index 0bd31b6..881bc43 100644 --- a/script/outside.js +++ b/script/outside.js @@ -3,7 +3,6 @@ */ var Outside = { name: _("Outside"), - music: '/audio/outside.wav', _STORES_OFFSET: 0, _GATHER_DELAY: 60, diff --git a/script/room.js b/script/room.js index 41b5d82..7ce3145 100644 --- a/script/room.js +++ b/script/room.js @@ -8,9 +8,19 @@ var Room = { _BUILDER_STATE_DELAY: 0.5 * 60 * 1000, // time between builder state updates _STOKE_COOLDOWN: 10, // cooldown to stoke the fire _NEED_WOOD_DELAY: 15 * 1000, // from when the stranger shows up, to when you need wood - - buttons:{}, - music: '/audio/room.wav', + currentMusic: 0, + MUSIC: { + 0: '/audio/fire-0.wav', + 1: '/audio/fire-1.wav', + 2: '/audio/fire-2.wav', + 3: '/audio/fire-3.wav', + 4: '/audio/fire-4.wav', + }, + SOUNDS: { + 'light-fire': '/audio/light-fire.wav', + 'stoke-fire': '/audio/stoke-fire.wav' + }, + buttons: {}, Craftables: { 'trap': { name: _('trap'), @@ -20,10 +30,10 @@ var Room = { buildMsg: _('more traps to catch more creatures'), maxMsg: _("more traps won't help now"), type: 'building', - cost: function() { + cost: function () { var n = $SM.get('game.buildings["trap"]', true); return { - 'wood': 10 + (n*10) + 'wood': 10 + (n * 10) }; } }, @@ -34,7 +44,7 @@ var Room = { availableMsg: _('builder says she can make a cart for carrying wood'), buildMsg: _('the rickety cart will carry more wood from the forest'), type: 'building', - cost: function() { + cost: function () { return { 'wood': 30 }; @@ -48,10 +58,10 @@ var Room = { buildMsg: _('builder puts up a hut, out in the forest. says word will get around.'), maxMsg: _('no more room for huts.'), type: 'building', - cost: function() { + cost: function () { var n = $SM.get('game.buildings["hut"]', true); return { - 'wood': 100 + (n*50) + 'wood': 100 + (n * 50) }; } }, @@ -62,7 +72,7 @@ var Room = { availableMsg: _('villagers could help hunt, given the means'), buildMsg: _('the hunting lodge stands in the forest, a ways out of town'), type: 'building', - cost: function() { + cost: function () { return { wood: 200, fur: 10, @@ -77,7 +87,7 @@ var Room = { availableMsg: _("a trading post would make commerce easier"), buildMsg: _("now the nomads have a place to set up shop, they might stick around a while"), type: 'building', - cost: function() { + cost: function () { return { 'wood': 400, 'fur': 100 @@ -91,7 +101,7 @@ var Room = { availableMsg: _("builder says leather could be useful. says the villagers could make it."), buildMsg: _('tannery goes up quick, on the edge of the village'), type: 'building', - cost: function() { + cost: function () { return { 'wood': 500, 'fur': 50 @@ -105,7 +115,7 @@ var Room = { availableMsg: _("should cure the meat, or it'll spoil. builder says she can fix something up."), buildMsg: _('builder finishes the smokehouse. she looks hungry.'), type: 'building', - cost: function() { + cost: function () { return { 'wood': 600, 'meat': 50 @@ -119,7 +129,7 @@ var Room = { availableMsg: _("builder says she could make finer things, if she had the tools"), buildMsg: _("workshop's finally ready. builder's excited to get to it"), type: 'building', - cost: function() { + cost: function () { return { 'wood': 800, 'leather': 100, @@ -134,7 +144,7 @@ var Room = { availableMsg: _("builder says the villagers could make steel, given the tools"), buildMsg: _("a haze falls over the village as the steelworks fires up"), type: 'building', - cost: function() { + cost: function () { return { 'wood': 1500, 'iron': 100, @@ -149,7 +159,7 @@ var Room = { availableMsg: _("builder says it'd be useful to have a steady source of bullets"), buildMsg: _("armoury's done, welcoming back the weapons of the past."), type: 'building', - cost: function() { + cost: function () { return { 'wood': 3000, 'steel': 100, @@ -162,7 +172,7 @@ var Room = { button: null, type: 'tool', buildMsg: _('a torch to keep the dark away'), - cost: function() { + cost: function () { return { 'wood': 1, 'cloth': 1 @@ -175,7 +185,7 @@ var Room = { type: 'upgrade', maximum: 1, buildMsg: _('this waterskin\'ll hold a bit of water, at least'), - cost: function() { + cost: function () { return { 'leather': 50 }; @@ -187,7 +197,7 @@ var Room = { type: 'upgrade', maximum: 1, buildMsg: _('the cask holds enough water for longer expeditions'), - cost: function() { + cost: function () { return { 'leather': 100, 'iron': 20 @@ -200,7 +210,7 @@ var Room = { type: 'upgrade', maximum: 1, buildMsg: _('never go thirsty again'), - cost: function() { + cost: function () { return { 'iron': 100, 'steel': 50 @@ -212,7 +222,7 @@ var Room = { button: null, type: 'weapon', buildMsg: _("this spear's not elegant, but it's pretty good at stabbing"), - cost: function() { + cost: function () { return { 'wood': 100, 'teeth': 5 @@ -225,7 +235,7 @@ var Room = { type: 'upgrade', maximum: 1, buildMsg: _('carrying more means longer expeditions to the wilds'), - cost: function() { + cost: function () { return { 'leather': 200 }; @@ -237,7 +247,7 @@ var Room = { type: 'upgrade', maximum: 1, buildMsg: _('the wagon can carry a lot of supplies'), - cost: function() { + cost: function () { return { 'wood': 500, 'iron': 100 @@ -250,7 +260,7 @@ var Room = { type: 'upgrade', maximum: 1, buildMsg: _('the convoy can haul mostly everything'), - cost: function() { + cost: function () { return { 'wood': 1000, 'iron': 200, @@ -263,7 +273,7 @@ var Room = { type: 'upgrade', maximum: 1, buildMsg: _("leather's not strong. better than rags, though."), - cost: function() { + cost: function () { return { 'leather': 200, 'scales': 20 @@ -275,7 +285,7 @@ var Room = { type: 'upgrade', maximum: 1, buildMsg: _("iron's stronger than leather"), - cost: function() { + cost: function () { return { 'leather': 200, 'iron': 100 @@ -287,7 +297,7 @@ var Room = { type: 'upgrade', maximum: 1, buildMsg: _("steel's stronger than iron"), - cost: function() { + cost: function () { return { 'leather': 200, 'steel': 100 @@ -299,7 +309,7 @@ var Room = { button: null, type: 'weapon', buildMsg: _("sword is sharp. good protection out in the wilds."), - cost: function() { + cost: function () { return { 'wood': 200, 'leather': 50, @@ -312,7 +322,7 @@ var Room = { button: null, type: 'weapon', buildMsg: _("the steel is strong, and the blade true."), - cost: function() { + cost: function () { return { 'wood': 500, 'leather': 100, @@ -324,7 +334,7 @@ var Room = { name: _('rifle'), type: 'weapon', buildMsg: _("black powder and bullets, like the old days."), - cost: function() { + cost: function () { return { 'wood': 200, 'steel': 50, @@ -333,23 +343,23 @@ var Room = { } } }, - + TradeGoods: { 'scales': { type: 'good', - cost: function() { + cost: function () { return { fur: 150 }; } }, 'teeth': { type: 'good', - cost: function() { + cost: function () { return { fur: 300 }; } }, 'iron': { type: 'good', - cost: function() { + cost: function () { return { 'fur': 150, 'scales': 50 @@ -358,7 +368,7 @@ var Room = { }, 'coal': { type: 'good', - cost: function() { + cost: function () { return { 'fur': 200, 'teeth': 50 @@ -367,7 +377,7 @@ var Room = { }, 'steel': { type: 'good', - cost: function() { + cost: function () { return { 'fur': 300, 'scales': 50, @@ -377,7 +387,7 @@ var Room = { }, 'medicine': { type: 'good', - cost: function() { + cost: function () { return { 'scales': 50, 'teeth': 30 }; @@ -385,7 +395,7 @@ var Room = { }, 'bullets': { type: 'good', - cost: function() { + cost: function () { return { 'scales': 10 }; @@ -393,7 +403,7 @@ var Room = { }, 'energy cell': { type: 'good', - cost: function() { + cost: function () { return { 'scales': 10, 'teeth': 10 @@ -402,7 +412,7 @@ var Room = { }, 'bolas': { type: 'weapon', - cost: function() { + cost: function () { return { 'teeth': 10 }; @@ -410,7 +420,7 @@ var Room = { }, 'grenade': { type: 'weapon', - cost: function() { + cost: function () { return { 'scales': 100, 'teeth': 50 @@ -419,7 +429,7 @@ var Room = { }, 'bayonet': { type: 'weapon', - cost: function() { + cost: function () { return { 'scales': 500, 'teeth': 250 @@ -428,7 +438,7 @@ var Room = { }, 'alien alloy': { type: 'good', - cost: function() { + cost: function () { return { 'fur': 1500, 'scales': 750, @@ -439,59 +449,59 @@ var Room = { 'compass': { type: 'special', maximum: 1, - cost: function() { - return { - fur: 400, - scales: 20, - teeth: 10 + cost: function () { + return { + fur: 400, + scales: 20, + teeth: 10 }; } } }, - + MiscItems: { 'laser rifle': { type: 'weapon' } }, - + name: _("Room"), - init: function(options) { + init: function (options) { this.options = $.extend( this.options, options ); - + Room.pathDiscovery = Boolean($SM.get('stores["compass"]')); - if(Engine._debug) { + if (Engine._debug) { this._ROOM_WARM_DELAY = 5000; this._BUILDER_STATE_DELAY = 5000; this._STOKE_COOLDOWN = 0; this._NEED_WOOD_DELAY = 5000; } - - if(typeof $SM.get('features.location.room') == 'undefined') { + + if (typeof $SM.get('features.location.room') == 'undefined') { $SM.set('features.location.room', true); $SM.set('game.builder.level', -1); } - + // If this is the first time playing, the fire is dead and it's freezing. // Otherwise grab past save state temp and fire level. - $SM.set('game.temperature', $SM.get('game.temperature.value')===undefined?this.TempEnum.Freezing:$SM.get('game.temperature')); - $SM.set('game.fire', $SM.get('game.fire.value')===undefined?this.FireEnum.Dead:$SM.get('game.fire')); - + $SM.set('game.temperature', $SM.get('game.temperature.value') === undefined ? this.TempEnum.Freezing : $SM.get('game.temperature')); + $SM.set('game.fire', $SM.get('game.fire.value') === undefined ? this.FireEnum.Dead : $SM.get('game.fire')); + // Create the room tab this.tab = Header.addLocation(_("A Dark Room"), "room", Room); - + // Create the Room panel this.panel = $('
') .attr('id', "roomPanel") .addClass('location') .appendTo('div#locationSlider'); - + Engine.updateSlider(); - + // Create the light button new Button.Button({ id: 'lightButton', @@ -499,9 +509,9 @@ var Room = { click: Room.lightFire, cooldown: Room._STOKE_COOLDOWN, width: '80px', - cost: {'wood': 5} + cost: { 'wood': 5 } }).appendTo('div#roomPanel'); - + // Create the stoke button new Button.Button({ id: 'stokeButton', @@ -509,23 +519,23 @@ var Room = { click: Room.stokeFire, cooldown: Room._STOKE_COOLDOWN, width: '80px', - cost: {'wood': 1} + cost: { 'wood': 1 } }).appendTo('div#roomPanel'); - + // Create the stores container $('
').attr('id', 'storesContainer').prependTo('div#roomPanel'); - + //subscribe to stateUpdates $.Dispatch('stateUpdate').subscribe(Room.handleStateUpdates); - + Room.updateButton(); Room.updateStoresView(); Room.updateIncomeView(); Room.updateBuildButtons(); - + Room._fireTimer = Engine.setTimeout(Room.coolFire, Room._FIRE_COOL_DELAY); Room._tempTimer = Engine.setTimeout(Room.adjustTemp, Room._ROOM_WARM_DELAY); - + /* * Builder states: * 0 - Approaching @@ -534,10 +544,10 @@ var Room = { * 3 - Sleeping * 4 - Helping */ - if($SM.get('game.builder.level') >= 0 && $SM.get('game.builder.level') < 3) { + if ($SM.get('game.builder.level') >= 0 && $SM.get('game.builder.level') < 3) { Room._builderTimer = Engine.setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY); } - if($SM.get('game.builder.level') == 1 && $SM.get('stores.wood', true) < 0) { + if ($SM.get('game.builder.level') == 1 && $SM.get('stores.wood', true) < 0) { Engine.setTimeout(Room.unlockForest, Room._NEED_WOOD_DELAY); } Engine.setTimeout($SM.collectIncome, 1000); @@ -545,33 +555,34 @@ var Room = { Notifications.notify(Room, _("the room is {0}", Room.TempEnum.fromInt($SM.get('game.temperature.value')).text)); Notifications.notify(Room, _("the fire is {0}", Room.FireEnum.fromInt($SM.get('game.fire.value')).text)); }, - + options: {}, // Nothing for now - - onArrival: function(transition_diff) { + + onArrival: function (transition_diff) { Room.setTitle(); - if(Room.changed) { + if (Room.changed) { Notifications.notify(Room, _("the fire is {0}", Room.FireEnum.fromInt($SM.get('game.fire.value')).text)); Notifications.notify(Room, _("the room is {0}", Room.TempEnum.fromInt($SM.get('game.temperature.value')).text)); Room.changed = false; } - if($SM.get('game.builder.level') == 3) { + if ($SM.get('game.builder.level') == 3) { $SM.add('game.builder.level', 1); $SM.setIncome('builder', { delay: 10, - stores: {'wood' : 2 } + stores: { 'wood': 2 } }); Room.updateIncomeView(); Notifications.notify(Room, _("the stranger is standing by the fire. she says she can help. says she builds things.")); } Engine.moveStoresView(null, transition_diff); + Room.setMusic(); }, - + TempEnum: { - fromInt: function(value) { - for(var k in this) { - if(typeof this[k].value != 'undefined' && this[k].value == value) { + fromInt: function (value) { + for (var k in this) { + if (typeof this[k].value != 'undefined' && this[k].value == value) { return this[k]; } } @@ -583,11 +594,11 @@ var Room = { Warm: { value: 3, text: _('warm') }, Hot: { value: 4, text: _('hot') } }, - + FireEnum: { - fromInt: function(value) { - for(var k in this) { - if(typeof this[k].value != 'undefined' && this[k].value == value) { + fromInt: function (value) { + for (var k in this) { + if (typeof this[k].value != 'undefined' && this[k].value == value) { return this[k]; } } @@ -599,33 +610,33 @@ var Room = { Burning: { value: 3, text: _('burning') }, Roaring: { value: 4, text: _('roaring') } }, - - setTitle: function() { + + setTitle: function () { var title = $SM.get('game.fire.value') < 2 ? _("A Dark Room") : _("A Firelit Room"); - if(Engine.activeModule == this) { + if (Engine.activeModule == this) { document.title = title; } $('div#location_room').text(title); }, - - updateButton: function() { + + updateButton: function () { var light = $('#lightButton.button'); var stoke = $('#stokeButton.button'); - if($SM.get('game.fire.value') == Room.FireEnum.Dead.value && stoke.css('display') != 'none') { + if ($SM.get('game.fire.value') == Room.FireEnum.Dead.value && stoke.css('display') != 'none') { stoke.hide(); light.show(); - if(stoke.hasClass('disabled')) { + if (stoke.hasClass('disabled')) { Button.cooldown(light); } - } else if(light.css('display') != 'none') { + } else if (light.css('display') != 'none') { stoke.show(); light.hide(); - if(light.hasClass('disabled')) { + if (light.hasClass('disabled')) { Button.cooldown(stoke); } } - - if(!$SM.get('stores.wood')) { + + if (!$SM.get('stores.wood')) { light.addClass('free'); stoke.addClass('free'); } else { @@ -633,215 +644,221 @@ var Room = { stoke.removeClass('free'); } }, - + _fireTimer: null, _tempTimer: null, - lightFire: function() { + lightFire: function () { var wood = $SM.get('stores.wood'); - if(wood < 5) { + if (wood < 5) { Notifications.notify(Room, _("not enough wood to get the fire going")); Button.clearCooldown($('#lightButton.button')); return; - } else if(wood > 4) { + } else if (wood > 4) { $SM.set('stores.wood', wood - 5); } $SM.set('game.fire', Room.FireEnum.Burning); + AudioEngine.playSound(Room.SOUNDS['light-fire']); Room.onFireChange(); }, - - stokeFire: function() { + + stokeFire: function () { var wood = $SM.get('stores.wood'); - if(wood === 0) { + if (wood === 0) { Notifications.notify(Room, _("the wood has run out")); Button.clearCooldown($('#stokeButton.button')); return; } - if(wood > 0) { + if (wood > 0) { $SM.set('stores.wood', wood - 1); } - if($SM.get('game.fire.value') < 4) { + 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']); Room.onFireChange(); }, - - onFireChange: function() { - if(Engine.activeModule != Room) { + + onFireChange: function () { + if (Engine.activeModule != Room) { Room.changed = true; } Notifications.notify(Room, _("the fire is {0}", Room.FireEnum.fromInt($SM.get('game.fire.value')).text), true); - if($SM.get('game.fire.value') > 1 && $SM.get('game.builder.level') < 0) { + if ($SM.get('game.fire.value') > 1 && $SM.get('game.builder.level') < 0) { $SM.set('game.builder.level', 0); Notifications.notify(Room, _("the light from the fire spills from the windows, out into the dark")); Engine.setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY); - } + } window.clearTimeout(Room._fireTimer); Room._fireTimer = Engine.setTimeout(Room.coolFire, Room._FIRE_COOL_DELAY); Room.updateButton(); Room.setTitle(); + + if ($SM.get('game.fire.value') !== Room.currentMusic) { + Room.setMusic(); + } }, - - coolFire: function() { + + coolFire: function () { var wood = $SM.get('stores.wood'); - if($SM.get('game.fire.value') <= Room.FireEnum.Flickering.value && + if ($SM.get('game.fire.value') <= Room.FireEnum.Flickering.value && $SM.get('game.builder.level') > 3 && wood > 0) { Notifications.notify(Room, _("builder stokes the fire"), true); $SM.set('stores.wood', wood - 1); - $SM.set('game.fire',Room.FireEnum.fromInt($SM.get('game.fire.value') + 1)); + $SM.set('game.fire', Room.FireEnum.fromInt($SM.get('game.fire.value') + 1)); } - if($SM.get('game.fire.value') > 0) { - $SM.set('game.fire',Room.FireEnum.fromInt($SM.get('game.fire.value') - 1)); + if ($SM.get('game.fire.value') > 0) { + $SM.set('game.fire', Room.FireEnum.fromInt($SM.get('game.fire.value') - 1)); Room._fireTimer = Engine.setTimeout(Room.coolFire, Room._FIRE_COOL_DELAY); Room.onFireChange(); } }, - - adjustTemp: function() { + + adjustTemp: function () { var old = $SM.get('game.temperature.value'); - if($SM.get('game.temperature.value') > 0 && $SM.get('game.temperature.value') > $SM.get('game.fire.value')) { - $SM.set('game.temperature',Room.TempEnum.fromInt($SM.get('game.temperature.value') - 1)); - Notifications.notify(Room, _("the room is {0}" , Room.TempEnum.fromInt($SM.get('game.temperature.value')).text), true); + if ($SM.get('game.temperature.value') > 0 && $SM.get('game.temperature.value') > $SM.get('game.fire.value')) { + $SM.set('game.temperature', Room.TempEnum.fromInt($SM.get('game.temperature.value') - 1)); + Notifications.notify(Room, _("the room is {0}", Room.TempEnum.fromInt($SM.get('game.temperature.value')).text), true); } - if($SM.get('game.temperature.value') < 4 && $SM.get('game.temperature.value') < $SM.get('game.fire.value')) { + if ($SM.get('game.temperature.value') < 4 && $SM.get('game.temperature.value') < $SM.get('game.fire.value')) { $SM.set('game.temperature', Room.TempEnum.fromInt($SM.get('game.temperature.value') + 1)); - Notifications.notify(Room, _("the room is {0}" , Room.TempEnum.fromInt($SM.get('game.temperature.value')).text), true); + Notifications.notify(Room, _("the room is {0}", Room.TempEnum.fromInt($SM.get('game.temperature.value')).text), true); } - if($SM.get('game.temperature.value') != old) { + if ($SM.get('game.temperature.value') != old) { Room.changed = true; } Room._tempTimer = Engine.setTimeout(Room.adjustTemp, Room._ROOM_WARM_DELAY); }, - - unlockForest: function() { + + unlockForest: function () { $SM.set('stores.wood', 4); Outside.init(); Notifications.notify(Room, _("the wind howls outside")); Notifications.notify(Room, _("the wood is running out")); Engine.event('progress', 'outside'); }, - - updateBuilderState: function() { + + updateBuilderState: function () { var lBuilder = $SM.get('game.builder.level'); - if(lBuilder === 0) { + if (lBuilder === 0) { Notifications.notify(Room, _("a ragged stranger stumbles through the door and collapses in the corner")); lBuilder = $SM.setget('game.builder.level', 1); Engine.setTimeout(Room.unlockForest, Room._NEED_WOOD_DELAY); - } - else if(lBuilder < 3 && $SM.get('game.temperature.value') >= Room.TempEnum.Warm.value) { + } + else if (lBuilder < 3 && $SM.get('game.temperature.value') >= Room.TempEnum.Warm.value) { var msg = ""; - switch(lBuilder) { - case 1: - msg = _("the stranger shivers, and mumbles quietly. her words are unintelligible."); - break; - case 2: - msg = _("the stranger in the corner stops shivering. her breathing calms."); - break; + switch (lBuilder) { + case 1: + msg = _("the stranger shivers, and mumbles quietly. her words are unintelligible."); + break; + case 2: + msg = _("the stranger in the corner stops shivering. her breathing calms."); + break; } Notifications.notify(Room, msg); - if(lBuilder < 3) { + if (lBuilder < 3) { lBuilder = $SM.setget('game.builder.level', lBuilder + 1); } } - if(lBuilder < 3) { + if (lBuilder < 3) { Engine.setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY); } Engine.saveGame(); }, - - updateStoresView: function() { + + updateStoresView: function () { var stores = $('div#stores'); var resources = $('div#resources'); var special = $('div#special'); var weapons = $('div#weapons'); var needsAppend = false, rNeedsAppend = false, sNeedsAppend = false, wNeedsAppend = false, newRow = false; - if(stores.length === 0) { + if (stores.length === 0) { stores = $('
').attr({ 'id': 'stores', 'data-legend': _('stores') }).css('opacity', 0); needsAppend = true; } - if(resources.length === 0) { + if (resources.length === 0) { resources = $('
').attr({ id: 'resources' }).css('opacity', 0); rNeedsAppend = true; } - if(special.length === 0) { + if (special.length === 0) { special = $('
').attr({ id: 'special' }).css('opacity', 0); sNeedsAppend = true; } - if(weapons.length === 0) { + if (weapons.length === 0) { weapons = $('
').attr({ 'id': 'weapons', 'data-legend': _('weapons') }).css('opacity', 0); wNeedsAppend = true; } - for(var k in $SM.get('stores')) { - + for (var k in $SM.get('stores')) { + var type = null; - if(Room.Craftables[k]) { + if (Room.Craftables[k]) { type = Room.Craftables[k].type; - } else if(Room.TradeGoods[k]) { + } else if (Room.TradeGoods[k]) { type = Room.TradeGoods[k].type; } else if (Room.MiscItems[k]) { type = Room.MiscItems[k].type; } - + var location; - switch(type) { - case 'upgrade': - // Don't display upgrades on the Room screen - continue; - case 'building': - // Don't display buildings either - continue; - case 'weapon': - location = weapons; - break; - case 'special': - location = special; - break; - default: - location = resources; - break; + switch (type) { + case 'upgrade': + // Don't display upgrades on the Room screen + continue; + case 'building': + // Don't display buildings either + continue; + case 'weapon': + location = weapons; + break; + case 'special': + location = special; + break; + default: + location = resources; + break; } - + var id = "row_" + k.replace(' ', '-'); var row = $('div#' + id, location); - var num = $SM.get('stores["'+k+'"]'); - - if(typeof num != 'number' || isNaN(num)) { + var num = $SM.get('stores["' + k + '"]'); + + if (typeof num != 'number' || isNaN(num)) { // No idea how counts get corrupted, but I have reason to believe that they occassionally do. // Build a little fence around it! num = 0; - $SM.set('stores["'+k+'"]', 0); + $SM.set('stores["' + k + '"]', 0); } - + var lk = _(k); - + // thieves? - if(typeof $SM.get('game.thieves') == 'undefined' && num > 5000 && $SM.get('features.location.world')) { + if (typeof $SM.get('game.thieves') == 'undefined' && num > 5000 && $SM.get('features.location.world')) { $SM.startThieves(); } - - if(row.length === 0) { + + if (row.length === 0) { row = $('
').attr('id', id).addClass('storeRow'); $('
').addClass('row_key').text(lk).appendTo(row); $('
').addClass('row_val').text(Math.floor(num)).appendTo(row); $('
').addClass('clear').appendTo(row); var curPrev = null; - location.children().each(function(i) { + location.children().each(function (i) { var child = $(this); var cName = child.children('.row_key').text(); - if(cName < lk) { + if (cName < lk) { curPrev = child.attr('id'); } }); - if(curPrev == null) { + if (curPrev == null) { row.prependTo(location); } else { row.insertAfter(location.find('#' + curPrev)); @@ -851,55 +868,55 @@ var Room = { $('div#' + row.attr('id') + ' > div.row_val', location).text(Math.floor(num)); } } - - if(rNeedsAppend && resources.children().length > 0) { + + if (rNeedsAppend && resources.children().length > 0) { resources.prependTo(stores); - resources.animate({opacity: 1}, 300, 'linear'); + resources.animate({ opacity: 1 }, 300, 'linear'); } - - if(sNeedsAppend && special.children().length > 0) { + + if (sNeedsAppend && special.children().length > 0) { special.appendTo(stores); - special.animate({opacity: 1}, 300, 'linear'); + special.animate({ opacity: 1 }, 300, 'linear'); } - - if(needsAppend && stores.find('div.storeRow').length > 0) { + + if (needsAppend && stores.find('div.storeRow').length > 0) { stores.appendTo('div#storesContainer'); - stores.animate({opacity: 1}, 300, 'linear'); + stores.animate({ opacity: 1 }, 300, 'linear'); } - - if(wNeedsAppend && weapons.children().length > 0) { + + if (wNeedsAppend && weapons.children().length > 0) { weapons.appendTo('div#storesContainer'); - weapons.animate({opacity: 1}, 300, 'linear'); + weapons.animate({ opacity: 1 }, 300, 'linear'); } - - if(newRow) { + + if (newRow) { Room.updateIncomeView(); } - if($("div#outsidePanel").length) { + if ($("div#outsidePanel").length) { Outside.updateVillage(); } - if($SM.get('stores.compass') && !Room.pathDiscovery){ + if ($SM.get('stores.compass') && !Room.pathDiscovery) { Room.pathDiscovery = true; Path.openPath(); } }, - - updateIncomeView: function() { + + updateIncomeView: function () { var stores = $('div#resources'); var totalIncome = {}; - if(stores.length === 0 || typeof $SM.get('income') == 'undefined') return; - $('div.storeRow', stores).each(function(index, el) { + if (stores.length === 0 || typeof $SM.get('income') == 'undefined') return; + $('div.storeRow', stores).each(function (index, el) { el = $(el); $('div.tooltip', el).remove(); var ttPos = index > 10 ? 'top right' : 'bottom right'; var tt = $('
').addClass('tooltip ' + ttPos); var storeName = el.attr('id').substring(4).replace('-', ' '); - for(var incomeSource in $SM.get('income')) { - var income = $SM.get('income["'+incomeSource+'"]'); - for(var store in income.stores) { - if(store == storeName && income.stores[store] !== 0) { + for (var incomeSource in $SM.get('income')) { + var income = $SM.get('income["' + incomeSource + '"]'); + for (var store in income.stores) { + if (store == storeName && income.stores[store] !== 0) { $('
').addClass('row_key').text(_(incomeSource)).appendTo(tt); $('
') .addClass('row_val') @@ -913,7 +930,7 @@ var Room = { } } } - if(tt.children().length > 0) { + if (tt.children().length > 0) { var total = totalIncome[storeName].income; $('
').addClass('total row_key').text(_('total')).appendTo(tt); $('
').addClass('total row_val').text(Engine.getIncomeMsg(total, totalIncome[storeName].delay)).appendTo(tt); @@ -921,21 +938,21 @@ var Room = { } }); }, - - buy: function(buyBtn) { + + buy: function (buyBtn) { var thing = $(buyBtn).attr('buildThing'); var good = Room.TradeGoods[thing]; - var numThings = $SM.get('stores["'+thing+'"]', true); - if(numThings < 0) numThings = 0; - if(good.maximum <= numThings) { + var numThings = $SM.get('stores["' + thing + '"]', true); + if (numThings < 0) numThings = 0; + if (good.maximum <= numThings) { return; } - + var storeMod = {}; var cost = good.cost(); - for(var k in cost) { - var have = $SM.get('stores["'+k+'"]', true); - if(have < cost[k]) { + for (var k in cost) { + var have = $SM.get('stores["' + k + '"]', true); + if (have < cost[k]) { Notifications.notify(Room, _("not enough " + k)); return false; } else { @@ -943,141 +960,141 @@ var Room = { } } $SM.setM('stores', storeMod); - + Notifications.notify(Room, good.buildMsg); - - $SM.add('stores["'+thing+'"]', 1); + + $SM.add('stores["' + thing + '"]', 1); }, - - build: function(buildBtn) { + + build: function (buildBtn) { var thing = $(buildBtn).attr('buildThing'); - if($SM.get('game.temperature.value') <= Room.TempEnum.Cold.value) { + if ($SM.get('game.temperature.value') <= Room.TempEnum.Cold.value) { Notifications.notify(Room, _("builder just shivers")); return false; } var craftable = Room.Craftables[thing]; - - var numThings = 0; - switch(craftable.type) { - case 'good': - case 'weapon': - case 'tool': - case 'upgrade': - numThings = $SM.get('stores["'+thing+'"]', true); - break; - case 'building': - numThings = $SM.get('game.buildings["'+thing+'"]', true); - break; + + var numThings = 0; + switch (craftable.type) { + case 'good': + case 'weapon': + case 'tool': + case 'upgrade': + numThings = $SM.get('stores["' + thing + '"]', true); + break; + case 'building': + numThings = $SM.get('game.buildings["' + thing + '"]', true); + break; } - - if(numThings < 0) numThings = 0; - if(craftable.maximum <= numThings) { + + if (numThings < 0) numThings = 0; + if (craftable.maximum <= numThings) { return; } - + var storeMod = {}; var cost = craftable.cost(); - for(var k in cost) { - var have = $SM.get('stores["'+k+'"]', true); - if(have < cost[k]) { - Notifications.notify(Room, _("not enough "+k)); + for (var k in cost) { + var have = $SM.get('stores["' + k + '"]', true); + if (have < cost[k]) { + Notifications.notify(Room, _("not enough " + k)); return false; } else { storeMod[k] = have - cost[k]; } } $SM.setM('stores', storeMod); - + Notifications.notify(Room, craftable.buildMsg); - - switch(craftable.type) { - case 'good': - case 'weapon': - case 'upgrade': - case 'tool': - $SM.add('stores["'+thing+'"]', 1); - break; - case 'building': - $SM.add('game.buildings["'+thing+'"]', 1); - break; - } + + switch (craftable.type) { + case 'good': + case 'weapon': + case 'upgrade': + case 'tool': + $SM.add('stores["' + thing + '"]', 1); + break; + case 'building': + $SM.add('game.buildings["' + thing + '"]', 1); + break; + } }, - - needsWorkshop: function(type) { - return type == 'weapon' || type == 'upgrade' || type =='tool'; + + needsWorkshop: function (type) { + return type == 'weapon' || type == 'upgrade' || type == 'tool'; }, - - craftUnlocked: function(thing) { - if(Room.buttons[thing]) { + + craftUnlocked: function (thing) { + if (Room.buttons[thing]) { return true; } - if($SM.get('game.builder.level') < 4) return false; + if ($SM.get('game.builder.level') < 4) return false; var craftable = Room.Craftables[thing]; - if(Room.needsWorkshop(craftable.type) && $SM.get('game.buildings["'+'workshop'+'"]', true) === 0) return false; + if (Room.needsWorkshop(craftable.type) && $SM.get('game.buildings["' + 'workshop' + '"]', true) === 0) return false; var cost = craftable.cost(); - + //show button if one has already been built - if($SM.get('game.buildings["'+thing+'"]') > 0){ + if ($SM.get('game.buildings["' + thing + '"]') > 0) { Room.buttons[thing] = true; return true; } // Show buttons if we have at least 1/2 the wood, and all other components have been seen. - if($SM.get('stores.wood', true) < cost['wood'] * 0.5) { + if ($SM.get('stores.wood', true) < cost['wood'] * 0.5) { return false; } - for(var c in cost) { - if(!$SM.get('stores["'+c+'"]')) { + for (var c in cost) { + if (!$SM.get('stores["' + c + '"]')) { return false; } } - + Room.buttons[thing] = true; //don't notify if it has already been built before - if(!$SM.get('game.buildings["'+thing+'"]')){ + if (!$SM.get('game.buildings["' + thing + '"]')) { Notifications.notify(Room, craftable.availableMsg); } return true; }, - - buyUnlocked: function(thing) { - if(Room.buttons[thing]) { + + buyUnlocked: function (thing) { + if (Room.buttons[thing]) { return true; - } else if($SM.get('game.buildings["trading post"]', true) > 0) { - if(thing == 'compass' || typeof $SM.get('stores["'+thing+'"]') != 'undefined') { + } else if ($SM.get('game.buildings["trading post"]', true) > 0) { + if (thing == 'compass' || typeof $SM.get('stores["' + thing + '"]') != 'undefined') { // Allow the purchase of stuff once you've seen it return true; } } return false; }, - - updateBuildButtons: function() { + + updateBuildButtons: function () { var buildSection = $('#buildBtns'); var needsAppend = false; - if(buildSection.length === 0) { - buildSection = $('
').attr({'id': 'buildBtns', 'data-legend': _('build:')}).css('opacity', 0); + if (buildSection.length === 0) { + buildSection = $('
').attr({ 'id': 'buildBtns', 'data-legend': _('build:') }).css('opacity', 0); needsAppend = true; } - + var craftSection = $('#craftBtns'); var cNeedsAppend = false; - if(craftSection.length === 0 && $SM.get('game.buildings["workshop"]', true) > 0) { - craftSection = $('
').attr({'id': 'craftBtns', 'data-legend': _('craft:')}).css('opacity', 0); + if (craftSection.length === 0 && $SM.get('game.buildings["workshop"]', true) > 0) { + craftSection = $('
').attr({ 'id': 'craftBtns', 'data-legend': _('craft:') }).css('opacity', 0); cNeedsAppend = true; } - + var buySection = $('#buyBtns'); var bNeedsAppend = false; - if(buySection.length === 0 && $SM.get('game.buildings["trading post"]', true) > 0) { - buySection = $('
').attr({'id': 'buyBtns', 'data-legend': _('buy:')}).css('opacity', 0); + if (buySection.length === 0 && $SM.get('game.buildings["trading post"]', true) > 0) { + buySection = $('
').attr({ 'id': 'buyBtns', 'data-legend': _('buy:') }).css('opacity', 0); bNeedsAppend = true; } - - for(var k in Room.Craftables) { + + for (var k in Room.Craftables) { craftable = Room.Craftables[k]; var max = $SM.num(k, craftable) + 1 > craftable.maximum; - if(craftable.button == null) { - if(Room.craftUnlocked(k)) { + if (craftable.button == null) { + if (Room.craftUnlocked(k)) { var loc = Room.needsWorkshop(craftable.type) ? craftSection : buildSection; craftable.button = new Button.Button({ id: 'build_' + k, @@ -1086,33 +1103,33 @@ var Room = { click: Room.build, width: '80px', ttPos: loc.children().length > 10 ? 'top right' : 'bottom right' - }).css('opacity', 0).attr('buildThing', k).appendTo(loc).animate({opacity: 1}, 300, 'linear'); + }).css('opacity', 0).attr('buildThing', k).appendTo(loc).animate({ opacity: 1 }, 300, 'linear'); } } else { // refresh the tooltip var costTooltip = $('.tooltip', craftable.button); costTooltip.empty(); var cost = craftable.cost(); - for(var c in cost) { + for (var c in cost) { $("
").addClass('row_key').text(_(c)).appendTo(costTooltip); $("
").addClass('row_val').text(cost[c]).appendTo(costTooltip); } - if(max && !craftable.button.hasClass('disabled')) { + if (max && !craftable.button.hasClass('disabled')) { Notifications.notify(Room, craftable.maxMsg); } } - if(max) { + if (max) { Button.setDisabled(craftable.button, true); } else { Button.setDisabled(craftable.button, false); } } - - for(var g in Room.TradeGoods) { + + for (var g in Room.TradeGoods) { good = Room.TradeGoods[g]; var goodsMax = $SM.num(g, good) + 1 > good.maximum; - if(good.button == null) { - if(Room.buyUnlocked(g)) { + if (good.button == null) { + if (Room.buyUnlocked(g)) { good.button = new Button.Button({ id: 'build_' + g, cost: good.cost(), @@ -1120,55 +1137,77 @@ var Room = { click: Room.buy, width: '80px', ttPos: buySection.children().length > 10 ? 'top right' : 'bottom right' - }).css('opacity', 0).attr('buildThing', g).appendTo(buySection).animate({opacity:1}, 300, 'linear'); + }).css('opacity', 0).attr('buildThing', g).appendTo(buySection).animate({ opacity: 1 }, 300, 'linear'); } } else { // refresh the tooltip var goodsCostTooltip = $('.tooltip', good.button); goodsCostTooltip.empty(); var goodCost = good.cost(); - for(var gc in goodCost) { + for (var gc in goodCost) { $("
").addClass('row_key').text(_(gc)).appendTo(goodsCostTooltip); $("
").addClass('row_val').text(goodCost[gc]).appendTo(goodsCostTooltip); } - if(goodsMax && !good.button.hasClass('disabled')) { + if (goodsMax && !good.button.hasClass('disabled')) { Notifications.notify(Room, good.maxMsg); } } - if(goodsMax) { + if (goodsMax) { Button.setDisabled(good.button, true); } else { Button.setDisabled(good.button, false); } } - - if(needsAppend && buildSection.children().length > 0) { - buildSection.appendTo('div#roomPanel').animate({opacity: 1}, 300, 'linear'); + + if (needsAppend && buildSection.children().length > 0) { + buildSection.appendTo('div#roomPanel').animate({ opacity: 1 }, 300, 'linear'); } - if(cNeedsAppend && craftSection.children().length > 0) { - craftSection.appendTo('div#roomPanel').animate({opacity: 1}, 300, 'linear'); + if (cNeedsAppend && craftSection.children().length > 0) { + craftSection.appendTo('div#roomPanel').animate({ opacity: 1 }, 300, 'linear'); } - if(bNeedsAppend && buildSection.children().length > 0) { - buySection.appendTo('div#roomPanel').animate({opacity: 1}, 300, 'linear'); + if (bNeedsAppend && buildSection.children().length > 0) { + buySection.appendTo('div#roomPanel').animate({ opacity: 1 }, 300, 'linear'); } }, - - compassTooltip: function(direction){ + + compassTooltip: function (direction) { var ttPos = $('div#resources').children().length > 10 ? 'top right' : 'bottom right'; var tt = $('
').addClass('tooltip ' + ttPos); - $('
').addClass('row_key').text(_('the compass points '+ direction)).appendTo(tt); + $('
').addClass('row_key').text(_('the compass points ' + direction)).appendTo(tt); tt.appendTo($('#row_compass')); }, - - handleStateUpdates: function(e){ - if(e.category == 'stores'){ + + handleStateUpdates: function (e) { + if (e.category == 'stores') { Room.updateStoresView(); Room.updateBuildButtons(); - } else if(e.category == 'income'){ + } else if (e.category == 'income') { Room.updateStoresView(); Room.updateIncomeView(); - } else if(e.stateName.indexOf('game.buildings') === 0){ + } 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; } };