mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Background simulation is now showing signs of life!
This commit is contained in:
parent
612a374b3f
commit
58bfddeebf
3 changed files with 37 additions and 35 deletions
|
@ -118,12 +118,12 @@ module.exports = class God
|
|||
@spells = null # Don't hold onto old spells; memory leaks
|
||||
|
||||
getUserCodeMap: ->
|
||||
console.log "Spells at user codemap step:"
|
||||
console.log @spells
|
||||
console.log "userCodeMap is "
|
||||
userCodeMap = {}
|
||||
for spellKey, spell of @spells
|
||||
for thangID, spellThang of spell.thangs
|
||||
(userCodeMap[thangID] ?= {})[spell.name] = spellThang.aether.serialize()
|
||||
console.log userCodeMap
|
||||
userCodeMap
|
||||
|
||||
destroy: ->
|
||||
|
|
|
@ -3,7 +3,6 @@ template = require 'templates/home'
|
|||
WizardSprite = require 'lib/surface/WizardSprite'
|
||||
ThangType = require 'models/ThangType'
|
||||
LevelLoader = require 'lib/LevelLoader'
|
||||
|
||||
God = require 'lib/God'
|
||||
|
||||
module.exports = class HomeView extends View
|
||||
|
@ -111,9 +110,8 @@ module.exports = class HomeView extends View
|
|||
world = levelLoader.world
|
||||
level = levelLoader.level
|
||||
levelLoader.destroy()
|
||||
programmableThangs = @filterProgrammableComponents level.attributes.thangs
|
||||
console.log "Programmable Components:"
|
||||
console.log programmableThangs
|
||||
god.spells = @filterProgrammableComponents level.attributes.thangs, @generateSpellToSourceMap data.sessions
|
||||
|
||||
#generate spell
|
||||
#spells = @createSpells programmableThangs
|
||||
#console.log spells
|
||||
|
@ -125,49 +123,53 @@ module.exports = class HomeView extends View
|
|||
|
||||
|
||||
|
||||
filterProgrammableComponents: (thangs) ->
|
||||
programmableComponents = {}
|
||||
filterProgrammableComponents: (thangs, spellToSourceMap) =>
|
||||
spells = {}
|
||||
for thang in thangs
|
||||
isTemplate = false
|
||||
for component in thang.components
|
||||
if component.config? and _.has component.config,'programmableMethods'
|
||||
programmableComponents[thang.id] ?= {}
|
||||
programmableComponents[thang.id].programmableMethods ?= []
|
||||
for methodName, method of component.config.programmableMethods
|
||||
if typeof method is 'string'
|
||||
console.log thang.id,"is a template"
|
||||
delete programmableComponents[thang.id]
|
||||
isTemplate = true
|
||||
break
|
||||
methodObject = {}
|
||||
methodObject[methodName] = method
|
||||
programmableComponents[thang.id].programmableMethods.push methodObject
|
||||
|
||||
pathComponents = [thang.id,methodName]
|
||||
pathComponents[0] = _.string.slugify pathComponents[0]
|
||||
spellKey = pathComponents.join '/'
|
||||
spells[spellKey] ?= {}
|
||||
spells[spellKey].thangs ?= {}
|
||||
spells[spellKey].name = methodName
|
||||
thangID = _.string.slugify thang.id
|
||||
spells[spellKey].thangs[thang.id] ?= {}
|
||||
spells[spellKey].thangs[thang.id].aether = @createAether methodName, method
|
||||
if spellToSourceMap[thangID]? then source = spellToSourceMap[thangID][methodName] else source = ""
|
||||
spells[spellKey].thangs[thang.id].aether.transpile source
|
||||
if isTemplate
|
||||
break
|
||||
|
||||
programmableComponents
|
||||
|
||||
|
||||
createSpells: (programmableThangs) ->
|
||||
thangSpells = {}
|
||||
spells = {}
|
||||
for thang in programmableThangs
|
||||
continue if thangSpells[thang.id]?
|
||||
thangSpells[thang.id] = []
|
||||
console.log thang
|
||||
for methodName, method of thang.programmableMethods
|
||||
continue if method.cloneOf?
|
||||
spellKey = [thang.id,methodName].join '/'
|
||||
console.log spellKey
|
||||
thangSpells[thang.id].push spellKey
|
||||
|
||||
spells[spellKey] = {spellKey: spellKey, programmableMethod: method, aether: null}
|
||||
thangSpells
|
||||
|
||||
spells
|
||||
|
||||
createAether : (methodName, method) ->
|
||||
aetherOptions =
|
||||
functionName: methodName
|
||||
protectAPI: false
|
||||
includeFlow: false
|
||||
return new Aether aetherOptions
|
||||
|
||||
generateSpellToSourceMap: (sessions) ->
|
||||
spellKeyToSourceMap = {}
|
||||
spellSources = {}
|
||||
for session in sessions
|
||||
teamSpells = session.teamSpells[session.team]
|
||||
_.merge spellSources, _.pick(session.code, teamSpells)
|
||||
|
||||
#merge common ones, this overwrites until the last session
|
||||
commonSpells = session.teamSpells["common"]
|
||||
if commonSpells?
|
||||
_.merge spellSources, _.pick(session.code, commonSpells)
|
||||
|
||||
spellSources
|
||||
|
||||
#spells must have spellKey: spell
|
||||
#spell must have spell.thangs as thangID: spellThang and spell.name
|
||||
|
|
|
@ -87,7 +87,7 @@ constructTaskObject = (taskMessageBody, callback) ->
|
|||
sessionInformation =
|
||||
"sessionID": session.sessionID
|
||||
"sessionChangedTime": session.changed
|
||||
"team": session.team? "No team"
|
||||
"team": session.team ? "No team"
|
||||
"code": session.code
|
||||
"teamSpells": session.teamSpells ? {}
|
||||
"levelID": session.levelID
|
||||
|
|
Loading…
Reference in a new issue