Hover debugger optimization for "this"

This commit is contained in:
Michael Schmatz 2014-05-16 10:19:34 -07:00
parent 5d30cc7eab
commit 60342cc40e

View file

@ -134,7 +134,9 @@ module.exports = class DebugView extends View
update: ->
if @variableChain
if @workerIsSimulating
if @variableChain.length is 2 and @variableChain[0] is "this"
@setTooltipKeyAndValue(@variableChain.join("."),@stringifyValue(@thang[@variableChain[1]],0))
else if @workerIsSimulating
@setTooltipText("World is simulating, please wait...")
else if @currentFrame is @lastFrameRequested and (cacheValue = @retrieveValueFromCache(@thang.id, @spell.name, @variableChain, @currentFrame))
@setTooltipKeyAndValue(@variableChain.join("."),cacheValue)
@ -155,7 +157,40 @@ module.exports = class DebugView extends View
else
@notifyPropertyHovered()
@updateMarker()
stringifyValue: (value, depth) ->
return value if not value or _.isString value
if _.isFunction value
return if depth is 2 then undefined else "<Function>"
return "<this #{value.id}>" if value is @thang and depth
if depth is 2
if value.constructor?.className is "Thang"
value = "<#{value.type or value.spriteName} - #{value.id}, #{if value.pos then value.pos.toString() else 'non-physical'}>"
else
value = value.toString()
return value
isArray = _.isArray value
isObject = _.isObject value
return value.toString() unless isArray or isObject
brackets = if isArray then ["[", "]"] else ["{", "}"]
size = _.size value
return brackets.join "" unless size
values = []
if isArray
for v in value
s = @stringifyValue(v, depth + 1)
values.push "" + s unless s is undefined
else
for key in value.apiProperties ? _.keys value
s = @stringifyValue(value[key], depth + 1)
values.push key + ": " + s unless s is undefined
sep = '\n' + (" " for i in [0 ... depth]).join('')
prefix = value.constructor?.className
prefix ?= "Array" if isArray
prefix ?= "Object" if isObject
prefix = if prefix then prefix + " " else ""
return "#{prefix}#{brackets[0]}#{sep} #{values.join(sep + ' ')}#{sep}#{brackets[1]}"
notifyPropertyHovered: =>
clearTimeout @hoveredPropertyTimeout if @hoveredPropertyTimeout
@hoveredPropertyTimeout = null
@ -163,6 +198,7 @@ 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