This commit is contained in:
Scott Erickson 2014-03-13 15:45:41 -07:00
commit 8431fd1e57
2 changed files with 29 additions and 32 deletions
app

View file

@ -49,8 +49,6 @@
//max-width: 1680px // guideline, but for now let's let it stretch out //max-width: 1680px // guideline, but for now let's let it stretch out
min-width: 1024px min-width: 1024px
position: relative position: relative
#playback-view
margin: 0 auto
#thang-hud #thang-hud
margin: 0 auto margin: 0 auto
display: none display: none

View file

@ -65,10 +65,15 @@ module.exports = class SpectateLevelView extends View
'ctrl+s': 'onCtrlS' 'ctrl+s': 'onCtrlS'
constructor: (options, @levelID) -> constructor: (options, @levelID) ->
@originalOptions = _.cloneDeep(options)
console.profile?() if PROFILE_ME console.profile?() if PROFILE_ME
super options super options
@sessionOne = @getQueryVariable 'session-one' if options.spectateSessions?
@sessionTwo = @getQueryVariable 'session-two' @sessionOne = options.spectateSessions.sessionOne
@sessionTwo = options.spectateSessions.sessionTwo
else
@sessionOne = @getQueryVariable 'session-one'
@sessionTwo = @getQueryVariable 'session-two'
$(window).on('resize', @onWindowResize) $(window).on('resize', @onWindowResize)
@supermodel.once 'error', @onLevelLoadError @supermodel.once 'error', @onLevelLoadError
@ -150,6 +155,7 @@ module.exports = class SpectateLevelView extends View
@initScriptManager() @initScriptManager()
@insertSubviews ladderGame: @otherSession? @insertSubviews ladderGame: @otherSession?
@initVolume() @initVolume()
@originalSessionState = _.cloneDeep(@session.get('state')) @originalSessionState = _.cloneDeep(@session.get('state'))
@register() @register()
@controlBar.setBus(@bus) @controlBar.setBus(@bus)
@ -165,7 +171,6 @@ module.exports = class SpectateLevelView extends View
name: @otherSession.get('creatorName') name: @otherSession.get('creatorName')
team: @otherSession.get('team') team: @otherSession.get('team')
grabLevelLoaderData: -> grabLevelLoaderData: ->
@session = @levelLoader.session @session = @levelLoader.session
@world = @levelLoader.world @world = @levelLoader.world
@ -247,18 +252,8 @@ module.exports = class SpectateLevelView extends View
$(@wasFocusedOn).focus() if @wasFocusedOn $(@wasFocusedOn).focus() if @wasFocusedOn
@wasFocusedOn = null @wasFocusedOn = null
onDonePressed: -> @showVictory() onDonePressed: -> return
onShowVictory: (e) ->
$('#level-done-button').show()
@showVictory() if e.showModal
setTimeout(@preloadNextLevel, 3000)
showVictory: ->
options = {level: @level, supermodel: @supermodel, session:@session}
docs = new VictoryModal(options)
@openModalView(docs)
window.tracker?.trackEvent 'Saw Victory', level: @world.name, label: @world.name
onNewWorld: (e) -> onNewWorld: (e) ->
@world = e.world @world = e.world
@ -365,7 +360,7 @@ module.exports = class SpectateLevelView extends View
initSurface: -> initSurface: ->
surfaceCanvas = $('canvas#surface', @$el) surfaceCanvas = $('canvas#surface', @$el)
@surface = new Surface(@world, surfaceCanvas, thangTypes: @supermodel.getModels(ThangType), playJingle: not @isEditorPreview) @surface = new Surface(@world, surfaceCanvas, thangTypes: @supermodel.getModels(ThangType), playJingle: not @isEditorPreview, spectateGame: true)
worldBounds = @world.getBounds() worldBounds = @world.getBounds()
bounds = [{x:worldBounds.left, y:worldBounds.top}, {x:worldBounds.right, y:worldBounds.bottom}] bounds = [{x:worldBounds.left, y:worldBounds.top}, {x:worldBounds.right, y:worldBounds.bottom}]
@surface.camera.setBounds(bounds) @surface.camera.setBounds(bounds)
@ -376,7 +371,14 @@ module.exports = class SpectateLevelView extends View
@god.goalManager = @goalManager @god.goalManager = @goalManager
initScriptManager: -> initScriptManager: ->
@scriptManager = new ScriptManager({scripts: @world.scripts or [], view:@, session: @session}) if @world.scripts
nonVictoryPlaybackScripts = _.reject @world.scripts, (script) ->
script.id.indexOf("Set Camera Boundaries and Goals") == -1
else
console.log "World scripts don't exist!"
nonVictoryPlaybackScripts = []
console.log nonVictoryPlaybackScripts
@scriptManager = new ScriptManager({scripts: nonVictoryPlaybackScripts, view:@, session: @session})
@scriptManager.loadFromSession() @scriptManager.loadFromSession()
initVolume: -> initVolume: ->
@ -388,11 +390,6 @@ module.exports = class SpectateLevelView extends View
return if @alreadyLoadedState return if @alreadyLoadedState
@alreadyLoadedState = true @alreadyLoadedState = true
state = @originalSessionState state = @originalSessionState
if state.frame
Backbone.Mediator.publish 'level-set-time', { time: 0, frameOffset: state.frame }
if state.selected
# TODO: Should also restore selected spell here by saving spellName
Backbone.Mediator.publish 'level-select-sprite', { thangID: state.selected, spellName: null }
if state.playing? if state.playing?
Backbone.Mediator.publish 'level-set-playing', { playing: state.playing } Backbone.Mediator.publish 'level-set-playing', { playing: state.playing }
@ -428,11 +425,16 @@ module.exports = class SpectateLevelView extends View
console.log "You want to see the next game!" console.log "You want to see the next game!"
@sessionOne = "53193c8f7a89df21c4d968e9" @sessionOne = "53193c8f7a89df21c4d968e9"
@sessionTwo = "531aa613026834331eac5e7e" @sessionTwo = "531aa613026834331eac5e7e"
@destroy(true) url = "/play/spectate/dungeon-arena?session-one=#{@sessionOne}&session-two=#{@sessionTwo}"
@load() Backbone.Mediator.publish 'router:navigate', {
@afterRender() route: url,
viewClass: SpectateLevelView,
viewArgs: [{spectateSessions:{sessionOne: @sessionOne, sessionTwo: @sessionTwo}}, "dungeon-arena"]}
destroy: (destroyHalfway)->
destroy: ()->
@supermodel?.off 'error', @onLevelLoadError @supermodel?.off 'error', @onLevelLoadError
@levelLoader?.off 'loaded-all', @onLevelLoaderLoaded @levelLoader?.off 'loaded-all', @onLevelLoaderLoaded
@levelLoader?.destroy() @levelLoader?.destroy()
@ -440,11 +442,9 @@ module.exports = class SpectateLevelView extends View
@god?.destroy() @god?.destroy()
@goalManager?.destroy() @goalManager?.destroy()
@scriptManager?.destroy() @scriptManager?.destroy()
unless destroyHalfway $(window).off('resize', @onWindowResize)
$(window).off('resize', @onWindowResize)
delete window.world # not sure where this is set, but this is one way to clean it up delete window.world # not sure where this is set, but this is one way to clean it up
clearInterval(@pointerInterval) clearInterval(@pointerInterval)
console.profileEnd?() if PROFILE_ME console.profileEnd?() if PROFILE_ME
@session?.off 'change:multiplayer', @onMultiplayerChanged, @ @session?.off 'change:multiplayer', @onMultiplayerChanged, @
@onLevelLoadError = null @onLevelLoadError = null
@ -452,5 +452,4 @@ module.exports = class SpectateLevelView extends View
@onSupermodelLoadedOne = null @onSupermodelLoadedOne = null
@preloadNextLevel = null @preloadNextLevel = null
@saveScreenshot = null @saveScreenshot = null
unless destroyHalfway super()
super()