2016-07-12 17:07:10 -04:00
|
|
|
RootView = require 'views/core/RootView'
|
|
|
|
|
|
|
|
GameUIState = require 'models/GameUIState'
|
|
|
|
God = require 'lib/God'
|
|
|
|
LevelLoader = require 'lib/LevelLoader'
|
|
|
|
GoalManager = require 'lib/world/GoalManager'
|
|
|
|
Surface = require 'lib/surface/Surface'
|
|
|
|
ThangType = require 'models/ThangType'
|
2016-07-12 18:12:11 -04:00
|
|
|
Level = require 'models/Level'
|
|
|
|
LevelSession = require 'models/LevelSession'
|
2016-07-13 14:43:25 -04:00
|
|
|
{createAetherOptions} = require 'lib/aether_utils'
|
|
|
|
State = require 'models/State'
|
|
|
|
|
|
|
|
TEAM = 'humans'
|
2016-07-12 17:07:10 -04:00
|
|
|
|
|
|
|
module.exports = class PlayGameDevLevelView extends RootView
|
|
|
|
id: 'play-game-dev-level-view'
|
|
|
|
template: require 'templates/play/level/play-game-dev-level-view'
|
|
|
|
|
2016-07-13 14:43:25 -04:00
|
|
|
events:
|
|
|
|
'click #play-btn': 'onClickPlayButton'
|
|
|
|
|
2016-07-12 17:07:10 -04:00
|
|
|
initialize: (@options, @levelID, @sessionID) ->
|
2016-07-13 14:43:25 -04:00
|
|
|
@state = new State({
|
|
|
|
loading: true
|
|
|
|
})
|
2016-07-12 18:12:11 -04:00
|
|
|
@level = new Level()
|
|
|
|
@session = new LevelSession()
|
2016-07-12 17:07:10 -04:00
|
|
|
@gameUIState = new GameUIState()
|
|
|
|
@god = new God({ @gameUIState })
|
2016-07-13 14:43:25 -04:00
|
|
|
@levelLoader = new LevelLoader({ @supermodel, @levelID, @sessionID, observing: true, team: TEAM })
|
2016-07-12 17:07:10 -04:00
|
|
|
@listenToOnce @levelLoader, 'world-necessities-loaded', @onWorldNecessitiesLoaded
|
|
|
|
@listenTo @levelLoader, 'world-necessity-load-failed', @onWorldNecessityLoadFailed
|
2016-07-13 14:43:25 -04:00
|
|
|
@listenTo @state, 'change', _.debounce(-> @renderSelectors('#info-col'))
|
2016-07-12 17:07:10 -04:00
|
|
|
|
|
|
|
onWorldNecessitiesLoaded: ->
|
|
|
|
{ @level, @session, @world, @classMap } = @levelLoader
|
|
|
|
levelObject = @level.serialize(@supermodel, @session)
|
|
|
|
@god.setLevel(levelObject)
|
2016-07-13 14:43:25 -04:00
|
|
|
@god.setWorldClassMap(@world.classMap)
|
2016-07-12 17:07:10 -04:00
|
|
|
@goalManager = new GoalManager(@world, @level.get('goals'), @team)
|
|
|
|
@god.setGoalManager(@goalManager)
|
2016-07-13 14:43:25 -04:00
|
|
|
me.team = TEAM
|
|
|
|
@session.set 'team', TEAM
|
2016-07-12 17:07:10 -04:00
|
|
|
|
|
|
|
onWorldNecessityLoadFailed: ->
|
|
|
|
# TODO: handle these and other failures with Promises
|
|
|
|
|
|
|
|
onLoaded: ->
|
|
|
|
_.defer => @onLevelLoaderLoaded()
|
|
|
|
|
|
|
|
onLevelLoaderLoaded: ->
|
|
|
|
return unless @levelLoader.progress() is 1 # double check, since closing the guide may trigger this early
|
|
|
|
@levelLoader.destroy()
|
|
|
|
@levelLoader = null
|
|
|
|
webGLSurface = @$('canvas#webgl-surface')
|
|
|
|
normalSurface = @$('canvas#normal-surface')
|
|
|
|
@surface = new Surface(@world, normalSurface, webGLSurface, {
|
|
|
|
thangTypes: @supermodel.getModels(ThangType)
|
|
|
|
levelType: @level.get('type', true)
|
|
|
|
@gameUIState
|
|
|
|
})
|
|
|
|
worldBounds = @world.getBounds()
|
|
|
|
bounds = [{x: worldBounds.left, y: worldBounds.top}, {x: worldBounds.right, y: worldBounds.bottom}]
|
|
|
|
@surface.camera.setBounds(bounds)
|
|
|
|
@surface.camera.zoomTo({x: 0, y: 0}, 0.1, 0)
|
|
|
|
@surface.setWorld(@world)
|
2016-07-12 18:12:11 -04:00
|
|
|
@renderSelectors '#info-col'
|
2016-07-13 14:43:25 -04:00
|
|
|
@spells = @session.generateSpellsObject()
|
|
|
|
@state.set('loading', false)
|
|
|
|
|
|
|
|
onClickPlayButton: ->
|
|
|
|
@god.createWorld(@spells, false, true)
|
|
|
|
Backbone.Mediator.publish('playback:real-time-playback-started', {})
|
|
|
|
Backbone.Mediator.publish('level:set-playing', {playing: true})
|
|
|
|
@state.set('playing', true)
|