Fixes for equipping items and adding them to the World.
This commit is contained in:
parent
cf7e2042c9
commit
31d7e641e6
4 changed files with 38 additions and 55 deletions
app
lib
templates/docs
views/docs
|
@ -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
|
||||||
|
|
|
@ -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,34 +172,38 @@ 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
|
||||||
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()
|
|
||||||
null
|
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) ->
|
loadScriptsFromLevel: (level) ->
|
||||||
@scriptNotes = []
|
@scriptNotes = []
|
||||||
@scripts = []
|
@scripts = []
|
||||||
|
@ -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()
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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'
|
c
|
||||||
else
|
|
||||||
c.language = me.get('aceConfig').language
|
|
||||||
c
|
|
||||||
|
|
Reference in a new issue