mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Optimized level serialization a bit more to make placing and moving thangs around in the level editor more fluid.
This commit is contained in:
parent
1888e9ea92
commit
975c6ad2a6
2 changed files with 24 additions and 8 deletions
|
@ -8,13 +8,13 @@ module.exports = class Level extends CocoModel
|
|||
@schema: require 'schemas/models/level'
|
||||
urlRoot: '/db/level'
|
||||
|
||||
serialize: (supermodel, session) ->
|
||||
o = @denormalize supermodel, session
|
||||
serialize: (supermodel, session, cached=false) ->
|
||||
o = @denormalize supermodel, session # hot spot to optimize
|
||||
|
||||
# Figure out Components
|
||||
o.levelComponents = $.extend true, [], (lc.attributes for lc in supermodel.getModels LevelComponent)
|
||||
o.levelComponents = if cached then @getCachedLevelComponents(supermodel) else $.extend true, [], (lc.attributes for lc in supermodel.getModels LevelComponent)
|
||||
@sortThangComponents o.thangs, o.levelComponents, 'Level Thang'
|
||||
@fillInDefaultComponentConfiguration o.thangs, o.levelComponents
|
||||
@fillInDefaultComponentConfiguration o.thangs, o.levelComponents # hot spot to optimize
|
||||
|
||||
# Figure out Systems
|
||||
systemModels = $.extend true, [], (ls.attributes for ls in supermodel.getModels LevelSystem)
|
||||
|
@ -22,12 +22,28 @@ module.exports = class Level extends CocoModel
|
|||
@fillInDefaultSystemConfiguration o.systems
|
||||
|
||||
# Figure out ThangTypes' Components
|
||||
o.thangTypes = (original: tt.get('original'), name: tt.get('name'), components: $.extend(true, [], tt.get('components')) for tt in supermodel.getModels ThangType)
|
||||
tmap = {}
|
||||
tmap[t.thangType] = true for t in o.thangs
|
||||
o.thangTypes = (original: tt.get('original'), name: tt.get('name'), components: $.extend(true, [], tt.get('components')) for tt in supermodel.getModels ThangType when tmap[tt.get('original')] or tt.isFullyLoaded())
|
||||
@sortThangComponents o.thangTypes, o.levelComponents, 'ThangType'
|
||||
@fillInDefaultComponentConfiguration o.thangTypes, o.levelComponents
|
||||
|
||||
|
||||
o
|
||||
|
||||
|
||||
cachedLevelComponents: null
|
||||
|
||||
getCachedLevelComponents: (supermodel) ->
|
||||
@cachedLevelComponents ?= {}
|
||||
levelComponents = supermodel.getModels LevelComponent
|
||||
newLevelComponents = []
|
||||
for levelComponent in levelComponents
|
||||
if levelComponent.hasLocalChanges()
|
||||
newLevelComponents.push $.extend(true, {}, levelComponent.attributes)
|
||||
continue
|
||||
@cachedLevelComponents[levelComponent.id] ?= @cachedLevelComponents[levelComponent.id] = $.extend(true, {}, levelComponent.attributes)
|
||||
newLevelComponents.push(@cachedLevelComponents[levelComponent.id])
|
||||
newLevelComponents
|
||||
|
||||
denormalize: (supermodel, session) ->
|
||||
o = $.extend true, {}, @attributes
|
||||
if o.thangs and @get('type', true) is 'hero'
|
||||
|
|
|
@ -405,7 +405,7 @@ module.exports = class ThangsTabView extends CocoView
|
|||
onThangsChanged: (e) =>
|
||||
@level.set 'thangs', @thangsTreema.data
|
||||
return if @editThangView
|
||||
serializedLevel = @level.serialize @supermodel
|
||||
serializedLevel = @level.serialize @supermodel, null, true
|
||||
try
|
||||
@world.loadFromLevel serializedLevel, false
|
||||
catch error
|
||||
|
|
Loading…
Reference in a new issue