Fixed serialization of tracked property arrays.

This commit is contained in:
Nick Winter 2014-05-01 13:23:14 -07:00
parent bebe5a0620
commit 5376a42f94
3 changed files with 13 additions and 8 deletions

View file

@ -29,8 +29,8 @@ module.exports = class ThangState
value = thang[prop]
if type is 'Vector'
@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'
@props.push = clone(value, true)
else if type is 'object' or type is 'array'
@props.push clone(value, true)
else
@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.
stringPieces = ['\x1D'] # Group Separator
for element in value
if element and element.isThang
element = element.id
stringPieces.push element, '\x1E' # Record Separator(s)
value = stringPieces.join('')
specialKey = specialValuesToKeys[value]

View file

@ -42,12 +42,15 @@ module.exports.clone = clone = (obj, skipThangs=false) ->
if skipThangs and obj.isThang
return obj
if _.isArray obj
return obj.slice()
if ArrayBufferView and obj instanceof ArrayBufferView
newInstance = new obj.constructor obj
else
newInstance = new obj.constructor()
for key of obj
newInstance[key] = clone obj[key]
return new obj.constructor obj
newInstance = new obj.constructor()
for key of obj
newInstance[key] = clone obj[key], skipThangs
newInstance

View file

@ -21,7 +21,7 @@ module.exports = class DebugView extends View
@ace = options.ace
@thang = options.thang
@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
@globals[className] = klass
@onMouseMove = _.throttle @onMouseMove, 25