2014-01-03 13:32:13 -05:00
|
|
|
SpellView = require './spell_view'
|
|
|
|
SpellListTabEntryView = require './spell_list_tab_entry_view'
|
|
|
|
{me} = require 'lib/auth'
|
|
|
|
|
|
|
|
module.exports = class Spell
|
|
|
|
loaded: false
|
|
|
|
view: null
|
|
|
|
entryView: null
|
|
|
|
|
2014-01-28 18:24:08 -05:00
|
|
|
constructor: (options) ->
|
|
|
|
@spellKey = options.spellKey
|
|
|
|
@pathComponents = options.pathComponents
|
|
|
|
@session = options.session
|
|
|
|
@supermodel = options.supermodel
|
|
|
|
@skipFlow = options.skipFlow
|
|
|
|
@skipProtectAPI = options.skipProtectAPI
|
|
|
|
p = options.programmableMethod
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
@name = p.name
|
|
|
|
@source = @session.getSourceFor(@spellKey) ? p.source
|
|
|
|
@originalSource = p.source
|
|
|
|
@parameters = p.parameters
|
|
|
|
@permissions = read: p.permissions?.read ? [], readwrite: p.permissions?.readwrite ? [] # teams
|
|
|
|
@thangs = {}
|
|
|
|
@view = new SpellView {spell: @, session: @session}
|
|
|
|
@view.render() # Get it ready and code loaded in advance
|
2014-01-09 17:04:46 -05:00
|
|
|
@tabView = new SpellListTabEntryView spell: @, supermodel: @supermodel
|
2014-01-03 13:32:13 -05:00
|
|
|
@tabView.render()
|
|
|
|
|
|
|
|
addThang: (thang) ->
|
2014-01-29 13:14:12 -05:00
|
|
|
@thangs[thang.id] ?= {thang: thang, aether: @createAether(thang), castAether: null}
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
canRead: (team) ->
|
|
|
|
(team ? me.team) in @permissions.read or (team ? me.team) in @permissions.readwrite
|
|
|
|
|
|
|
|
canWrite: (team) ->
|
|
|
|
(team ? me.team) in @permissions.readwrite
|
|
|
|
|
|
|
|
getSource: ->
|
|
|
|
@view.getSource()
|
|
|
|
|
|
|
|
transpile: (source) ->
|
|
|
|
if source
|
|
|
|
@source = source
|
|
|
|
else
|
|
|
|
source = @getSource()
|
|
|
|
spellThang.aether.transpile source for thangID, spellThang of @thangs
|
|
|
|
#for thangID, spellThang of @thangs
|
|
|
|
# console.log "aether transpiled", source, "to", spellThang.aether.pure
|
|
|
|
# break
|
|
|
|
|
|
|
|
hasChanged: (newSource=null, currentSource=null) ->
|
|
|
|
(newSource ? @originalSource) isnt (currentSource ? @source)
|
|
|
|
|
|
|
|
hasChangedSignificantly: (newSource=null, currentSource=null) ->
|
|
|
|
for thangID, spellThang of @thangs
|
|
|
|
aether = spellThang.aether
|
|
|
|
break
|
|
|
|
unless aether
|
|
|
|
console.error @toString(), "couldn't find a spellThang with aether of", @thangs
|
|
|
|
return false
|
|
|
|
aether.hasChangedSignificantly (newSource ? @originalSource), (currentSource ? @source), true, true
|
|
|
|
|
|
|
|
createAether: (thang) ->
|
|
|
|
aetherOptions =
|
|
|
|
problems:
|
|
|
|
jshint_W040: {level: "ignore"}
|
|
|
|
aether_MissingThis: {level: (if thang.requiresThis then 'error' else 'warning')}
|
|
|
|
functionName: @name
|
|
|
|
functionParameters: @parameters
|
|
|
|
yieldConditionally: thang.plan?
|
|
|
|
requiresThis: thang.requiresThis
|
2014-01-29 11:38:37 -05:00
|
|
|
# TODO: Gridmancer doesn't currently work with protectAPI, so hack it off
|
2014-01-28 18:24:08 -05:00
|
|
|
protectAPI: not (@skipProtectAPI or window.currentView?.level.get('name').match("Gridmancer"))
|
|
|
|
includeFlow: not @skipFlow
|
2014-01-21 12:03:04 -05:00
|
|
|
#callIndex: 0
|
2014-01-19 12:14:42 -05:00
|
|
|
#timelessVariables: ['i']
|
|
|
|
#statementIndex: 9001
|
2014-01-24 16:46:51 -05:00
|
|
|
if not (me.team in @permissions.readwrite) or window.currentView?.sessionID is "52bfb88099264e565d001349" # temp fix for debugger explosion bug
|
2014-01-21 12:03:04 -05:00
|
|
|
#console.log "Turning off includeFlow for", @spellKey
|
|
|
|
aetherOptions.includeFlow = false
|
2014-01-03 13:32:13 -05:00
|
|
|
aether = new Aether aetherOptions
|
|
|
|
aether
|
|
|
|
|
|
|
|
toString: ->
|
|
|
|
"<Spell: #{@spellKey}>"
|