mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -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
|
@spells = null # Don't hold onto old spells; memory leaks
|
||||||
|
|
||||||
getUserCodeMap: ->
|
getUserCodeMap: ->
|
||||||
console.log "Spells at user codemap step:"
|
console.log "userCodeMap is "
|
||||||
console.log @spells
|
|
||||||
userCodeMap = {}
|
userCodeMap = {}
|
||||||
for spellKey, spell of @spells
|
for spellKey, spell of @spells
|
||||||
for thangID, spellThang of spell.thangs
|
for thangID, spellThang of spell.thangs
|
||||||
(userCodeMap[thangID] ?= {})[spell.name] = spellThang.aether.serialize()
|
(userCodeMap[thangID] ?= {})[spell.name] = spellThang.aether.serialize()
|
||||||
|
console.log userCodeMap
|
||||||
userCodeMap
|
userCodeMap
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
|
|
|
@ -3,7 +3,6 @@ template = require 'templates/home'
|
||||||
WizardSprite = require 'lib/surface/WizardSprite'
|
WizardSprite = require 'lib/surface/WizardSprite'
|
||||||
ThangType = require 'models/ThangType'
|
ThangType = require 'models/ThangType'
|
||||||
LevelLoader = require 'lib/LevelLoader'
|
LevelLoader = require 'lib/LevelLoader'
|
||||||
|
|
||||||
God = require 'lib/God'
|
God = require 'lib/God'
|
||||||
|
|
||||||
module.exports = class HomeView extends View
|
module.exports = class HomeView extends View
|
||||||
|
@ -111,9 +110,8 @@ module.exports = class HomeView extends View
|
||||||
world = levelLoader.world
|
world = levelLoader.world
|
||||||
level = levelLoader.level
|
level = levelLoader.level
|
||||||
levelLoader.destroy()
|
levelLoader.destroy()
|
||||||
programmableThangs = @filterProgrammableComponents level.attributes.thangs
|
god.spells = @filterProgrammableComponents level.attributes.thangs, @generateSpellToSourceMap data.sessions
|
||||||
console.log "Programmable Components:"
|
|
||||||
console.log programmableThangs
|
|
||||||
#generate spell
|
#generate spell
|
||||||
#spells = @createSpells programmableThangs
|
#spells = @createSpells programmableThangs
|
||||||
#console.log spells
|
#console.log spells
|
||||||
|
@ -125,49 +123,53 @@ module.exports = class HomeView extends View
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
filterProgrammableComponents: (thangs) ->
|
filterProgrammableComponents: (thangs, spellToSourceMap) =>
|
||||||
programmableComponents = {}
|
spells = {}
|
||||||
for thang in thangs
|
for thang in thangs
|
||||||
isTemplate = false
|
isTemplate = false
|
||||||
for component in thang.components
|
for component in thang.components
|
||||||
if component.config? and _.has component.config,'programmableMethods'
|
if component.config? and _.has component.config,'programmableMethods'
|
||||||
programmableComponents[thang.id] ?= {}
|
|
||||||
programmableComponents[thang.id].programmableMethods ?= []
|
|
||||||
for methodName, method of component.config.programmableMethods
|
for methodName, method of component.config.programmableMethods
|
||||||
if typeof method is 'string'
|
if typeof method is 'string'
|
||||||
console.log thang.id,"is a template"
|
|
||||||
delete programmableComponents[thang.id]
|
|
||||||
isTemplate = true
|
isTemplate = true
|
||||||
break
|
break
|
||||||
methodObject = {}
|
|
||||||
methodObject[methodName] = method
|
pathComponents = [thang.id,methodName]
|
||||||
programmableComponents[thang.id].programmableMethods.push methodObject
|
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
|
if isTemplate
|
||||||
break
|
break
|
||||||
|
|
||||||
programmableComponents
|
spells
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
#spells must have spellKey: spell
|
||||||
#spell must have spell.thangs as thangID: spellThang and spell.name
|
#spell must have spell.thangs as thangID: spellThang and spell.name
|
||||||
|
|
|
@ -87,7 +87,7 @@ constructTaskObject = (taskMessageBody, callback) ->
|
||||||
sessionInformation =
|
sessionInformation =
|
||||||
"sessionID": session.sessionID
|
"sessionID": session.sessionID
|
||||||
"sessionChangedTime": session.changed
|
"sessionChangedTime": session.changed
|
||||||
"team": session.team? "No team"
|
"team": session.team ? "No team"
|
||||||
"code": session.code
|
"code": session.code
|
||||||
"teamSpells": session.teamSpells ? {}
|
"teamSpells": session.teamSpells ? {}
|
||||||
"levelID": session.levelID
|
"levelID": session.levelID
|
||||||
|
|
Loading…
Reference in a new issue