mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-24 11:50:58 -04:00
Refactored hover debugger is functional
Still needs optimizations and a few bug fixes, but it’s better than the existing code existing to Nick
This commit is contained in:
parent
e8d26af985
commit
da575f8945
4 changed files with 36 additions and 48 deletions
app
assets/javascripts/workers
lib
views/play/level/tome
|
@ -147,6 +147,7 @@ self.stringifyValue = function(value, depth) {
|
|||
_ref2 = (_ref1 = value.apiProperties) != null ? _ref1 : _.keys(value);
|
||||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
||||
key = _ref2[_j];
|
||||
if (key[0] === "_") continue;
|
||||
s = this.stringifyValue(value[key], depth + 1);
|
||||
if (s !== void 0) {
|
||||
values.push(key + ": " + s);
|
||||
|
@ -207,7 +208,7 @@ self.updateCache = function (thangID, spellID, variableChain, frame, value) {
|
|||
|
||||
self.retrieveValueFromFrame = function retrieveValueFromFrame(args) {
|
||||
var cacheValue;
|
||||
if (cacheValue = self.retrieveValueFromCache(args.currentThangID, args.currentSpellID, args.variableChain, args.frame))
|
||||
if (args.frame === self.currentWorldFrame && (cacheValue = self.retrieveValueFromCache(args.currentThangID, args.currentSpellID, args.variableChain, args.frame)))
|
||||
return self.postMessage({type: 'debug-value-return', serialized: {"key": args.variableChain.join(), "value": cacheValue}});
|
||||
|
||||
|
||||
|
@ -265,9 +266,8 @@ self.retrieveValueFromFrame = function retrieveValueFromFrame(args) {
|
|||
};
|
||||
self.enableFlowOnThangSpell(args.currentThangID, args.currentSpellID, args.userCodeMap);
|
||||
self.setupWorldToRunUntilFrame(args);
|
||||
//You need to load until the very next frame, as the state is gathered at the next frame, this might be a source of bugs!
|
||||
self.world.loadFramesUntilFrame(
|
||||
args.frame + 1,
|
||||
args.frame,
|
||||
retrieveProperty.bind({},args.currentThangID, args.currentSpellID, args.variableChain),
|
||||
self.onWorldError,
|
||||
self.onWorldLoadProgress
|
||||
|
@ -304,26 +304,28 @@ self.setupWorldToRunUntilFrame = function setupWorldToRunUntilFrame(args) {
|
|||
|
||||
var stringifiedUserCodeMap = JSON.stringify(args.userCodeMap);
|
||||
var userCodeMapHasChanged = ! _.isEqual(self.currentUserCodeMapCopy, stringifiedUserCodeMap);
|
||||
if (userCodeMapHasChanged) self.invalidateCache();
|
||||
self.currentUserCodeMapCopy = stringifiedUserCodeMap;
|
||||
try {
|
||||
self.world = new World(args.worldName, args.userCodeMap);
|
||||
if(args.level)
|
||||
self.world.loadFromLevel(args.level, true);
|
||||
self.goalManager = new GoalManager(self.world);
|
||||
self.goalManager.setGoals(args.goals);
|
||||
self.goalManager.setCode(args.userCodeMap);
|
||||
self.goalManager.worldGenerationWillBegin();
|
||||
self.world.setGoalManager(self.goalManager);
|
||||
}
|
||||
catch (error) {
|
||||
self.onWorldError(error);
|
||||
return;
|
||||
}
|
||||
Math.random = self.world.rand.randf; // so user code is predictable
|
||||
if (!self.world || userCodeMapHasChanged || args.frame != self.currentWorldFrame) {
|
||||
self.invalidateCache();
|
||||
try {
|
||||
self.world = new World(args.worldName, args.userCodeMap);
|
||||
if (args.level)
|
||||
self.world.loadFromLevel(args.level, true);
|
||||
self.goalManager = new GoalManager(self.world);
|
||||
self.goalManager.setGoals(args.goals);
|
||||
self.goalManager.setCode(args.userCodeMap);
|
||||
self.goalManager.worldGenerationWillBegin();
|
||||
self.world.setGoalManager(self.goalManager);
|
||||
}
|
||||
catch (error) {
|
||||
self.onWorldError(error);
|
||||
return;
|
||||
}
|
||||
Math.random = self.world.rand.randf; // so user code is predictable
|
||||
|
||||
self.world.totalFrames = args.frame; //hack to work around error checking
|
||||
self.currentWorldFrame = args.frame;
|
||||
self.world.totalFrames = args.frame; //hack to work around error checking
|
||||
self.currentWorldFrame = args.frame;
|
||||
}
|
||||
};
|
||||
self.runWorldUntilFrame = function runWorldUntilFrame(args) {
|
||||
self.setupWorldToRunUntilFrame(args);
|
||||
|
|
|
@ -58,7 +58,6 @@ module.exports = class God
|
|||
worker = new Worker '/javascripts/workers/worker_debug.js'
|
||||
worker.creationTime = new Date()
|
||||
worker.addEventListener 'message', @onDebugWorkerMessage
|
||||
console.log "GOD: Created debug worker"
|
||||
worker
|
||||
|
||||
onWorkerMessage: (event) =>
|
||||
|
@ -130,21 +129,9 @@ module.exports = class God
|
|||
goals: @goalManager?.getGoals()
|
||||
}}
|
||||
|
||||
createDebugWorldUntilFrame: (frame) ->
|
||||
@debugWorker.postMessage
|
||||
func : 'runWorldUntilFrame'
|
||||
args:
|
||||
worldName: @level.name
|
||||
userCodeMap: @currentUserCodeMap
|
||||
level: @level
|
||||
firstWorld: @firstWorld
|
||||
goals: @goalManager?.getGoals()
|
||||
frame: 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:
|
||||
|
@ -157,12 +144,7 @@ module.exports = class God
|
|||
currentThangID: args.thangID
|
||||
currentSpellID: args.spellID
|
||||
variableChain: args.variableChain
|
||||
|
||||
|
||||
getDebugWorldCurrentFrame: ->
|
||||
@debugWorker.postMessage
|
||||
func: 'getCurrentFrame'
|
||||
|
||||
|
||||
beholdWorld: (angel, serialized, goalStates) ->
|
||||
worldCreation = angel.started
|
||||
angel.free()
|
||||
|
@ -203,7 +185,6 @@ module.exports = class God
|
|||
infos: []
|
||||
warnings: []
|
||||
style: {}
|
||||
|
||||
newUserCodeMap
|
||||
|
||||
getUserCodeMap: ->
|
||||
|
@ -219,6 +200,10 @@ module.exports = class God
|
|||
@dead = true
|
||||
Backbone.Mediator.unsubscribe('tome:cast-spells', @onTomeCast, @)
|
||||
@goalManager?.destroy()
|
||||
@debugWorker?.terminate()
|
||||
@debugWorker?.removeEventListener 'message', @onDebugWorkerMessage
|
||||
@debugWorker ?= null
|
||||
@currentUserCodeMap = null
|
||||
@goalManager = null
|
||||
@fillWorkerPool = null
|
||||
@simulateWorld = null
|
||||
|
|
|
@ -109,7 +109,7 @@ module.exports = class World
|
|||
t1 = now()
|
||||
@t0 ?= t1
|
||||
i = @frames.length
|
||||
while i < frameToLoadUntil
|
||||
while i <= frameToLoadUntil #state is gathered at next frame
|
||||
try
|
||||
@getFrame(i)
|
||||
++i # increment this after we have succeeded in getting the frame, otherwise we'll have to do that frame again
|
||||
|
|
|
@ -27,15 +27,16 @@ module.exports = class DebugView extends View
|
|||
@globals = {Math: Math, _: _} # ... add more as documented
|
||||
for className, serializedClass of serializedClasses
|
||||
@globals[className] = serializedClass
|
||||
@onMouseMove = _.throttle @onMouseMove, 500
|
||||
@onMouseMove = _.throttle @onMouseMove, 25
|
||||
|
||||
changeCurrentThangAndSpell: (thangAndSpellObject) ->
|
||||
@thang = thangAndSpellObject.thang
|
||||
@spell = thangAndSpellObject.spell
|
||||
|
||||
handleDebugValue: (returnObject) ->
|
||||
console.log "Got debug value!"
|
||||
console.log returnObject
|
||||
{key, value} = returnObject
|
||||
@$el.find("code").text "#{key}: #{value}"
|
||||
@$el.show().css(@pos)
|
||||
|
||||
|
||||
afterRender: ->
|
||||
|
@ -69,7 +70,8 @@ module.exports = class DebugView extends View
|
|||
token = prev
|
||||
start = it.getCurrentTokenColumn()
|
||||
chain.unshift token.value
|
||||
if token and (token.value of @variableStates or token.value is "this" or @globals[token.value])
|
||||
#Highlight all tokens, so true overrides all other conditions TODO: Refactor this later
|
||||
if token and (true or token.value of @variableStates or token.value is "this" or @globals[token.value])
|
||||
@variableChain = chain
|
||||
offsetX = e.domEvent.offsetX ? e.clientX - $(e.domEvent.target).offset().left
|
||||
offsetY = e.domEvent.offsetY ? e.clientY - $(e.domEvent.target).offset().top
|
||||
|
@ -94,8 +96,7 @@ module.exports = class DebugView extends View
|
|||
thangID: @thang.id
|
||||
spellID: @spell.name
|
||||
variableChain: @variableChain
|
||||
{key, value} = @deserializeVariableChain @variableChain
|
||||
@$el.find("code").text "#{key}: #{value}"
|
||||
@$el.find("code").text "Finding value..."
|
||||
@$el.show().css(@pos)
|
||||
else
|
||||
@$el.hide()
|
||||
|
|
Loading…
Add table
Reference in a new issue