Set up the level editor to lazily load thang types.

This commit is contained in:
Scott Erickson 2014-01-20 17:20:04 -08:00
parent 5a78d92173
commit 222fa6100b
4 changed files with 16 additions and 6 deletions

View file

@ -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()

View file

@ -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 ? {}

View file

@ -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: ->

View file

@ -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) ->