2014-01-19 10:08:28 -05:00
|
|
|
View = require 'views/kinds/CocoView'
|
|
|
|
template = require 'templates/play/level/tome/debug'
|
2014-01-19 12:14:42 -05:00
|
|
|
Range = ace.require("ace/range").Range
|
2014-01-19 10:08:28 -05:00
|
|
|
|
|
|
|
module.exports = class DebugView extends View
|
|
|
|
className: 'tome-debug-view'
|
|
|
|
template: template
|
|
|
|
|
|
|
|
subscriptions: {}
|
|
|
|
|
|
|
|
events: {}
|
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
@ace = options.ace
|
|
|
|
@variableStates = {}
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
@ace.on "mousemove", @onMouseMove
|
|
|
|
|
|
|
|
setVariableStates: (@variableStates) ->
|
|
|
|
@update()
|
|
|
|
|
|
|
|
onMouseMove: (e) =>
|
|
|
|
pos = e.getDocumentPosition()
|
|
|
|
token = e.editor.session.getTokenAt pos.row, pos.column
|
|
|
|
if token?.type is 'identifier' and token.value of @variableStates
|
|
|
|
@variable = token.value
|
|
|
|
@pos = {left: e.domEvent.offsetX + 50, top: e.domEvent.offsetY + 10}
|
2014-01-19 12:14:42 -05:00
|
|
|
@markerRange = new Range pos.row, token.start, pos.row, token.start + token.value.length
|
2014-01-19 10:08:28 -05:00
|
|
|
else
|
|
|
|
@variable = null
|
2014-01-19 12:14:42 -05:00
|
|
|
@markerRange = null
|
2014-01-19 10:08:28 -05:00
|
|
|
@update()
|
|
|
|
|
|
|
|
update: ->
|
|
|
|
if @variable
|
|
|
|
value = @variableStates[@variable]
|
2014-01-19 12:14:42 -05:00
|
|
|
@$el.find("code").text "#{@variable}: #{value}"
|
2014-01-19 10:08:28 -05:00
|
|
|
@$el.show().css(@pos)
|
|
|
|
else
|
|
|
|
@$el.hide()
|
2014-01-19 12:14:42 -05:00
|
|
|
@updateMarker()
|
|
|
|
|
|
|
|
updateMarker: ->
|
|
|
|
if @marker
|
|
|
|
@ace.getSession().removeMarker @marker
|
|
|
|
@marker = null
|
|
|
|
if @markerRange
|
|
|
|
@marker = @ace.getSession().addMarker @markerRange, "ace_bracket", "text"
|
2014-01-19 10:08:28 -05:00
|
|
|
|
|
|
|
destroy: ->
|
|
|
|
super()
|
|
|
|
@ace?.removeEventListener "mousemove", @onMouseMove
|