From 222fa6100be0282546d3dfcf033d7290d7455c4a Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Mon, 20 Jan 2014 17:20:04 -0800 Subject: [PATCH] Set up the level editor to lazily load thang types. --- app/lib/surface/CocoSprite.coffee | 14 ++++++++++++-- app/models/ThangType.coffee | 2 +- app/views/editor/level/thangs_tab_view.coffee | 4 ++-- server/handlers/Handler.coffee | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/lib/surface/CocoSprite.coffee b/app/lib/surface/CocoSprite.coffee index 98187cb7b..3dcb70a2a 100644 --- a/app/lib/surface/CocoSprite.coffee +++ b/app/lib/surface/CocoSprite.coffee @@ -61,9 +61,19 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass @actionQueue = [] @marks = {} @labels = {} + @ticker = 0 + @displayObject = new createjs.Container() + if @thangType.get('actions') + @onThangTypeLoaded() + else + @stillLoading = true + @thangType.fetch() + @thangType.once 'sync', @onThangTypeLoaded, @ + + onThangTypeLoaded: -> + @stillLoading = false @actions = @thangType.getActions() @buildFromSpriteSheet @buildSpriteSheet() - @ticker = 0 destroy: -> super() @@ -87,7 +97,6 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass # temp, until these are re-exported with perspective if @options.camera and @thangType.get('name') in ['Dungeon Floor', 'Grass', 'Goal Trigger', 'Obstacle'] sprite.scaleY *= @options.camera.y2x - @displayObject = new createjs.Container() @imageObject = sprite @displayObject.addChild(sprite) @addHealthBar() @@ -135,6 +144,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass update: -> # Gets the sprite to reflect what the current state of the thangs and surface are + return if @stillLoading @updatePosition() @updateScale() @updateAlpha() diff --git a/app/models/ThangType.coffee b/app/models/ThangType.coffee index c2159363c..f950d1a6a 100644 --- a/app/models/ThangType.coffee +++ b/app/models/ThangType.coffee @@ -27,7 +27,7 @@ module.exports = class ThangType extends CocoModel return @actions or @buildActions() buildActions: -> - @actions = _.cloneDeep(@get('actions')) + @actions = _.cloneDeep(@get('actions') or {}) for name, action of @actions action.name = name for relatedName, relatedAction of action.relatedActions ? {} diff --git a/app/views/editor/level/thangs_tab_view.coffee b/app/views/editor/level/thangs_tab_view.coffee index c936a8858..15fa9c6c7 100644 --- a/app/views/editor/level/thangs_tab_view.coffee +++ b/app/views/editor/level/thangs_tab_view.coffee @@ -19,7 +19,7 @@ componentOriginals = "physics.Physical" : "524b75ad7fc0f6d519000001" class ThangTypeSearchCollection extends CocoCollection - url: '/db/thang_type/search' + url: '/db/thang_type/search?project=true' model: ThangType module.exports = class ThangsTabView extends View @@ -63,7 +63,7 @@ module.exports = class ThangsTabView extends View getRenderData: (context={}) => context = super(context) - context.thangTypes = (thangType.attributes for thangType in @supermodel.getModels(ThangType) when not _.isEmpty thangType.get('actions')) + context.thangTypes = (thangType.attributes for thangType in @supermodel.getModels(ThangType)) context afterRender: -> diff --git a/server/handlers/Handler.coffee b/server/handlers/Handler.coffee index 5428657bf..c193ab050 100644 --- a/server/handlers/Handler.coffee +++ b/server/handlers/Handler.coffee @@ -114,7 +114,7 @@ module.exports = class Handler @modelClass.textSearch term, filter, callback else args = [filter.filter] - args.push filter.project if req.query.project + args.push project if req.query.project @modelClass.find(args...).limit(100).exec callback versions: (req, res, id) ->