Merge remote-tracking branch 'origin/master'

This commit is contained in:
Scott Erickson 2014-04-22 16:42:50 -07:00
commit 9c8841e838
25 changed files with 1277 additions and 95 deletions

View file

@ -0,0 +1,99 @@
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,
"spellKey": spellKey
};
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);
};
var transpile = function(spellKey, source)
{
var currentAether = aethers[spellKey];
currentAether.transpile(source);
var functionName = "transpile";
var returnObject = {
"problems": currentAether.problems,
"function": functionName,
"spellKey": spellKey
};
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 if (data.function == "transpile")
{
self.postMessage(transpile(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

@ -1,11 +1,11 @@
module.exports = nativeDescription: "Nederlands (België)", englishDescription: "Dutch (Belgium)", translation:
common:
loading: "Aan het laden..."
loading: "Bezig met laden..."
saving: "Opslaan..."
sending: "Verzenden..."
send: "Verzend"
cancel: "Annuleren"
save: "Opslagen"
save: "Opslaan"
publish: "Publiceren"
create: "Creëer"
delay_1_sec: "1 seconde"
@ -46,7 +46,7 @@ module.exports = nativeDescription: "Nederlands (België)", englishDescription:
employers: "Werkgevers"
versions:
save_version_title: "Nieuwe versie opslagen"
save_version_title: "Nieuwe versie opslaan"
new_major_version: "Nieuwe hoofd versie"
cla_prefix: "Om bewerkingen op te slaan, moet je eerst akkoord gaan met onze"
cla_url: "CLA"
@ -308,7 +308,7 @@ module.exports = nativeDescription: "Nederlands (België)", englishDescription:
editor:
main_title: "CodeCombat Editors"
main_description: "Maak je eigen levels, campagnes, eenheden en leermateriaal. Wij bieden alle programma's aan die u nodig heeft!"
main_description: "Maak je eigen levels, campagnes, eenheden en leermateriaal. Wij bieden alle programma's aan die je nodig hebt!"
article_title: "Artikel Editor"
article_description: "Schrijf artikels die spelers een overzicht geven over programmeer concepten die kunnen gebruikt worden over een variëteit van levels en campagnes."
thang_title: "Thang Editor"

View file

@ -1,11 +1,11 @@
module.exports = nativeDescription: "Nederlands (Nederland)", englishDescription: "Dutch (Netherlands)", translation:
common:
loading: "Aan het laden..."
loading: "Bezig met laden..."
saving: "Opslaan..."
sending: "Verzenden..."
send: "Verzend"
cancel: "Annuleren"
save: "Opslagen"
save: "Opslaan"
publish: "Publiceren"
create: "Creëer"
delay_1_sec: "1 seconde"
@ -46,7 +46,7 @@ module.exports = nativeDescription: "Nederlands (Nederland)", englishDescription
employers: "Werkgevers"
versions:
save_version_title: "Nieuwe versie opslagen"
save_version_title: "Nieuwe versie opslaan"
new_major_version: "Nieuwe hoofd versie"
cla_prefix: "Om bewerkingen op te slaan, moet je eerst akkoord gaan met onze"
cla_url: "CLA"
@ -308,7 +308,7 @@ module.exports = nativeDescription: "Nederlands (Nederland)", englishDescription
editor:
main_title: "CodeCombat Editors"
main_description: "Maak je eigen levels, campagnes, eenheden en leermateriaal. Wij bieden alle programma's aan die u nodig heeft!"
main_description: "Maak je eigen levels, campagnes, eenheden en leermateriaal. Wij bieden alle programma's aan die je nodig hebt!"
article_title: "Artikel Editor"
article_description: "Schrijf artikels die spelers een overzicht geven over programmeer concepten die kunnen gebruikt worden over een variëteit van levels en campagnes."
thang_title: "Thang Editor"

View file

@ -1,11 +1,11 @@
module.exports = nativeDescription: "Nederlands", englishDescription: "Dutch", translation:
common:
loading: "Aan het laden..."
loading: "Bezig met laden..."
saving: "Opslaan..."
sending: "Verzenden..."
send: "Verzend"
cancel: "Annuleren"
save: "Opslagen"
save: "Opslaan"
publish: "Publiceren"
create: "Creëer"
delay_1_sec: "1 seconde"
@ -46,7 +46,7 @@ module.exports = nativeDescription: "Nederlands", englishDescription: "Dutch", t
employers: "Werkgevers"
versions:
save_version_title: "Nieuwe versie opslagen"
save_version_title: "Nieuwe versie opslaan"
new_major_version: "Nieuwe hoofd versie"
cla_prefix: "Om bewerkingen op te slaan, moet je eerst akkoord gaan met onze"
cla_url: "CLA"
@ -308,7 +308,7 @@ module.exports = nativeDescription: "Nederlands", englishDescription: "Dutch", t
editor:
main_title: "CodeCombat Editors"
main_description: "Maak je eigen levels, campagnes, eenheden en leermateriaal. Wij bieden alle programma's aan die u nodig heeft!"
main_description: "Maak je eigen levels, campagnes, eenheden en leermateriaal. Wij bieden alle programma's aan die je nodig hebt!"
article_title: "Artikel Editor"
article_description: "Schrijf artikels die spelers een overzicht geven over programmeer concepten die kunnen gebruikt worden over een variëteit van levels en campagnes."
thang_title: "Thang Editor"

View file

@ -2,5 +2,6 @@ CocoModel = require('./CocoModel')
module.exports = class Article extends CocoModel
@className: "Article"
@schema: require 'schemas/models/article'
urlRoot: "/db/article"
saveBackups: true

View file

@ -11,7 +11,6 @@ class CocoModel extends Backbone.Model
initialize: ->
super()
@constructor.schema ?= require "schemas/models/#{@urlRoot[4..].replace '.', '_'}"
if not @constructor.className
console.error("#{@} needs a className set.")
@markToRevert()
@ -224,7 +223,7 @@ class CocoModel extends Backbone.Model
watch: (doWatch=true) ->
$.ajax("#{@urlRoot}/#{@id}/watch", {type:'PUT', data:{on:doWatch}})
@watching = -> doWatch
watching: ->
return me.id in (@get('watchers') or [])

View file

@ -2,4 +2,5 @@ CocoModel = require('./CocoModel')
module.exports = class File extends CocoModel
@className: "File"
urlRoot: "/db/file"
@schema: require 'schemas/models/file'
urlRoot: "/db/file"

View file

@ -5,6 +5,7 @@ ThangType = require './ThangType'
module.exports = class Level extends CocoModel
@className: "Level"
@schema: require 'schemas/models/level'
urlRoot: "/db/level"
serialize: (supermodel) ->

View file

@ -2,6 +2,7 @@ CocoModel = require('./CocoModel')
module.exports = class LevelComponent extends CocoModel
@className: "LevelComponent"
@schema: require 'schemas/models/level_component'
urlRoot: "/db/level.component"
set: (key, val, options) ->

View file

@ -2,4 +2,5 @@ CocoModel = require('./CocoModel')
module.exports = class LevelFeedback extends CocoModel
@className: "LevelFeedback"
@schema: require 'schemas/models/level_feedback'
urlRoot: "/db/level.feedback"

View file

@ -2,6 +2,7 @@ CocoModel = require('./CocoModel')
module.exports = class LevelSession extends CocoModel
@className: "LevelSession"
@schema: require 'schemas/models/level_session'
urlRoot: "/db/level.session"
initialize: ->
@ -10,7 +11,7 @@ module.exports = class LevelSession extends CocoModel
state = @get('state') or {}
state.scripts ?= {}
@set('state', state)
updatePermissions: ->
permissions = @get 'permissions'
permissions = (p for p in permissions when p.target isnt 'public')

View file

@ -3,6 +3,7 @@ SystemNameLoader = require('lib/SystemNameLoader')
module.exports = class LevelSystem extends CocoModel
@className: "LevelSystem"
@schema: require 'schemas/models/level_system'
urlRoot: "/db/level.system"
set: (key, val, options) ->

View file

@ -2,10 +2,11 @@ CocoModel = require('./CocoModel')
module.exports = class PatchModel extends CocoModel
@className: "Patch"
urlRoot: "/db/patch"
@schema: require 'schemas/models/patch'
urlRoot: "/db/patch"
setStatus: (status) ->
PatchModel.setStatus @id, status
@setStatus: (id, status) ->
$.ajax("/db/patch/#{id}/status", {type:"PUT", data: {status:status}})
$.ajax("/db/patch/#{id}/status", {type:"PUT", data: {status:status}})

View file

@ -5,6 +5,7 @@ buildQueue = []
module.exports = class ThangType extends CocoModel
@className: "ThangType"
@schema: require 'schemas/models/thang_type'
urlRoot: "/db/thang.type"
building: {}

View file

@ -4,6 +4,7 @@ CocoModel = require('./CocoModel')
module.exports = class User extends CocoModel
@className: "User"
@schema: require 'schemas/models/user'
urlRoot: "/db/user"
initialize: ->
@ -72,4 +73,4 @@ module.exports = class User extends CocoModel
newSubs[newSubName] = { enabled: oldSubName in oldSubs } for oldSubName, newSubName of @emailMap
@set('emails', newSubs)
isEmailSubscriptionEnabled: (name) -> (@get('emails') or {})[name]?.enabled
isEmailSubscriptionEnabled: (name) -> (@get('emails') or {})[name]?.enabled

View file

@ -1,5 +1,5 @@
c = require './../schemas'
ThangComponentSchema = require './../models/thang_component'
ThangComponentSchema = require './thang_component'
SpecificArticleSchema = c.object()
c.extendNamedProperties SpecificArticleSchema # name first

View file

@ -18,7 +18,7 @@ body.is-playing
position: relative
canvas#surface
background-color: #ddd
background-color: #333
width: 100%
display: block
z-index: 1

View file

@ -157,17 +157,18 @@ module.exports = class ThangComponentEditView extends CocoView
@reportChanges()
onAddComponentEnterPressed: (node) =>
extantSystems =
(@supermodel.getModelByOriginalAndMajorVersion LevelSystem, sn.original, sn.majorVersion).attributes.name.toLowerCase() for idx, sn of @level.get('systems')
requireSystem = node.data.system.toLowerCase()
if extantSystems
extantSystems =
(@supermodel.getModelByOriginalAndMajorVersion LevelSystem, sn.original, sn.majorVersion).attributes.name.toLowerCase() for idx, sn of @level.get('systems')
requireSystem = node.data.system.toLowerCase()
if requireSystem not in extantSystems
warn_element = 'Component <b>' + node.data.name + '</b> requires system <b>' + requireSystem + '</b> which is currently not specified in this level.'
noty({
text: warn_element,
layout: 'bottomLeft',
type: 'warning'
})
if requireSystem not in extantSystems
warn_element = 'Component <b>' + node.data.name + '</b> requires system <b>' + requireSystem + '</b> which is currently not specified in this level.'
noty({
text: warn_element,
layout: 'bottomLeft',
type: 'warning'
})
currentSelection = @addComponentsTreema?.getLastSelectedTreema()?.data._id

View file

@ -112,7 +112,7 @@ module.exports = class PlaybackView extends View
@$el.find('.toggle-fullscreen').hide()
updatePopupContent: ->
@timePopup.updateContent "<h2>#{@timeToString @newTime}</h2>#{@formatTime(@current, @currentTime)}<br/>#{@formatTime(@total, @totalTime)}"
@timePopup?.updateContent "<h2>#{@timeToString @newTime}</h2>#{@formatTime(@current, @currentTime)}<br/>#{@formatTime(@total, @totalTime)}"
# These functions could go to some helper class

View file

@ -74,16 +74,20 @@ module.exports = class CastButtonView extends View
updateCastButton: ->
return if _.some @spells, (spell) => not spell.loaded
castable = _.some @spells, (spell) => spell.hasChangedSignificantly spell.getSource()
@castButtonGroup.toggleClass('castable', castable).toggleClass('casting', @casting)
if @casting
s = $.i18n.t("play_level.tome_cast_button_casting", defaultValue: "Casting")
else if castable
s = $.i18n.t("play_level.tome_cast_button_castable", defaultValue: "Cast Spell") + " " + @castShortcut
else
s = $.i18n.t("play_level.tome_cast_button_cast", defaultValue: "Spell Cast")
@castButton.text s
@castButton.prop 'disabled', not castable
async.some _.values(@spells), (spell, callback) =>
spell.hasChangedSignificantly spell.getSource(), null, callback
, (castable) =>
@castButtonGroup.toggleClass('castable', castable).toggleClass('casting', @casting)
if @casting
s = $.i18n.t("play_level.tome_cast_button_casting", defaultValue: "Casting")
else if castable
s = $.i18n.t("play_level.tome_cast_button_castable", defaultValue: "Cast Spell") + " " + @castShortcut
else
s = $.i18n.t("play_level.tome_cast_button_cast", defaultValue: "Spell Cast")
@castButton.text s
@castButton.prop 'disabled', not castable
setAutocastDelay: (delay) ->
#console.log "Set autocast delay to", delay

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()
@ -75,15 +75,27 @@ module.exports = class Spell
hasChanged: (newSource=null, currentSource=null) ->
(newSource ? @originalSource) isnt (currentSource ? @source)
hasChangedSignificantly: (newSource=null, currentSource=null) ->
hasChangedSignificantly: (newSource=null, currentSource=null, cb) ->
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
cb false
workerMessage =
function: "hasChangedSignificantly"
a: (newSource ? @originalSource)
spellKey: @spellKey
b: (currentSource ? @source)
careAboutLineNumbers: true
careAboutLint: true
@worker.addEventListener "message", (e) =>
workerData = JSON.parse e.data
if workerData.function is "hasChangedSignificantly" and workerData.spellKey is @spellKey
@worker.removeEventListener("message",arguments.callee, false)
cb(workerData.hasChanged)
@worker.postMessage JSON.stringify(workerMessage)
createAether: (thang) ->
aceConfig = me.get('aceConfig') ? {}
aetherOptions =
@ -111,13 +123,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
@ -278,9 +279,10 @@ module.exports = class SpellView extends View
]
@onCodeChangeMetaHandler = =>
return if @eventsSuppressed
if not @spellThang or @spell.hasChangedSignificantly @getSource(), @spellThang.aether.raw
callback() for callback in onSignificantChange # Do these first
callback() for callback in onAnyChange # Then these
@spell.hasChangedSignificantly @getSource(), @spellThang.aether.raw, (hasChanged) =>
if not @spellThang or hasChanged
callback() for callback in onSignificantChange # Do these first
callback() for callback in onAnyChange # Then these
@aceDoc.on 'change', @onCodeChangeMetaHandler
setRecompileNeeded: (needed=true) =>
@ -317,20 +319,37 @@ module.exports = class SpellView extends View
# to a new spellThang, we may want to refresh our Aether display.
return unless aether = @spellThang?.aether
source = @getSource()
codeHasChangedSignificantly = force or @spell.hasChangedSignificantly source, aether.raw
needsUpdate = codeHasChangedSignificantly or @spellThang isnt @lastUpdatedAetherSpellThang
return if not needsUpdate and aether is @displayedAether
castAether = @spellThang.castAether
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.
@clearAetherDisplay()
aether.transpile source if codeHasChangedSignificantly and not codeIsAsCast
@displayAether aether
@lastUpdatedAetherSpellThang = @spellThang
@guessWhetherFinished aether if fromCodeChange
@spell.hasChangedSignificantly source, aether.raw, (hasChanged) =>
codeHasChangedSignificantly = force or hasChanged
needsUpdate = codeHasChangedSignificantly or @spellThang isnt @lastUpdatedAetherSpellThang
return if not needsUpdate and aether is @displayedAether
castAether = @spellThang.castAether
codeIsAsCast = castAether and not hasChanged
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()
workerMessage =
function: "transpile"
spellKey: @spell.spellKey
source: source
@worker.addEventListener "message", (e) =>
workerData = JSON.parse e.data
if workerData.function is "transpile" and workerData.spellKey is @spell.spellKey
@worker.removeEventListener("message",arguments.callee, false)
aether.problems = workerData.problems
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
@ -400,10 +419,11 @@ module.exports = class SpellView extends View
return @onInfiniteLoop e if e.problem.id is "runtime_InfiniteLoop"
return unless e.problem.userInfo.methodName is @spell.name
return unless spellThang = _.find @spell.thangs, (spellThang, thangID) -> thangID is e.problem.userInfo.thangID
return if @spell.hasChangedSignificantly @getSource() # don't show this error if we've since edited the code
spellThang.aether.addProblem e.problem
@lastUpdatedAetherSpellThang = null # force a refresh without a re-transpile
@updateAether false, false
@spell.hasChangedSignificantly @getSource(), null, (hasChanged) =>
return if hasChanged
spellThang.aether.addProblem e.problem
@lastUpdatedAetherSpellThang = null # force a refresh without a re-transpile
@updateAether false, false
onInfiniteLoop: (e) ->
return unless @spellThang
@ -578,7 +598,9 @@ module.exports = class SpellView extends View
@aceSession.setMode @editModes[aceConfig.language ? 'javascript']
dismiss: ->
@recompile() if @spell.hasChangedSignificantly @getSource()
@spell.hasChangedSignificantly @getSource(), null, (hasChanged) =>
@recompile() if hasChanged
destroy: ->
$(@ace?.container).find('.ace_gutter').off 'click', '.ace_error, .ace_warning, .ace_info', @onAnnotationClick

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,7 @@ 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
return new Worker("/javascripts/workers/aether_worker.js")
generateTeamSpellMap: (spellObject) ->
teamSpellMap = {}
@ -222,7 +203,7 @@ module.exports = class TomeView extends View
@spellPaletteView.toggleControls {}, spell.view.controlsEnabled # TODO: know when palette should have been disabled but didn't exist
reloadAllCode: ->
spell.view.reloadCode false for spellKey, spell of @spells when spell.team is me.team
spell.view.reloadCode false for spellKey, spell of @spells when spell.team is me.team or (spell.team in ["common", "neutral", null])
Backbone.Mediator.publish 'tome:cast-spells', spells: @spells
updateLanguageForAllSpells: ->
@ -230,5 +211,5 @@ module.exports = class TomeView extends View
destroy: ->
spell.destroy() for spellKey, spell of @spells
@worker?._close()
@worker?.terminate()
super()

View file

@ -59,6 +59,7 @@ exports.config =
# Aether before box2d for some strange Object.defineProperty thing
'bower_components/aether/build/aether.js'
'bower_components/d3/d3.min.js'
'vendor/scripts/async.js'
]
stylesheets:
defaultExtension: 'sass'

1043
vendor/scripts/async.js vendored Normal file

File diff suppressed because it is too large Load diff