Using isThang instead of instanceof Thang.

This commit is contained in:
Nick Winter 2014-03-13 17:59:17 -07:00
parent 8ccd12866e
commit 8b572f0647
4 changed files with 5 additions and 7 deletions

View file

@ -23,7 +23,7 @@ module.exports = class Thang
name name
@resetThangIDs: -> Thang.remainingThangNames = {} @resetThangIDs: -> Thang.remainingThangNames = {}
isThang: true
apiProperties: ['id', 'spriteName', 'health', 'pos', 'team'] apiProperties: ['id', 'spriteName', 'health', 'pos', 'team']
constructor: (@world, @spriteName, @id) -> constructor: (@world, @spriteName, @id) ->

View file

@ -18,11 +18,11 @@ module.exports = class WorldScriptNote
serialize: -> serialize: ->
o = {channel: @channel, event: {}} o = {channel: @channel, event: {}}
for key, value of @event for key, value of @event
if value instanceof Thang if value?.isThang
value = {isThang: true, id: value.id} value = {isThang: true, id: value.id}
else if _.isArray value else if _.isArray value
for subval, i in value for subval, i in value
if subval instanceof Thang if subval?.isThang
value[i] = {isThang: true, id: subval.id} value[i] = {isThang: true, id: subval.id}
o.event[key] = value o.event[key] = value
o o

View file

@ -39,9 +39,7 @@ module.exports.clone = clone = (obj, skipThangs=false) ->
if (obj instanceof Vector) or (obj instanceof Rectangle) if (obj instanceof Vector) or (obj instanceof Rectangle)
return obj.copy() return obj.copy()
# We don't have Thang class here, but we can fake it to avoid the circular import if skipThangs and obj.isThang
#if skipThangs and obj instanceof Thang
if skipThangs and obj.id? and obj.trackedPropertiesKeys?
return obj return obj
if ArrayBufferView and obj instanceof ArrayBufferView if ArrayBufferView and obj instanceof ArrayBufferView

View file

@ -32,7 +32,7 @@
"firepad": "~0.1.2", "firepad": "~0.1.2",
"marked": "~0.3.0", "marked": "~0.3.0",
"moment": "~2.5.0", "moment": "~2.5.0",
"aether": "~0.1.9", "aether": "~0.1.10",
"underscore.string": "~2.3.3", "underscore.string": "~2.3.3",
"firebase": "~1.0.2", "firebase": "~1.0.2",
"catiline": "~2.9.3" "catiline": "~2.9.3"