mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-27 14:33:59 -04:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
c2e53be58f
5 changed files with 42 additions and 59 deletions
app
lib
templates/docs
views/docs
|
@ -77,11 +77,11 @@ module.exports = class LevelLoader extends CocoClass
|
|||
onSessionLoaded: (session) ->
|
||||
session.url = -> '/db/level.session/' + @id
|
||||
if heroConfig = session.get('heroConfig')
|
||||
url = "/db/thang.type/#{heroConfig.thangType}/version?project=name,components"
|
||||
url = "/db/thang.type/#{heroConfig.thangType}/version?project=name,components,original"
|
||||
@worldNecessities.push @maybeLoadURL(url, ThangType, 'thang')
|
||||
|
||||
for itemThangType in _.values(heroConfig.inventory)
|
||||
url = "/db/thang.type/#{itemThangType}/version?project=name,components"
|
||||
url = "/db/thang.type/#{itemThangType}/version?project=name,components,original"
|
||||
@worldNecessities.push @maybeLoadURL(url, ThangType, 'thang')
|
||||
|
||||
# Supermodel (Level) Loading
|
||||
|
@ -157,7 +157,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
unless itemThangType
|
||||
console.warn "Empty item in inventory for", levelThang
|
||||
continue
|
||||
url = "/db/thang.type/#{itemThangType}/version?project=name,components"
|
||||
url = "/db/thang.type/#{itemThangType}/version?project=name,components,original"
|
||||
@worldNecessities.push @maybeLoadURL(url, ThangType, 'thang')
|
||||
|
||||
onThangNamesLoaded: (thangNames) ->
|
||||
|
@ -181,7 +181,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
inventory = equipsComponent.config?.inventory
|
||||
continue unless inventory
|
||||
for itemThangType in _.values inventory
|
||||
url = "/db/thang.type/#{itemThangType}/version?project=name,components"
|
||||
url = "/db/thang.type/#{itemThangType}/version?project=name,components,original"
|
||||
@worldNecessities.push @maybeLoadURL(url, ThangType, 'thang')
|
||||
|
||||
onWorldNecessityLoaded: (resource) ->
|
||||
|
|
|
@ -182,7 +182,7 @@ module.exports = class SpriteBoss extends CocoClass
|
|||
# Add anything new, remove anything old, update everything current
|
||||
updateCache = false
|
||||
itemsJustEquipped = []
|
||||
for thang in @world.thangs when thang.exists
|
||||
for thang in @world.thangs when thang.exists and thang.pos
|
||||
if thang.equip and not thang.equipped
|
||||
thang.equip() # Pretty hacky, since initialize may not be called
|
||||
itemsJustEquipped.push thang
|
||||
|
|
|
@ -12,6 +12,7 @@ Component = require 'lib/world/component'
|
|||
System = require 'lib/world/system'
|
||||
PROGRESS_UPDATE_INTERVAL = 200
|
||||
DESERIALIZATION_INTERVAL = 20
|
||||
ITEM_ORIGINAL = '53e12043b82921000051cdf9'
|
||||
|
||||
module.exports = class World
|
||||
@className: 'World'
|
||||
|
@ -143,7 +144,8 @@ module.exports = class World
|
|||
@aborted = true
|
||||
|
||||
loadFromLevel: (level, willSimulate=true) ->
|
||||
@level = level
|
||||
@levelComponents = level.levelComponents
|
||||
@thangTypes = level.thangTypes
|
||||
@loadSystemsFromLevel level
|
||||
@loadThangsFromLevel level, willSimulate
|
||||
@loadScriptsFromLevel level
|
||||
|
@ -170,34 +172,38 @@ module.exports = class World
|
|||
@thangMap = {}
|
||||
|
||||
# Load new Thangs
|
||||
toAdd = []
|
||||
for d in level.thangs
|
||||
continue if d.thangType is 'Interface' # ignore old Interface Thangs until we've migrated away
|
||||
components = []
|
||||
for component in d.components
|
||||
componentModel = _.find level.levelComponents, (c) -> c.original is component.original and c.version.major is (component.majorVersion ? 0)
|
||||
#console.log 'found model', componentModel, 'from', component, 'for', d.id, 'from existing components', level.levelComponents
|
||||
componentClass = @loadClassFromCode componentModel.js, componentModel.name, 'component'
|
||||
components.push [componentClass, component.config]
|
||||
#console.log '---', d.id, "using db component class ---\n", componentClass, "\n--- from code ---\n", componentModel.js, '\n---'
|
||||
#console.log '(found', componentModel, 'for id', component.original, 'from', level.levelComponents, ')'
|
||||
thangType = d.thangType
|
||||
thangTypeModel = _.find level.thangTypes, (t) -> t.original is thangType
|
||||
thangType = thangTypeModel.name if thangTypeModel
|
||||
thang = new Thang @, thangType, d.id
|
||||
try
|
||||
thang.addComponents components...
|
||||
catch e
|
||||
console.error 'couldn\'t load components for', d.thangType, d.id, 'because', e, e.stack, e.stackTrace
|
||||
toAdd.push thang
|
||||
@extraneousThangs = consolidateThangs toAdd if willSimulate # combine walls, for example; serialize the leftovers later
|
||||
for thang in toAdd
|
||||
@thangs.unshift thang # interactions happen in reverse order of specification/drawing
|
||||
@setThang thang
|
||||
@updateThangState thang
|
||||
thang.updateRegistration()
|
||||
toAdd = (@loadThangFromLevel thangConfig, level.levelComponents, level.thangTypes for thangConfig in level.thangs)
|
||||
@extraneousThangs = consolidateThangs toAdd if willSimulate # Combine walls, for example; serialize the leftovers later
|
||||
@addThang thang for thang in toAdd
|
||||
null
|
||||
|
||||
loadThangFromLevel: (thangConfig, levelComponents, thangTypes, equipBy=null) ->
|
||||
components = []
|
||||
for component in thangConfig.components
|
||||
componentModel = _.find levelComponents, (c) ->
|
||||
c.original is component.original and c.version.major is (component.majorVersion ? 0)
|
||||
componentClass = @loadClassFromCode componentModel.js, componentModel.name, 'component'
|
||||
components.push [componentClass, component.config]
|
||||
if equipBy and component.original is ITEM_ORIGINAL
|
||||
component.config.ownerID = equipBy
|
||||
thangTypeOriginal = thangConfig.thangType
|
||||
thangTypeModel = _.find thangTypes, (t) -> t.original is thangTypeOriginal
|
||||
return console.error thangConfig.id ? equipBy, 'could not find ThangType for', thangTypeOriginal unless thangTypeModel
|
||||
thangTypeName = thangTypeModel.name
|
||||
thang = new Thang @, thangTypeName, thangConfig.id
|
||||
try
|
||||
thang.addComponents components...
|
||||
catch e
|
||||
console.error 'couldn\'t load components for', thangConfig.thangType, thangConfig.id, 'because', e, e.stack
|
||||
thang
|
||||
|
||||
addThang: (thang) ->
|
||||
@thangs.unshift thang # Interactions happen in reverse order of specification/drawing
|
||||
@setThang thang
|
||||
@updateThangState thang
|
||||
thang.updateRegistration()
|
||||
thang
|
||||
|
||||
loadScriptsFromLevel: (level) ->
|
||||
@scriptNotes = []
|
||||
@scripts = []
|
||||
|
@ -218,15 +224,6 @@ module.exports = class World
|
|||
c.className = name
|
||||
c
|
||||
|
||||
add: (spriteName, id, components...) ->
|
||||
thang = new Thang @, spriteName, id
|
||||
@thangs.unshift thang # interactions happen in reverse order of specification/drawing
|
||||
@setThang thang
|
||||
thang.addComponents components...
|
||||
@updateThangState thang
|
||||
thang.updateRegistration()
|
||||
thang
|
||||
|
||||
updateThangState: (thang) ->
|
||||
@frames[@frames.length-1].thangStateMap[thang.id] = thang.getState()
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ block content
|
|||
li.list-group-item(id="#{component.get('name')}#{doc.name}")
|
||||
| #{doc.name}
|
||||
ul.specialList
|
||||
if doc.description[language]
|
||||
li!=marked(doc.description[language])
|
||||
if doc.description[codeLanguage]
|
||||
li!=marked(doc.description[codeLanguage])
|
||||
else
|
||||
li!=marked(doc.description)
|
||||
li.panel-heading
|
||||
|
|
|
@ -18,23 +18,9 @@ module.exports = class ComponentDocumentationView extends CocoView
|
|||
@componentDocs = new ComponentDocsCollection()
|
||||
@supermodel.loadCollection @componentDocs, 'components'
|
||||
|
||||
onLoaded: ->
|
||||
console.log 'we have the components...', (c.get('name') for c in @componentDocs.models)
|
||||
console.log 'we have the attributes...', (c.attributes for c in @componentDocs.models)
|
||||
if (me.get('aceConfig')?.language?) is false
|
||||
console.log 'default language javascript'
|
||||
else
|
||||
console.log 'language is =', me.get('aceConfig').language
|
||||
|
||||
#console.log 'test', @componentDocs.models[99].attributes.propertyDocumentation[1].description['python']
|
||||
super()
|
||||
|
||||
getRenderData: ->
|
||||
c = super()
|
||||
c.components = @componentDocs.models
|
||||
c.marked = marked
|
||||
if (me.get('aceConfig')?.language?) is false
|
||||
c.language = 'javascript'
|
||||
else
|
||||
c.language = me.get('aceConfig').language
|
||||
c
|
||||
c.codeLanguage = me.get('aceConfig')?.language ? 'javascript'
|
||||
c
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue