mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -05:00
Fixed serialization of tracked property arrays.
This commit is contained in:
parent
bebe5a0620
commit
5376a42f94
3 changed files with 13 additions and 8 deletions
|
@ -29,8 +29,8 @@ module.exports = class ThangState
|
||||||
value = thang[prop]
|
value = thang[prop]
|
||||||
if type is 'Vector'
|
if type is 'Vector'
|
||||||
@props.push value?.copy() # could try storing [x, y, z] or {x, y, z} here instead if this is expensive
|
@props.push value?.copy() # could try storing [x, y, z] or {x, y, z} here instead if this is expensive
|
||||||
else if type is 'object'
|
else if type is 'object' or type is 'array'
|
||||||
@props.push = clone(value, true)
|
@props.push clone(value, true)
|
||||||
else
|
else
|
||||||
@props.push value
|
@props.push value
|
||||||
|
|
||||||
|
@ -144,6 +144,8 @@ module.exports = class ThangState
|
||||||
# We make sure the array keys won't collide with any string keys by using some unprintable characters.
|
# We make sure the array keys won't collide with any string keys by using some unprintable characters.
|
||||||
stringPieces = ['\x1D'] # Group Separator
|
stringPieces = ['\x1D'] # Group Separator
|
||||||
for element in value
|
for element in value
|
||||||
|
if element and element.isThang
|
||||||
|
element = element.id
|
||||||
stringPieces.push element, '\x1E' # Record Separator(s)
|
stringPieces.push element, '\x1E' # Record Separator(s)
|
||||||
value = stringPieces.join('')
|
value = stringPieces.join('')
|
||||||
specialKey = specialValuesToKeys[value]
|
specialKey = specialValuesToKeys[value]
|
||||||
|
|
|
@ -42,12 +42,15 @@ module.exports.clone = clone = (obj, skipThangs=false) ->
|
||||||
if skipThangs and obj.isThang
|
if skipThangs and obj.isThang
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
if _.isArray obj
|
||||||
|
return obj.slice()
|
||||||
|
|
||||||
if ArrayBufferView and obj instanceof ArrayBufferView
|
if ArrayBufferView and obj instanceof ArrayBufferView
|
||||||
newInstance = new obj.constructor obj
|
return new obj.constructor obj
|
||||||
else
|
|
||||||
newInstance = new obj.constructor()
|
newInstance = new obj.constructor()
|
||||||
for key of obj
|
for key of obj
|
||||||
newInstance[key] = clone obj[key]
|
newInstance[key] = clone obj[key], skipThangs
|
||||||
|
|
||||||
newInstance
|
newInstance
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ module.exports = class DebugView extends View
|
||||||
@ace = options.ace
|
@ace = options.ace
|
||||||
@thang = options.thang
|
@thang = options.thang
|
||||||
@variableStates = {}
|
@variableStates = {}
|
||||||
@globals = {Math: Math, _: _} # ... add more as documented
|
@globals = {Math: Math, _: _, String: String, Number: Number, Array: Array, Object: Object} # ... add more as documented
|
||||||
for className, klass of serializedClasses
|
for className, klass of serializedClasses
|
||||||
@globals[className] = klass
|
@globals[className] = klass
|
||||||
@onMouseMove = _.throttle @onMouseMove, 25
|
@onMouseMove = _.throttle @onMouseMove, 25
|
||||||
|
|
Loading…
Reference in a new issue