mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Some fixes for how audio is triggered.
This commit is contained in:
parent
851ad43b45
commit
68808d0e07
6 changed files with 33 additions and 14 deletions
|
@ -3,6 +3,7 @@ AudioPlayer = require 'lib/AudioPlayer'
|
|||
{me} = require 'lib/auth'
|
||||
|
||||
CROSSFADE_LENGTH = 1500
|
||||
MUSIC_VOLUME = 0.6
|
||||
|
||||
module.exports = class MusicPlayer extends CocoClass
|
||||
currentMusic: null
|
||||
|
@ -51,7 +52,7 @@ module.exports = class MusicPlayer extends CocoClass
|
|||
return unless @currentMusic
|
||||
@currentMusic.volume = 0.0
|
||||
if me.get('music')
|
||||
createjs.Tween.get(@currentMusic).to({volume: 1.0}, CROSSFADE_LENGTH)
|
||||
createjs.Tween.get(@currentMusic).to({volume: MUSIC_VOLUME}, CROSSFADE_LENGTH)
|
||||
|
||||
onMusicSettingChanged: ->
|
||||
@updateMusicVolume()
|
||||
|
@ -59,7 +60,7 @@ module.exports = class MusicPlayer extends CocoClass
|
|||
updateMusicVolume: ->
|
||||
return unless @currentMusic
|
||||
createjs.Tween.removeTweens(@currentMusic)
|
||||
@currentMusic.volume = if me.get('music') then 1.0 else 0.0
|
||||
@currentMusic.volume = if me.get('music') then MUSIC_VOLUME else 0.0
|
||||
|
||||
destroy: ->
|
||||
me.off 'change:music', @onMusicSettingChanged, @
|
||||
|
|
|
@ -15,14 +15,15 @@ module.exports = class GameMenuModal extends ModalView
|
|||
id: 'game-menu-modal'
|
||||
instant: true
|
||||
|
||||
events:
|
||||
'change input.select': 'onSelectionChanged'
|
||||
'shown.bs.tab .nav-tabs a': 'onTabShown'
|
||||
|
||||
constructor: (options) ->
|
||||
super options
|
||||
@options.showDevBits = me.isAdmin() or /https?:\/\/localhost/.test(window.location.href)
|
||||
@options.showInventory = @options.level.get('type', true) is 'hero'
|
||||
|
||||
events:
|
||||
'change input.select': 'onSelectionChanged'
|
||||
|
||||
getRenderData: (context={}) ->
|
||||
context = super(context)
|
||||
context.showDevBits = @options.showDevBits
|
||||
|
@ -36,6 +37,10 @@ module.exports = class GameMenuModal extends ModalView
|
|||
(if @options.showInventory then @subviews.inventory_view else @subviews.choose_hero_view).$el.addClass 'active'
|
||||
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'game-menu-open', volume: 1
|
||||
|
||||
onTabShown: ->
|
||||
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'game-menu-tab-switch', volume: 1
|
||||
|
||||
onHidden: ->
|
||||
subview.onHidden?() for subviewKey, subview of @subviews
|
||||
me.patch()
|
||||
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'game-menu-close', volume: 1
|
||||
|
|
|
@ -28,7 +28,7 @@ module.exports = class LevelGoalsView extends CocoView
|
|||
@updatePlacement()
|
||||
|
||||
onNewGoalStates: (e) ->
|
||||
firstRun = @previousGoalStatus?
|
||||
firstRun = not @previousGoalStatus?
|
||||
@previousGoalStatus ?= {}
|
||||
@$el.find('.goal-status').addClass 'secret'
|
||||
classToShow = null
|
||||
|
@ -63,8 +63,9 @@ module.exports = class LevelGoalsView extends CocoView
|
|||
goals.push goal
|
||||
if not firstRun and state.status is 'success' and @previousGoalStatus[goal.id] isnt 'success'
|
||||
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'goal-success', volume: 1
|
||||
else if not firstRun and state.status is 'incomplete' and @previousGoalStatus[goal.id] is 'success'
|
||||
else if not firstRun and state.status isnt 'success' and @previousGoalStatus[goal.id] is 'success'
|
||||
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'goal-incomplete-again', volume: 1
|
||||
@previousGoalStatus[goal.id] = state.status
|
||||
@$el.removeClass('secret') if goals.length > 0
|
||||
|
||||
onSurfacePlaybackRestarted: ->
|
||||
|
@ -91,9 +92,20 @@ module.exports = class LevelGoalsView extends CocoView
|
|||
sound = if expand then 'goals-expand' else 'goals-collapse'
|
||||
top = if expand then -10 else 26 - @$el.outerHeight()
|
||||
@$el.css 'top', top
|
||||
Backbone.Mediator.publish 'audio-player:play-sound', trigger: sound, volume: 1 if @expanded?
|
||||
if @soundTimeout
|
||||
# Don't play the sound we were going to play after all; the transition has reversed.
|
||||
clearTimeout @soundTimeout
|
||||
@soundTimeout = null
|
||||
else if @expanded?
|
||||
# Play it when the transition ends, not when it begins.
|
||||
@soundTimeout = _.delay @playToggleSound, 500, sound
|
||||
@expanded = expand
|
||||
|
||||
playToggleSound: (sound) =>
|
||||
return if @destroyed
|
||||
Backbone.Mediator.publish 'audio-player:play-sound', trigger: sound, volume: 1
|
||||
@soundTimeout = null
|
||||
|
||||
onSetLetterbox: (e) ->
|
||||
@$el.toggle not e.on
|
||||
@updatePlacement()
|
||||
|
|
|
@ -31,7 +31,7 @@ module.exports = class LevelLoadingView extends CocoView
|
|||
loadingDetails.css 'top', -loadingDetails.outerHeight(true)
|
||||
@$el.find('.left-wing').css left: '-100%', backgroundPosition: 'right -400px top 0'
|
||||
@$el.find('.right-wing').css right: '-100%', backgroundPosition: 'left -400px top 0'
|
||||
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'loading-view-unveil', volume: 1
|
||||
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'loading-view-unveil', volume: 0.5
|
||||
_.delay @onUnveilEnded, duration * 1000
|
||||
|
||||
onUnveilEnded: =>
|
||||
|
|
|
@ -78,7 +78,8 @@ module.exports = class SpellListTabEntryView extends SpellListEntryView
|
|||
trigger: 'hover'
|
||||
content: docFormatter.formatPopover()
|
||||
container: @$el.parent()
|
||||
)
|
||||
).on 'show.bs.popover', =>
|
||||
Backbone.Mediator.publish 'audio-player:play-sound', trigger: "spell-tab-entry-open", volume: 0.75
|
||||
|
||||
onMouseEnterAvatar: (e) -> # Don't call super
|
||||
onMouseLeaveAvatar: (e) -> # Don't call super
|
||||
|
|
|
@ -44,11 +44,10 @@ module.exports = class SpellPaletteEntryView extends CocoView
|
|||
content: @docFormatter.formatPopover()
|
||||
container: 'body'
|
||||
template: @overridePopoverTemplate
|
||||
)
|
||||
window.element = @$el
|
||||
@$el.on 'show.bs.popover', =>
|
||||
).on 'show.bs.popover', =>
|
||||
Backbone.Mediator.publish 'tome:palette-hovered', thang: @thang, prop: @doc.name, entry: @
|
||||
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'spell-palette-entry-open', volume: 1
|
||||
soundIndex = Math.floor(Math.random() * 4)
|
||||
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
|
||||
|
@ -65,6 +64,7 @@ module.exports = class SpellPaletteEntryView extends CocoView
|
|||
@$el.add('.spell-palette-popover.popover').removeClass 'pinned'
|
||||
$('.spell-palette-popover.popover .close').remove()
|
||||
@$el.popover 'hide'
|
||||
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'spell-palette-entry-unpin', volume: 1
|
||||
else
|
||||
@popoverPinned = true
|
||||
@$el.popover 'show'
|
||||
|
|
Loading…
Reference in a new issue