Hooked up some menu music transitions to play menu music during HeroVictoryModal and GameMenuModal.

This commit is contained in:
Nick Winter 2014-10-23 20:03:19 -07:00
parent 4c33b98e27
commit 79ed8b2470
6 changed files with 40 additions and 6 deletions

View file

@ -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, @

View file

@ -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 {}

View file

@ -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

View file

@ -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
}

View file

@ -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

View file

@ -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