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
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

View file

@ -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()

View file

@ -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

View file

@ -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