Added tracking properties to systems.

This commit is contained in:
Scott Erickson 2014-01-13 16:58:17 -08:00
parent dbbfbcf861
commit 05f4840369

View file

@ -245,11 +245,17 @@ module.exports = class World
addScripts: (scripts...) ->
@scripts = (@scripts ? []).concat scripts
addTrackedProperties: (props...) ->
@trackedProperties = (@trackedProperties ? []).concat props
serialize: ->
# Code hotspot; optimize it
if @frames.length < @totalFrames then worldShouldBeOverBeforeSerialization
[transferableObjects, nontransferableObjects] = [0, 0]
o = {name: @name, totalFrames: @totalFrames, maxTotalFrames: @maxTotalFrames, frameRate: @frameRate, dt: @dt, victory: @victory, userCodeMap: {}, showCoordinates: @showCoordinates, showGrid: @showGrid, showPaths: @showPaths, indieSprites: @indieSprites}
o = {name: @name, totalFrames: @totalFrames, maxTotalFrames: @maxTotalFrames, frameRate: @frameRate, dt: @dt, victory: @victory, userCodeMap: {}}
o[prop] = @[prop] for prop in @trackedProperties or []
for thangID, methods of @userCodeMap
serializedMethods = o.userCodeMap[thangID] = {}
for methodName, method of methods