From b521aee322b6c28d98b0429aa235bef34b35c6b8 Mon Sep 17 00:00:00 2001 From: Scott Erickson <sderickson@gmail.com> Date: Tue, 2 Sep 2014 12:33:34 -0700 Subject: [PATCH] Optimized level serialization a little so that level editing is a bit less painful. --- app/models/Level.coffee | 10 +++++----- app/views/editor/level/thangs/ThangsTabView.coffee | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/Level.coffee b/app/models/Level.coffee index be7364bac..fc49d8dfb 100644 --- a/app/models/Level.coffee +++ b/app/models/Level.coffee @@ -12,12 +12,12 @@ module.exports = class Level extends CocoModel o = @denormalize supermodel, session # Figure out Components - o.levelComponents = _.cloneDeep (lc.attributes for lc in supermodel.getModels LevelComponent) + o.levelComponents = $.extend true, [], (lc.attributes for lc in supermodel.getModels LevelComponent) @sortThangComponents o.thangs, o.levelComponents, 'Level Thang' @fillInDefaultComponentConfiguration o.thangs, o.levelComponents # Figure out Systems - systemModels = _.cloneDeep (ls.attributes for ls in supermodel.getModels LevelSystem) + systemModels = $.extend true, [], (ls.attributes for ls in supermodel.getModels LevelSystem) o.systems = @sortSystems o.systems, systemModels @fillInDefaultSystemConfiguration o.systems @@ -93,7 +93,7 @@ module.exports = class Level extends CocoModel system2 = _.find levelSystems, {original: d.original} visit system2 #console.log 'sorted systems adding', systemModel.name - sorted.push {model: systemModel, config: _.cloneDeep system.config} + sorted.push {model: systemModel, config: $.extend true, {}, system.config} originalsSeen[system.original] = true visit system for system in levelSystems ? [] sorted @@ -140,7 +140,7 @@ module.exports = class Level extends CocoModel for component in thang.components or [] continue unless lc = _.find levelComponents, {original: component.original} component.config ?= {} - TreemaUtils.populateDefaults(component.config, lc.configSchema) + TreemaUtils.populateDefaults(component.config, lc.configSchema, tv4) @lastType = 'component' @lastOriginal = component.original @walkDefaults component.config, lc.configSchema.properties @@ -148,7 +148,7 @@ module.exports = class Level extends CocoModel fillInDefaultSystemConfiguration: (levelSystems) -> for system in levelSystems ? [] system.config ?= {} - TreemaUtils.populateDefaults(system.config, system.model.configSchema) + TreemaUtils.populateDefaults(system.config, system.model.configSchema, tv4) @lastType = 'system' @lastOriginal = system.model.name @walkDefaults system.config, system.model.configSchema.properties diff --git a/app/views/editor/level/thangs/ThangsTabView.coffee b/app/views/editor/level/thangs/ThangsTabView.coffee index c2d9b0d35..0fa9dc1cf 100644 --- a/app/views/editor/level/thangs/ThangsTabView.coffee +++ b/app/views/editor/level/thangs/ThangsTabView.coffee @@ -412,7 +412,7 @@ module.exports = class ThangsTabView extends CocoView # update selection, since the thangs have been remade if @selectedExtantThang @selectedExtantSprite = @surface.spriteBoss.sprites[@selectedExtantThang.id] - @selectedExtantThang = @selectedExtantSprite.thang + @selectedExtantThang = @selectedExtantSprite?.thang Backbone.Mediator.publish 'editor:thangs-edited', thangs: @world.thangs onTreemaThangSelected: (e, selectedTreemas) =>