Added background linting

Background hasChangedSignificantly is soon!
This commit is contained in:
Michael Schmatz 2014-04-18 14:59:08 -07:00
parent 8adca4a1da
commit a7867e5e2d
4 changed files with 134 additions and 28 deletions

View file

@ -0,0 +1,81 @@
var window = self;
var Global = self;
importScripts("/javascripts/tome_aether.js");
console.log("imported scripts!");
var aethers = {};
var createAether = function (spellKey, options)
{
aethers[spellKey] = new Aether(options);
return JSON.stringify({
"message": "Created aether for " + spellKey,
"function": "createAether"
});
};
var hasChangedSignificantly = function(spellKey, a,b,careAboutLineNumbers,careAboutLint) {
var hasChanged = aethers[spellKey].hasChangedSignificantly(a,b,careAboutLineNumbers,careAboutLint);
var functionName = "hasChangedSignificantly";
var returnObject = {
"function":functionName,
"hasChanged": hasChanged
};
return JSON.stringify(returnObject);
};
var updateLanguageAether = function(newLanguage)
{
for (var spellKey in aethers)
{
if (aethers.hasOwnProperty(spellKey))
{
aethers[spellKey].setLanguage(newLanguage);
}
}
};
var lint = function(spellKey, source)
{
var currentAether = aethers[spellKey]
var lintMessages = currentAether.lint(source);
var functionName = "lint";
var returnObject = {
"lintMessages": lintMessages,
"function": functionName
};
return JSON.stringify(returnObject);
};
self.addEventListener('message', function(e) {
var data = JSON.parse(e.data);
if (data.function == "createAether")
{
self.postMessage(createAether(data.spellKey, data.options));
}
else if (data.function == "updateLanguageAether")
{
updateLanguageAether(data.newLanguage)
}
else if (data.function == "hasChangedSignificantly")
{
self.postMessage(hasChangedSignificantly(
data.spellKey,
data.a,
data.b,
data.careAboutLineNumbers,
data.careAboutLint
));
}
else if (data.function == "lint")
{
self.postMessage(lint(data.spellKey, data.source));
}
else
{
var message = "Didn't execute any function...";
var returnObject = {"message":message, "function":"none"};
self.postMessage(JSON.stringify(returnObject));
}
}, false);

View file

@ -23,7 +23,7 @@ module.exports = class Spell
@parameters = p.parameters
@permissions = read: p.permissions?.read ? [], readwrite: p.permissions?.readwrite ? [] # teams
@thangs = {}
@view = new SpellView {spell: @, session: @session}
@view = new SpellView {spell: @, session: @session, worker: @worker}
@view.render() # Get it ready and code loaded in advance
@tabView = new SpellListTabEntryView spell: @, supermodel: @supermodel
@tabView.render()
@ -61,7 +61,20 @@ module.exports = class Spell
else
source = @getSource()
[pure, problems] = [null, null]
workerMessage =
function: "lint"
spellKey: @spellKey
source: source
@worker.postMessage JSON.stringify(workerMessage)
@worker.addEventListener "message", (e) ->
workerData = JSON.parse e.data
if workerData.function is "lint"
pure = workerData.lintMessages
for thangID, spellThang of @thangs
unless pure
pure = spellThang.aether.transpile source
problems = spellThang.aether.problems
@ -111,13 +124,23 @@ module.exports = class Spell
aetherOptions.includeFlow = false
#console.log "creating aether with options", aetherOptions
aether = new Aether aetherOptions
workerMessage =
function: "createAether"
spellKey: @spellKey
options: aetherOptions
@worker.postMessage JSON.stringify workerMessage
aether
updateLanguageAether: ->
aceConfig = me.get('aceConfig') ? {}
newLanguage = (aceConfig.language ? 'javascript')
for thangId, spellThang of @thangs
spellThang.aether?.setLanguage (aceConfig.language ? 'javascript')
spellThang.aether?.setLanguage newLanguage
spellThang.castAether = null
workerMessage =
function: "updateLanguageAether"
newLanguage: newLanguage
@worker.postMessage JSON.stringify workerMessage
@transpile()
toString: ->

View file

@ -47,6 +47,7 @@ module.exports = class SpellView extends View
constructor: (options) ->
super options
@worker = options.worker
@session = options.session
@listenTo(@session, 'change:multiplayer', @onMultiplayerChanged)
@spell = options.spell
@ -324,13 +325,29 @@ module.exports = class SpellView extends View
codeIsAsCast = castAether and not @spell.hasChangedSignificantly source, castAether.raw
aether = castAether if codeIsAsCast
return if not needsUpdate and aether is @displayedAether
# Now that that's figured out, perform the update.
# The web worker Aether won't track state, so don't have to worry about updating it
@clearAetherDisplay()
aether.transpile source if codeHasChangedSignificantly and not codeIsAsCast
@displayAether aether
@lastUpdatedAetherSpellThang = @spellThang
@guessWhetherFinished aether if fromCodeChange
workerMessage =
function: "lint"
spellKey: @spell.spellKey
source: source
@worker.addEventListener "message", (e) =>
workerData = JSON.parse e.data
if workerData.function is "lint"
@worker.removeEventListener("message",arguments.callee, false)
aether.problems = workerData.lintMessages
aether.raw = source
@displayAether aether
@lastUpdatedAetherSpellThang = @spellThang
@guessWhetherFinished aether if fromCodeChange
@worker.postMessage JSON.stringify(workerMessage)
#aether.transpile source if codeHasChangedSignificantly and not codeIsAsCast
#@displayAether aether
#@lastUpdatedAetherSpellThang = @spellThang
#@guessWhetherFinished aether if fromCodeChange
clearAetherDisplay: ->
problem.destroy() for problem in @problems

View file

@ -71,7 +71,7 @@ module.exports = class TomeView extends View
@cast()
console.warn "Warning: There are no Programmable Thangs in this level, which makes it unplayable."
delete @options.thangs
onNewWorld: (e) ->
thangs = _.filter e.world.thangs, 'isSelectable'
programmableThangs = _.filter thangs, 'isProgrammable'
@ -88,26 +88,11 @@ module.exports = class TomeView extends View
@cast()
createWorker: ->
return
# In progress
worker = cw
initialize: (scope) ->
self.window = self
self.global = self
console.log 'Tome worker initialized.'
doIt: (data, callback, scope) ->
console.log 'doing', what
try
importScripts '/javascripts/tome_aether.js'
catch err
console.log err.toString()
a = new Aether()
callback 'good'
undefined
onAccepted = (s) -> console.log 'accepted', s
onRejected = (s) -> console.log 'rejected', s
worker.doIt('hmm').then onAccepted, onRejected
worker
worker = new Worker("/javascripts/workers/test_worker.js")
worker.addEventListener 'message', (e) ->
console.log "Aether worker said something!"
, false
return worker
generateTeamSpellMap: (spellObject) ->
teamSpellMap = {}