diff --git a/app/lib/surface/MusicPlayer.coffee b/app/lib/surface/MusicPlayer.coffee index ddedecbf6..a3e1f0cb3 100644 --- a/app/lib/surface/MusicPlayer.coffee +++ b/app/lib/surface/MusicPlayer.coffee @@ -14,6 +14,8 @@ module.exports = class MusicPlayer extends CocoClass 'audio-player:loaded': 'onAudioLoaded' 'playback:real-time-playback-started': 'onRealTimePlaybackStarted' 'playback:real-time-playback-ended': 'onRealTimePlaybackEnded' + 'music-player:enter-menu': 'onEnterMenu' + 'music-player:exit-menu': 'onExitMenu' constructor: -> super arguments... @@ -35,9 +37,10 @@ module.exports = class MusicPlayer extends CocoClass @standingBy = e return + delay = e.delay ? 0 @standingBy = null @fadeOutCurrentMusic() - @startNewMusic(src) if e.play + @startNewMusic(src, delay) if e.play restartCurrentMusic: -> return unless @currentMusic @@ -46,15 +49,16 @@ module.exports = class MusicPlayer extends CocoClass fadeOutCurrentMusic: -> return unless @currentMusic + createjs.Tween.removeTweens(@currentMusic) f = -> @stop() createjs.Tween.get(@currentMusic).to({volume: 0.0}, CROSSFADE_LENGTH).call(f) - startNewMusic: (src) -> + startNewMusic: (src, delay) -> @currentMusic = createjs.Sound.play(src, 'none', 0, 0, -1, 0.3) if src return unless @currentMusic @currentMusic.volume = 0.0 if me.get('music', true) - createjs.Tween.get(@currentMusic).to({volume: MUSIC_VOLUME}, CROSSFADE_LENGTH) + createjs.Tween.get(@currentMusic).wait(delay).to({volume: MUSIC_VOLUME}, CROSSFADE_LENGTH) onMusicSettingChanged: -> @updateMusicVolume() @@ -74,6 +78,24 @@ module.exports = class MusicPlayer extends CocoClass if @previousMusic @currentMusic = @previousMusic @restartCurrentMusic() + if @currentMusic.volume + createjs.Tween.get(@currentMusic).wait(5000).to({volume: MUSIC_VOLUME}, CROSSFADE_LENGTH) + + onEnterMenu: (e) -> + return if @inMenu + @inMenu = true + @previousMusic = @currentMusic + terrain = (e.terrain ? 'Dungeon').toLowerCase() + file = "/music/music-menu-#{terrain}" + Backbone.Mediator.publish 'music-player:play-music', file: file, play: true, delay: 1000 + + onExitMenu: (e) -> + return unless @inMenu + @inMenu = false + @fadeOutCurrentMusic() + if @previousMusic + @currentMusic = @previousMusic + @restartCurrentMusic() destroy: -> me.off 'change:music', @onMusicSettingChanged, @ diff --git a/app/schemas/subscriptions/misc.coffee b/app/schemas/subscriptions/misc.coffee index d83c6dcaa..3800c4ab1 100644 --- a/app/schemas/subscriptions/misc.coffee +++ b/app/schemas/subscriptions/misc.coffee @@ -18,6 +18,12 @@ module.exports = 'music-player:play-music': c.object {required: ['play']}, play: {type: 'boolean'} file: {type: 'string'} + delay: {type: 'integer', minimum: 0, format: 'milliseconds'} + + 'music-player:enter-menu': c.object {required: []}, + terrain: {type: 'string'} + + 'music-player:exit-menu': c.object {} 'modal:opened': c.object {} diff --git a/app/views/game-menu/GameMenuModal.coffee b/app/views/game-menu/GameMenuModal.coffee index 04df7322e..f7488f505 100644 --- a/app/views/game-menu/GameMenuModal.coffee +++ b/app/views/game-menu/GameMenuModal.coffee @@ -24,6 +24,7 @@ module.exports = class GameMenuModal extends ModalView @options.showInventory = @options.level.get('type', true) in ['hero', 'hero-ladder', 'hero-coop'] @options.levelID = @options.level.get('slug') @options.startingSessionHeroConfig = $.extend {}, true, (@options.session.get('heroConfig') ? {}) + Backbone.Mediator.publish 'music-player:enter-menu', terrain: @options.level.get('terrain', true) getRenderData: (context={}) -> context = super(context) @@ -50,6 +51,7 @@ module.exports = class GameMenuModal extends ModalView patchingMe = @updateConfig() me.patch() unless patchingMe # Might need to patch for options menu, too Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'game-menu-close', volume: 1 + Backbone.Mediator.publish 'music-player:exit-menu', {} updateConfig: -> sessionHeroConfig = @options.startingSessionHeroConfig diff --git a/app/views/play/WorldMapView.coffee b/app/views/play/WorldMapView.coffee index 5b59df050..83089bb8a 100644 --- a/app/views/play/WorldMapView.coffee +++ b/app/views/play/WorldMapView.coffee @@ -860,7 +860,6 @@ hero = [ id: 'kithgard-gates' original: '541c9a30c6362edfb0f34479' description: 'Escape the Kithgard dungeons and don\'t let the guardians get you.' - disabled: true x: 89 y: 82 nextLevels: @@ -873,7 +872,6 @@ hero = [ id: 'defence-of-plainswood' original: '541b67f71ccc8eaae19f3c62' description: 'Protect the peasants from the pursuing ogres.' - disabled: true x: 95.31 y: 88.26 } diff --git a/app/views/play/level/modal/HeroVictoryModal.coffee b/app/views/play/level/modal/HeroVictoryModal.coffee index 463940df3..bfd52cc1f 100644 --- a/app/views/play/level/modal/HeroVictoryModal.coffee +++ b/app/views/play/level/modal/HeroVictoryModal.coffee @@ -41,6 +41,10 @@ module.exports = class HeroVictoryModal extends ModalView clearInterval @sequentialAnimationInterval super() + onHidden: -> + Backbone.Mediator.publish 'music-player:exit-menu', {} + super() + onAchievementsLoaded: -> thangTypeOriginals = [] achievementIDs = [] @@ -149,6 +153,7 @@ module.exports = class HeroVictoryModal extends ModalView panel.delay(500) panel.queue(-> complete()) @animationComplete = not @animatedPanels.length + complete() if @animationComplete if @level.get('type', true) is 'hero-ladder' @ladderSubmissionView = new LadderSubmissionView session: @session, level: @level @insertSubView @ladderSubmissionView, @$el.find('.ladder-submission-view') @@ -231,6 +236,7 @@ module.exports = class HeroVictoryModal extends ModalView clearInterval @sequentialAnimationInterval @animationComplete = true @updateSavingProgressStatus() + Backbone.Mediator.publish 'music-player:enter-menu', terrain: @level.get('terrain', true) updateSavingProgressStatus: -> return unless @animationComplete diff --git a/app/views/play/level/tome/SpellPaletteEntryView.coffee b/app/views/play/level/tome/SpellPaletteEntryView.coffee index 064bf2af4..29360f14c 100644 --- a/app/views/play/level/tome/SpellPaletteEntryView.coffee +++ b/app/views/play/level/tome/SpellPaletteEntryView.coffee @@ -47,7 +47,7 @@ module.exports = class SpellPaletteEntryView extends CocoView ).on 'show.bs.popover', => Backbone.Mediator.publish 'tome:palette-hovered', thang: @thang, prop: @doc.name, entry: @ soundIndex = Math.floor(Math.random() * 4) - Backbone.Mediator.publish 'audio-player:play-sound', trigger: "spell-palette-entry-open-{soundIndex}", volume: 0.75 + Backbone.Mediator.publish 'audio-player:play-sound', trigger: "spell-palette-entry-open-#{soundIndex}", volume: 0.75 onMouseEnter: (e) -> # Make sure the doc has the updated Thang so it can regenerate its prop value