Fixes for equipping items and adding them to the World.

This commit is contained in:
Nick Winter 2014-08-11 11:04:38 -07:00
parent cf7e2042c9
commit 31d7e641e6
4 changed files with 38 additions and 55 deletions

View file

@ -182,7 +182,7 @@ module.exports = class SpriteBoss extends CocoClass
# Add anything new, remove anything old, update everything current # Add anything new, remove anything old, update everything current
updateCache = false updateCache = false
itemsJustEquipped = [] 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 if thang.equip and not thang.equipped
thang.equip() # Pretty hacky, since initialize may not be called thang.equip() # Pretty hacky, since initialize may not be called
itemsJustEquipped.push thang itemsJustEquipped.push thang

View file

@ -12,6 +12,7 @@ Component = require 'lib/world/component'
System = require 'lib/world/system' System = require 'lib/world/system'
PROGRESS_UPDATE_INTERVAL = 200 PROGRESS_UPDATE_INTERVAL = 200
DESERIALIZATION_INTERVAL = 20 DESERIALIZATION_INTERVAL = 20
ITEM_ORIGINAL = '53e12043b82921000051cdf9'
module.exports = class World module.exports = class World
@className: 'World' @className: 'World'
@ -143,7 +144,8 @@ module.exports = class World
@aborted = true @aborted = true
loadFromLevel: (level, willSimulate=true) -> loadFromLevel: (level, willSimulate=true) ->
@level = level @levelComponents = level.levelComponents
@thangTypes = level.thangTypes
@loadSystemsFromLevel level @loadSystemsFromLevel level
@loadThangsFromLevel level, willSimulate @loadThangsFromLevel level, willSimulate
@loadScriptsFromLevel level @loadScriptsFromLevel level
@ -170,33 +172,37 @@ module.exports = class World
@thangMap = {} @thangMap = {}
# Load new Thangs # Load new Thangs
toAdd = [] toAdd = (@loadThangFromLevel thangConfig, level.levelComponents, level.thangTypes for thangConfig in level.thangs)
for d in level.thangs @extraneousThangs = consolidateThangs toAdd if willSimulate # Combine walls, for example; serialize the leftovers later
continue if d.thangType is 'Interface' # ignore old Interface Thangs until we've migrated away @addThang thang for thang in toAdd
null
loadThangFromLevel: (thangConfig, levelComponents, thangTypes, equipBy=null) ->
components = [] components = []
for component in d.components for component in thangConfig.components
componentModel = _.find level.levelComponents, (c) -> c.original is component.original and c.version.major is (component.majorVersion ? 0) componentModel = _.find levelComponents, (c) ->
#console.log 'found model', componentModel, 'from', component, 'for', d.id, 'from existing components', level.levelComponents c.original is component.original and c.version.major is (component.majorVersion ? 0)
componentClass = @loadClassFromCode componentModel.js, componentModel.name, 'component' componentClass = @loadClassFromCode componentModel.js, componentModel.name, 'component'
components.push [componentClass, component.config] components.push [componentClass, component.config]
#console.log '---', d.id, "using db component class ---\n", componentClass, "\n--- from code ---\n", componentModel.js, '\n---' if equipBy and component.original is ITEM_ORIGINAL
#console.log '(found', componentModel, 'for id', component.original, 'from', level.levelComponents, ')' component.config.ownerID = equipBy
thangType = d.thangType thangTypeOriginal = thangConfig.thangType
thangTypeModel = _.find level.thangTypes, (t) -> t.original is thangType thangTypeModel = _.find thangTypes, (t) -> t.original is thangTypeOriginal
thangType = thangTypeModel.name if thangTypeModel return console.error thangConfig.id ? equipBy, 'could not find ThangType for', thangTypeOriginal unless thangTypeModel
thang = new Thang @, thangType, d.id thangTypeName = thangTypeModel.name
thang = new Thang @, thangTypeName, thangConfig.id
try try
thang.addComponents components... thang.addComponents components...
catch e catch e
console.error 'couldn\'t load components for', d.thangType, d.id, 'because', e, e.stack, e.stackTrace console.error 'couldn\'t load components for', thangConfig.thangType, thangConfig.id, 'because', e, e.stack
toAdd.push thang thang
@extraneousThangs = consolidateThangs toAdd if willSimulate # combine walls, for example; serialize the leftovers later
for thang in toAdd addThang: (thang) ->
@thangs.unshift thang # interactions happen in reverse order of specification/drawing @thangs.unshift thang # Interactions happen in reverse order of specification/drawing
@setThang thang @setThang thang
@updateThangState thang @updateThangState thang
thang.updateRegistration() thang.updateRegistration()
null thang
loadScriptsFromLevel: (level) -> loadScriptsFromLevel: (level) ->
@scriptNotes = [] @scriptNotes = []
@ -218,15 +224,6 @@ module.exports = class World
c.className = name c.className = name
c 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) -> updateThangState: (thang) ->
@frames[@frames.length-1].thangStateMap[thang.id] = thang.getState() @frames[@frames.length-1].thangStateMap[thang.id] = thang.getState()

View file

@ -27,8 +27,8 @@ block content
li.list-group-item(id="#{component.get('name')}#{doc.name}") li.list-group-item(id="#{component.get('name')}#{doc.name}")
| #{doc.name} | #{doc.name}
ul.specialList ul.specialList
if doc.description[language] if doc.description[codeLanguage]
li!=marked(doc.description[language]) li!=marked(doc.description[codeLanguage])
else else
li!=marked(doc.description) li!=marked(doc.description)
li.panel-heading li.panel-heading

View file

@ -18,23 +18,9 @@ module.exports = class ComponentDocumentationView extends CocoView
@componentDocs = new ComponentDocsCollection() @componentDocs = new ComponentDocsCollection()
@supermodel.loadCollection @componentDocs, 'components' @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: -> getRenderData: ->
c = super() c = super()
c.components = @componentDocs.models c.components = @componentDocs.models
c.marked = marked c.marked = marked
if (me.get('aceConfig')?.language?) is false c.codeLanguage = me.get('aceConfig')?.language ? 'javascript'
c.language = 'javascript'
else
c.language = me.get('aceConfig').language
c c