mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 08:50:58 -05:00
Fixed building Thangs with new Components that no other Thang uses. Fixed THangs with id 0 in the level editor.
This commit is contained in:
parent
13fe1bbece
commit
4c33b98e27
4 changed files with 18 additions and 14 deletions
|
@ -119,7 +119,7 @@ module.exports = class Angel extends CocoClass
|
|||
return if @aborting
|
||||
# Toggle BOX2D_ENABLED during deserialization so that if we have box2d in the namespace, the Collides Components still don't try to create bodies for deserialized Thangs upon attachment.
|
||||
window.BOX2D_ENABLED = false
|
||||
@streamingWorld = World.deserialize serialized, @shared.worldClassMap, @shared.lastSerializedWorldFrames, @finishBeholdingWorld(goalStates), startFrame, endFrame, streamingWorld
|
||||
@streamingWorld = World.deserialize serialized, @shared.worldClassMap, @shared.lastSerializedWorldFrames, @finishBeholdingWorld(goalStates), startFrame, endFrame, @work.level, streamingWorld
|
||||
window.BOX2D_ENABLED = true
|
||||
@shared.lastSerializedWorldFrames = serialized.frames
|
||||
|
||||
|
@ -253,7 +253,7 @@ module.exports = class Angel extends CocoClass
|
|||
work.testWorld.goalManager.worldGenerationEnded() if work.testWorld.ended
|
||||
serialized = testWorld.serialize()
|
||||
window.BOX2D_ENABLED = false
|
||||
World.deserialize serialized.serializedWorld, @shared.worldClassMap, @shared.lastSerializedWorldFrames, @finishBeholdingWorld(goalStates), serialized.startFrame, serialized.endFrame
|
||||
World.deserialize serialized.serializedWorld, @shared.worldClassMap, @shared.lastSerializedWorldFrames, @finishBeholdingWorld(goalStates), serialized.startFrame, work.level, serialized.endFrame
|
||||
window.BOX2D_ENABLED = true
|
||||
@shared.lastSerializedWorldFrames = serialized.serializedWorld.frames
|
||||
|
||||
|
|
|
@ -151,10 +151,14 @@ module.exports = class Thang
|
|||
o.unusedTrackedPropertyKeys = (@trackedPropertiesKeys[propIndex] for used, propIndex in @trackedPropertiesUsed when not used)
|
||||
o
|
||||
|
||||
@deserialize: (o, world, classMap) ->
|
||||
@deserialize: (o, world, classMap, levelComponents) ->
|
||||
t = new Thang world, o.spriteName, o.id
|
||||
for [componentClassName, componentConfig] in o.components
|
||||
componentClass = classMap[componentClassName]
|
||||
unless componentClass = classMap[componentClassName]
|
||||
console.debug 'Compiling new Component while deserializing:', componentClassName
|
||||
componentModel = _.find levelComponents, name: componentClassName
|
||||
componentClass = world.loadClassFromCode componentModel.js, componentClassName, 'component'
|
||||
world.classMap[componentClassName] = componentClass
|
||||
t.addComponents [componentClass, componentConfig]
|
||||
t.unusedTrackedPropertyKeys = o.unusedTrackedPropertyKeys
|
||||
t.unusedTrackedPropertyValues = (t[prop] for prop in o.unusedTrackedPropertyKeys)
|
||||
|
|
|
@ -436,7 +436,7 @@ module.exports = class World
|
|||
console.log 'Whoa, serializing a lot of WorldScriptNotes here:', o.scriptNotes.length
|
||||
{serializedWorld: o, transferableObjects: [o.storageBuffer], startFrame: startFrame, endFrame: endFrame}
|
||||
|
||||
@deserialize: (o, classMap, oldSerializedWorldFrames, finishedWorldCallback, startFrame, endFrame, streamingWorld) ->
|
||||
@deserialize: (o, classMap, oldSerializedWorldFrames, finishedWorldCallback, startFrame, endFrame, level, streamingWorld) ->
|
||||
# Code hotspot; optimize it
|
||||
#console.log 'Deserializing', o, 'length', JSON.stringify(o).length
|
||||
#console.log JSON.stringify(o)
|
||||
|
@ -461,10 +461,10 @@ module.exports = class World
|
|||
perf.t1 = now()
|
||||
if w.thangs.length
|
||||
for thangConfig in o.thangs when not w.thangMap[thangConfig.id]
|
||||
w.thangs.push thang = Thang.deserialize(thangConfig, w, classMap)
|
||||
w.thangs.push thang = Thang.deserialize(thangConfig, w, classMap, level.levelComponents)
|
||||
w.setThang thang
|
||||
else
|
||||
w.thangs = (Thang.deserialize(thang, w, classMap) for thang in o.thangs)
|
||||
w.thangs = (Thang.deserialize(thang, w, classMap, level.levelComponents) for thang in o.thangs)
|
||||
w.setThang thang for thang in w.thangs
|
||||
w.scriptNotes = (WorldScriptNote.deserialize(sn, w, classMap) for sn in o.scriptNotes)
|
||||
perf.t2 = now()
|
||||
|
|
|
@ -52,7 +52,7 @@ module.exports = class ThangsTabView extends CocoView
|
|||
'click #thangs-palette-toggle': 'toggleThangsPalette'
|
||||
# 'click .add-thang-palette-icon': 'toggleThangsPalette'
|
||||
'click #rotation-menu-item button': 'onClickRotationButton'
|
||||
|
||||
|
||||
shortcuts:
|
||||
'esc': 'selectAddThang'
|
||||
'delete, del, backspace': 'deleteSelectedExtantThang'
|
||||
|
@ -501,7 +501,7 @@ module.exports = class ThangsTabView extends CocoView
|
|||
# foldered thangs -> array of thangs
|
||||
flattened = []
|
||||
for key, value of thangs
|
||||
if value.id and value.thangType
|
||||
if value.id? and value.thangType
|
||||
flattened.push value
|
||||
else
|
||||
flattened = flattened.concat @flattenThangs(value)
|
||||
|
@ -621,7 +621,7 @@ module.exports = class ThangsTabView extends CocoView
|
|||
$('#contextmenu').show()
|
||||
|
||||
#- Context menu callbacks
|
||||
|
||||
|
||||
onDeleteClicked: (e) ->
|
||||
$('#contextmenu').hide()
|
||||
@deleteSelectedExtantThang e
|
||||
|
@ -634,7 +634,7 @@ module.exports = class ThangsTabView extends CocoView
|
|||
$('#contextmenu').hide()
|
||||
rotation = parseFloat($(e.target).closest('button').data('rotation'))
|
||||
@rotateSelectedThangBy rotation * Math.PI
|
||||
|
||||
|
||||
rotateSelectedThangBy: (radians) ->
|
||||
return unless @selectedExtantThang
|
||||
@hush = true
|
||||
|
@ -645,7 +645,7 @@ module.exports = class ThangsTabView extends CocoView
|
|||
@thangsTreema.set(@pathForThang(thangData), thangData)
|
||||
@hush = false
|
||||
@onThangsChanged()
|
||||
|
||||
|
||||
toggleThangsContainer: (e) ->
|
||||
$('#all-thangs').toggleClass('hide')
|
||||
|
||||
|
@ -675,10 +675,10 @@ class ThangsFolderNode extends TreemaNode.nodeMap.object
|
|||
valEl.append(el)
|
||||
|
||||
countThangs: (data) ->
|
||||
return 0 if data.thangType and data.id
|
||||
return 0 if data.thangType and data.id?
|
||||
num = 0
|
||||
for key, value of data
|
||||
if value.thangType and value.id
|
||||
if value.thangType and value.id?
|
||||
num += 1
|
||||
else
|
||||
num += @countThangs(value)
|
||||
|
|
Loading…
Reference in a new issue