From 25e348c5ad749693e853eaf12e2c1169fb1d115a Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Tue, 12 Jul 2016 14:07:10 -0700 Subject: [PATCH] Initial, basically working PlayGameDevLevelView --- app/core/Router.coffee | 3 +- .../play/level/play-game-dev-level-view.jade | 3 + .../play/level/PlayGameDevLevelView.coffee | 59 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 app/templates/play/level/play-game-dev-level-view.jade create mode 100644 app/views/play/level/PlayGameDevLevelView.coffee diff --git a/app/core/Router.coffee b/app/core/Router.coffee index bec320c7b..4890b9bb5 100644 --- a/app/core/Router.coffee +++ b/app/core/Router.coffee @@ -132,6 +132,7 @@ module.exports = class CocoRouter extends Backbone.Router 'play/ladder/:levelID': go('ladder/LadderView') 'play/ladder': go('ladder/MainLadderView') 'play/level/:levelID': go('play/level/PlayLevelView') + 'play/game-dev-level/:levelID/:sessionID': go('play/level/PlayGameDevLevelView') 'play/spectate/:levelID': go('play/SpectateView') 'play/:map': go('play/CampaignView') @@ -192,7 +193,7 @@ module.exports = class CocoRouter extends Backbone.Router @listenToOnce application.moduleLoader, 'load-complete', -> @routeDirectly(path, args, options) return - return @openView @notFoundView() if not ViewClass + return go('NotFoundView') if not ViewClass view = new ViewClass(options, args...) # options, then any path fragment args view.render() @openView(view) diff --git a/app/templates/play/level/play-game-dev-level-view.jade b/app/templates/play/level/play-game-dev-level-view.jade new file mode 100644 index 000000000..dd63be30c --- /dev/null +++ b/app/templates/play/level/play-game-dev-level-view.jade @@ -0,0 +1,3 @@ +#canvas-wrapper + canvas(width=924, height=589)#webgl-surface + canvas(width=924, height=589)#normal-surface diff --git a/app/views/play/level/PlayGameDevLevelView.coffee b/app/views/play/level/PlayGameDevLevelView.coffee new file mode 100644 index 000000000..6502c7ee3 --- /dev/null +++ b/app/views/play/level/PlayGameDevLevelView.coffee @@ -0,0 +1,59 @@ +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' + +module.exports = class PlayGameDevLevelView extends RootView + id: 'play-game-dev-level-view' + template: require 'templates/play/level/play-game-dev-level-view' + + subscriptions: + 'level:started': 'onLevelStarted' + + initialize: (@options, @levelID, @sessionID) -> + @gameUIState = new GameUIState() + @god = new God({ @gameUIState }) + @levelLoader = new LevelLoader({ @supermodel, @levelID, @sessionID, observing: true }) + @listenToOnce @levelLoader, 'world-necessities-loaded', @onWorldNecessitiesLoaded + @listenTo @levelLoader, 'world-necessity-load-failed', @onWorldNecessityLoadFailed + + onWorldNecessitiesLoaded: -> + { @level, @session, @world, @classMap } = @levelLoader + levelObject = @level.serialize(@supermodel, @session) + @god.setLevel(levelObject) + @god.setWorldClassMap(@classMap) + @goalManager = new GoalManager(@world, @level.get('goals'), @team) + @god.setGoalManager(@goalManager) + + 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 + @initSurface() + + initSurface: -> + 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) + + onLevelStarted: -> + console.log 'level started'