Merge branch 'master' into production

This commit is contained in:
Nick Winter 2014-09-25 11:38:23 -07:00
commit cb01a30b1d
6 changed files with 45 additions and 8 deletions

View file

@ -12,6 +12,8 @@ module.exports = class MusicPlayer extends CocoClass
subscriptions: subscriptions:
'music-player:play-music': 'onPlayMusic' 'music-player:play-music': 'onPlayMusic'
'audio-player:loaded': 'onAudioLoaded' 'audio-player:loaded': 'onAudioLoaded'
'playback:real-time-playback-started': 'onRealTimePlaybackStarted'
'playback:real-time-playback-ended': 'onRealTimePlaybackEnded'
constructor: -> constructor: ->
super arguments... super arguments...
@ -62,6 +64,17 @@ module.exports = class MusicPlayer extends CocoClass
createjs.Tween.removeTweens(@currentMusic) createjs.Tween.removeTweens(@currentMusic)
@currentMusic.volume = if me.get('music') then MUSIC_VOLUME else 0.0 @currentMusic.volume = if me.get('music') then MUSIC_VOLUME else 0.0
onRealTimePlaybackStarted: (e) ->
@previousMusic = @currentMusic
trackNumber = _.random 0, 2
Backbone.Mediator.publish 'music-player:play-music', file: "/music/music_real_time_#{trackNumber}", play: true
onRealTimePlaybackEnded: (e) ->
@fadeOutCurrentMusic()
if @previousMusic
@currentMusic = @previousMusic
@restartCurrentMusic()
destroy: -> destroy: ->
me.off 'change:music', @onMusicSettingChanged, @ me.off 'change:music', @onMusicSettingChanged, @
super() super()

View file

@ -19,6 +19,8 @@ PointChooser = require './PointChooser'
RegionChooser = require './RegionChooser' RegionChooser = require './RegionChooser'
MusicPlayer = require './MusicPlayer' MusicPlayer = require './MusicPlayer'
resizeDelay = 500 # At least as much as $level-resize-transition-time.
module.exports = Surface = class Surface extends CocoClass module.exports = Surface = class Surface extends CocoClass
stage: null stage: null
@ -88,7 +90,7 @@ module.exports = Surface = class Surface extends CocoClass
@options = _.extend(@options, givenOptions) if givenOptions @options = _.extend(@options, givenOptions) if givenOptions
@initEasel() @initEasel()
@initAudio() @initAudio()
@onResize = _.debounce @onResize, 500 # At least as much as $level-resize-transition-time. @onResize = _.debounce @onResize, resizeDelay
$(window).on 'resize', @onResize $(window).on 'resize', @onResize
if @world.ended if @world.ended
_.defer => @setWorld @world _.defer => @setWorld @world
@ -545,6 +547,7 @@ module.exports = Surface = class Surface extends CocoClass
return unless @realTime return unless @realTime
@realTime = false @realTime = false
@onResize() @onResize()
_.delay @onResize, resizeDelay + 100 # Do it again just to be double sure that we don't stay zoomed in due to timing problems.
@spriteBoss.selfWizardSprite?.toggle true @spriteBoss.selfWizardSprite?.toggle true
@canvas.removeClass 'flag-color-selected' @canvas.removeClass 'flag-color-selected'
if @previousCameraZoom if @previousCameraZoom

View file

@ -98,6 +98,7 @@ module.exports = class World
continueLaterFn = => continueLaterFn = =>
@loadFrames(loadedCallback, errorCallback, loadProgressCallback, preloadedCallback, skipDeferredLoading, loadUntilFrame) unless @destroyed @loadFrames(loadedCallback, errorCallback, loadProgressCallback, preloadedCallback, skipDeferredLoading, loadUntilFrame) unless @destroyed
if @realTime and not @countdownFinished if @realTime and not @countdownFinished
@realTimeSpeedFactor ?= 1
return setTimeout @finishCountdown(continueLaterFn), REAL_TIME_COUNTDOWN_DELAY return setTimeout @finishCountdown(continueLaterFn), REAL_TIME_COUNTDOWN_DELAY
t1 = now() t1 = now()
@t0 ?= t1 @t0 ?= t1
@ -136,18 +137,18 @@ module.exports = class World
shouldDelayRealTimeSimulation: (t) -> shouldDelayRealTimeSimulation: (t) ->
return false unless @realTime return false unless @realTime
timeSinceStart = t - @worldLoadStartTime timeSinceStart = (t - @worldLoadStartTime) * @realTimeSpeedFactor
timeLoaded = @frames.length * @dt * 1000 timeLoaded = @frames.length * @dt * 1000
timeBuffered = timeLoaded - timeSinceStart timeBuffered = timeLoaded - timeSinceStart
timeBuffered > REAL_TIME_BUFFER_MAX timeBuffered > REAL_TIME_BUFFER_MAX * @realTimeSpeedFactor
shouldUpdateRealTimePlayback: (t) -> shouldUpdateRealTimePlayback: (t) ->
return false unless @realTime return false unless @realTime
return false if @frames.length * @dt is @lastRealTimeUpdate return false if @frames.length * @dt is @lastRealTimeUpdate
timeLoaded = @frames.length * @dt * 1000 timeLoaded = @frames.length * @dt * 1000
timeSinceStart = t - @worldLoadStartTime timeSinceStart = (t - @worldLoadStartTime) * @realTimeSpeedFactor
remainingBuffer = @lastRealTimeUpdate * 1000 - timeSinceStart remainingBuffer = @lastRealTimeUpdate * 1000 - timeSinceStart
remainingBuffer < REAL_TIME_BUFFER_MIN remainingBuffer < REAL_TIME_BUFFER_MIN * @realTimeSpeedFactor
shouldContinueLoading: (t1, loadProgressCallback, skipDeferredLoading, continueLaterFn) -> shouldContinueLoading: (t1, loadProgressCallback, skipDeferredLoading, continueLaterFn) ->
t2 = now() t2 = now()
@ -192,6 +193,8 @@ module.exports = class World
@flagHistory.push flagEvent @flagHistory.push flagEvent
loadFromLevel: (level, willSimulate=true) -> loadFromLevel: (level, willSimulate=true) ->
if level.slug in ['the-first-kithmaze', 'the-second-kithmaze', 'the-final-kithmaze']
@realTimeSpeedFactor = 3
@levelComponents = level.levelComponents @levelComponents = level.levelComponents
@thangTypes = level.thangTypes @thangTypes = level.thangTypes
@loadSystemsFromLevel level @loadSystemsFromLevel level

View file

@ -378,7 +378,7 @@ module.exports = nativeDescription: "Português (Portugal)", englishDescription:
done: "Concluir" done: "Concluir"
customize_wizard: "Personalizar Feiticeiro" customize_wizard: "Personalizar Feiticeiro"
home: "Início" home: "Início"
# skip: "Skip" skip: "Saltar"
game_menu: "Menu do Jogo" game_menu: "Menu do Jogo"
guide: "Guia" guide: "Guia"
restart: "Reiniciar" restart: "Reiniciar"
@ -400,7 +400,7 @@ module.exports = nativeDescription: "Português (Portugal)", englishDescription:
victory_rate_the_level: "Classifica este nível: " victory_rate_the_level: "Classifica este nível: "
victory_return_to_ladder: "Voltar à Classificação" victory_return_to_ladder: "Voltar à Classificação"
victory_play_next_level: "Jogar Próximo Nível" victory_play_next_level: "Jogar Próximo Nível"
# victory_play_continue: "Continue" victory_play_continue: "Continuar"
victory_go_home: "Ir para o Início" victory_go_home: "Ir para o Início"
victory_review: "Conta-nos mais!" victory_review: "Conta-nos mais!"
victory_hour_of_code_done: "Terminaste?" victory_hour_of_code_done: "Terminaste?"
@ -419,7 +419,7 @@ module.exports = nativeDescription: "Português (Portugal)", englishDescription:
tome_select_spell: "Seleciona um Feitiço" tome_select_spell: "Seleciona um Feitiço"
tome_select_a_thang: "Seleciona Alguém para " tome_select_a_thang: "Seleciona Alguém para "
tome_available_spells: "Feitiços Disponíveis" tome_available_spells: "Feitiços Disponíveis"
# tome_your_skills: "Your Skills" tome_your_skills: "As Tuas Habilidades"
hud_continue: "Continuar (shift-espaço)" hud_continue: "Continuar (shift-espaço)"
spell_saved: "Feitiço Guardado" spell_saved: "Feitiço Guardado"
skip_tutorial: "Saltar (esc)" skip_tutorial: "Saltar (esc)"

View file

@ -33,9 +33,13 @@ module.exports = class WorldMapView extends RootView
@listenToOnce @sessions, 'sync', @onSessionsLoaded @listenToOnce @sessions, 'sync', @onSessionsLoaded
@getLevelPlayCounts() @getLevelPlayCounts()
$(window).on 'resize', @onWindowResize $(window).on 'resize', @onWindowResize
@playAmbientSound()
destroy: -> destroy: ->
$(window).off 'resize', @onWindowResize $(window).off 'resize', @onWindowResize
if ambientSound = @ambientSound
# Doesn't seem to work; stops immediately.
createjs.Tween.get(ambientSound).to({volume: 0.0}, 1500).call -> ambientSound.stop()
super() super()
getLevelPlayCounts: -> getLevelPlayCounts: ->
@ -156,6 +160,19 @@ module.exports = class WorldMapView extends RootView
resultingMarginY = (pageHeight - resultingHeight) / 2 resultingMarginY = (pageHeight - resultingHeight) / 2
@$el.find('.map').css(width: resultingWidth, height: resultingHeight, 'margin-left': resultingMarginX, 'margin-top': resultingMarginY) @$el.find('.map').css(width: resultingWidth, height: resultingHeight, 'margin-left': resultingMarginX, 'margin-top': resultingMarginY)
playAmbientSound: ->
return if @ambientSound
terrain = 'Grass'
return unless file = {Dungeon: 'ambient-map-dungeon', Grass: 'ambient-map-grass'}[terrain]
src = "/file/interface/#{file}#{AudioPlayer.ext}"
unless AudioPlayer.getStatus(src)?.loaded
AudioPlayer.preloadSound src
Backbone.Mediator.subscribeOnce 'audio-player:loaded', @playAmbientSound, @
return
@ambientSound = createjs.Sound.play src, loop: -1, volume: 0.1
createjs.Tween.get(@ambientSound).to({volume: 1.0}, 1000)
tutorials = [ tutorials = [
{ {
name: 'Rescue Mission' name: 'Rescue Mission'

View file

@ -312,6 +312,7 @@ module.exports = class LevelPlaybackView extends CocoView
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'real-time-playback-end', volume: 1 Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'real-time-playback-end', volume: 1
onStopRealTimePlayback: (e) -> onStopRealTimePlayback: (e) ->
Backbone.Mediator.publish 'level:set-letterbox', on: false
Backbone.Mediator.publish 'playback:real-time-playback-ended', {} Backbone.Mediator.publish 'playback:real-time-playback-ended', {}
onSetDebug: (e) -> onSetDebug: (e) ->