2014-01-19 10:08:28 -05:00
|
|
|
View = require 'views/kinds/CocoView'
|
2014-01-21 12:03:04 -05:00
|
|
|
template = require 'templates/play/level/tome/spell_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
|
2014-01-21 12:03:04 -05:00
|
|
|
className: 'spell-debug-view'
|
2014-01-19 10:08:28 -05:00
|
|
|
template: template
|
|
|
|
subscriptions: {}
|
|
|
|
events: {}
|
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
@ace = options.ace
|
|
|
|
@variableStates = {}
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
@ace.on "mousemove", @onMouseMove
|
2014-01-21 12:03:04 -05:00
|
|
|
#@ace.on "click", onClick # same ACE API as mousemove
|
2014-01-19 10:08:28 -05:00
|
|
|
|
|
|
|
setVariableStates: (@variableStates) ->
|
|
|
|
@update()
|
|
|
|
|
|
|
|
onMouseMove: (e) =>
|
|
|
|
pos = e.getDocumentPosition()
|
2014-01-21 12:03:04 -05:00
|
|
|
column = pos.column
|
|
|
|
until column < 0
|
|
|
|
if token = e.editor.session.getTokenAt pos.row, column
|
|
|
|
break if token.type is 'identifier'
|
|
|
|
column = token.start - 1
|
|
|
|
else
|
|
|
|
--column
|
2014-01-19 10:08:28 -05:00
|
|
|
if token?.type is 'identifier' and token.value of @variableStates
|
|
|
|
@variable = token.value
|
2014-01-21 12:03:04 -05:00
|
|
|
@pos = {left: e.domEvent.offsetX + 50, top: e.domEvent.offsetY + 50}
|
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
|
2014-01-21 12:03:04 -05:00
|
|
|
@variable = @markerRange = null
|
|
|
|
@update()
|
|
|
|
|
|
|
|
onMouseOut: (e) =>
|
|
|
|
@variable = @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
|