userCodeMap issues fixed

Now beginning hooking up the UI
This commit is contained in:
Michael Schmatz 2014-05-06 10:06:32 -07:00
parent 97f3694dbf
commit dddd617a08
4 changed files with 52 additions and 58 deletions
app
assets/javascripts/workers
lib
views/play/level/tome

View file

@ -100,50 +100,7 @@ self.currentUserCodeMapCopy = {};
self.currentWorldFrame = 0;
self.maxSerializationDepth = 3;
self.serializeProperty = function serializeProperty(prop, depth) {
var typeOfProperty = typeof(prop);
if (["undefined","boolean","number","string","xml"].indexOf(typeOfProperty) > -1 || prop === null || prop instanceof Date || prop instanceof String)
return prop;
else if (typeOfProperty === "function") return "<function>";
else if (prop instanceof Array)
{
if (depth >= self.maxSerializationDepth) return Object.keys(prop);
else
{
var newProps = [];
for(var i= 0, arrayLength=prop.length; i < arrayLength; i++)
newProps[i] = self.serializeProperty(prop[i],depth + 1);
return newProps;
}
}
else if (prop.hasOwnProperty("id"))
{
return prop.id;
}
else if (prop.hasOwnProperty('serialize'))
{
return prop.serialize();
}
else
{
newObject = {};
for (var key in prop)
{
if (prop.hasOwnProperty(key))
{
if (depth >= self.maxSerializationDepth)
{
newObject[key] = "DEPTH EXCEEDED";
}
else
{
newObject[key] = self.serializeProperty(prop[key], depth + 1);
}
}
}
return newObject;
}
};
self.stringifyValue = function(value, depth) {
var brackets, i, isArray, isObject, key, prefix, s, sep, size, v, values, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3;
if (!value || _.isString(value)) {
@ -292,6 +249,7 @@ self.enableFlowOnThangSpell = function enableFlowOnThang(thangID, spellID, userC
userCodeMap[thangID][spellID].originalOptions.noSerializationInFlow = true;
var temporaryAether = Aether.deserialize(userCodeMap[thangID][spellID]);
temporaryAether.transpile(temporaryAether.raw);
console.log("Transpiled!");
userCodeMap[thangID][spellID] = temporaryAether.serialize();
}

View file

@ -21,6 +21,8 @@ module.exports = class God
@angels = []
@firstWorld = true
Backbone.Mediator.subscribe 'tome:cast-spells', @onTomeCast, @
@retriveValueFromFrame = _.throttle @retrieveValueFromFrame, 1000
Backbone.Mediator.subscribe 'tome:spell-debug-value-request', @retrieveValueFromFrame, @
@fillWorkerPool = _.throttle @fillWorkerPool, 3000, leading: false
@fillWorkerPool()
#TODO: have this as a constructor option
@ -76,8 +78,7 @@ module.exports = class God
when 'console-log'
console.log "|" + @id + "'s " + @id + "|", event.data.args...
when 'debug-value-return'
console.log event.data.serialized
Backbone.Mediator.publish 'god:debug-value-return', event.data.serialized
getAngel: ->
freeAngel = null
for angel in @angels
@ -140,8 +141,10 @@ module.exports = class God
goals: @goalManager?.getGoals()
frame: frame
retrieveValueFromFrame: (thangID, spellID, variableChain, frame) ->
retrieveValueFromFrame: (args) ->
if not args.thangID or not args.spellID or not args.variableChain then return
args.frame ?= @world.age / @world.dt
console.log "Retrieving value #{args.variableChain} from frame!!!"
@debugWorker.postMessage
func: 'retrieveValueFromFrame'
args:
@ -150,10 +153,10 @@ module.exports = class God
level: @level
firstWorld: @firstWorld
goals: @goalManager?.getGoals()
frame: frame
currentThangID: thangID
currentSpellID: spellID
variableChain: variableChain
frame: args.frame
currentThangID: args.thangID
currentSpellID: args.spellID
variableChain: args.variableChain
getDebugWorldCurrentFrame: ->
@ -174,6 +177,7 @@ module.exports = class God
finishBeholdingWorld: (newWorld) =>
newWorld.findFirstChangedFrame @world
@world = newWorld
@currentUserCodeMap = @filterUserCodeMapWhenFromWorld @world.userCodeMap
errorCount = (t for t in @world.thangs when t.errorsOut).length
Backbone.Mediator.publish('god:new-world-created', world: @world, firstWorld: @firstWorld, errorCount: errorCount, goalStates: @latestGoalStates, team: me.team)
for scriptNote in @world.scriptNotes
@ -184,12 +188,29 @@ module.exports = class God
unless _.find @angels, 'busy'
@spells = null # Don't hold onto old spells; memory leaks
filterUserCodeMapWhenFromWorld: (worldUserCodeMap) ->
newUserCodeMap = {}
for thangName, thang of worldUserCodeMap
newUserCodeMap[thangName] = {}
for spellName,aether of thang
shallowFilteredObject = _.pick aether, ['raw','pure','originalOptions']
newUserCodeMap[thangName][spellName] = _.cloneDeep shallowFilteredObject
newUserCodeMap[thangName][spellName] = _.defaults newUserCodeMap[thangName][spellName],
flow: {}
metrics: {}
problems:
errors: []
infos: []
warnings: []
style: {}
newUserCodeMap
getUserCodeMap: ->
userCodeMap = {}
for spellKey, spell of @spells
for thangID, spellThang of spell.thangs
(userCodeMap[thangID] ?= {})[spell.name] = spellThang.aether.serialize()
@currentUserCodeMap = userCodeMap
userCodeMap
destroy: ->

View file

@ -13,6 +13,8 @@ module.exports = class DebugView extends View
subscriptions:
'god:new-world-created': 'onNewWorld'
'god:debug-value-return': 'handleDebugValue'
'tome:spell-shown': 'changeCurrentThangAndSpell'
events: {}
@ -20,11 +22,21 @@ module.exports = class DebugView extends View
super options
@ace = options.ace
@thang = options.thang
@spell = options.spell
@variableStates = {}
@globals = {Math: Math, _: _} # ... add more as documented
for className, klass of serializedClasses
@globals[className] = klass
@onMouseMove = _.throttle @onMouseMove, 25
for className, serializedClass of serializedClasses
@globals[className] = serializedClass
@onMouseMove = _.throttle @onMouseMove, 500
changeCurrentThangAndSpell: (thangAndSpellObject) ->
@thang = thangAndSpellObject.thang
@spell = thangAndSpellObject.spell
handleDebugValue: (returnObject) ->
console.log "Got debug value!"
console.log returnObject
afterRender: ->
super()
@ -78,6 +90,10 @@ module.exports = class DebugView extends View
update: ->
if @variableChain
Backbone.Mediator.publish 'tome:spell-debug-value-request',
thangID: @thang.id
spellID: @spell.name
variableChain: @variableChain
{key, value} = @deserializeVariableChain @variableChain
@$el.find("code").text "#{key}: #{value}"
@$el.show().css(@pos)
@ -97,7 +113,6 @@ module.exports = class DebugView extends View
@hoveredProperty = if @variableChain?.length is 2 then owner: @variableChain[0], property: @variableChain[1] else {}
unless _.isEqual oldHoveredProperty, @hoveredProperty
Backbone.Mediator.publish 'tome:spell-debug-property-hovered', @hoveredProperty
updateMarker: ->
if @marker
@ace.getSession().removeMarker @marker

View file

@ -189,7 +189,7 @@ module.exports = class SpellView extends View
@createToolbarView()
createDebugView: ->
@debugView = new SpellDebugView ace: @ace, thang: @thang
@debugView = new SpellDebugView ace: @ace, thang: @thang, spell:@spell
@$el.append @debugView.render().$el.hide()
createToolbarView: ->