Trying to get item ThangType nodes and inventory loading working.

This commit is contained in:
Nick Winter 2014-08-10 22:09:13 -07:00
parent d1e26b40c2
commit 706ab7a251
6 changed files with 30 additions and 15 deletions

View file

@ -154,6 +154,9 @@ module.exports = class LevelLoader extends CocoClass
for component in levelThang.components
if component.original is LevelComponent.EquipsID and inventory = component.config?.inventory
for itemThangType in _.values(inventory)
unless itemThangType
console.warn "Empty item in inventory for", levelThang
continue
url = "/db/thang.type/#{itemThangType}/version?project=name,components"
@worldNecessities.push @maybeLoadURL(url, ThangType, 'thang')
@ -183,7 +186,7 @@ module.exports = class LevelLoader extends CocoClass
onWorldNecessityLoaded: (resource) ->
index = @worldNecessities.indexOf(resource)
if (@level.loading or (@level.get('type') is 'hero')) and resource.name is 'thang'
if (@level?.loading or (@level?.get('type') is 'hero')) and resource.name is 'thang'
@loadDefaultComponentsForThangType(resource.model)
@loadEquippedItemsInheritedFromThangType(resource.model)

View file

@ -149,6 +149,7 @@ module.exports = class SpriteBoss extends CocoClass
return false unless m.get('actions') or m.get('raster')
return m.get('name') is thang.spriteName
thangType ?= _.find @options.thangTypes, (m) -> return m.get('name') is thang.spriteName
return console.error "Couldn't find ThangType for", thang unless thangType
options = @createSpriteOptions thang: thang
options.resolutionFactor = if thangType.get('kind') is 'Floor' then 2 else SPRITE_RESOLUTION_FACTOR

View file

@ -143,6 +143,7 @@ module.exports = class World
@aborted = true
loadFromLevel: (level, willSimulate=true) ->
@level = level
@loadSystemsFromLevel level
@loadThangsFromLevel level, willSimulate
@loadScriptsFromLevel level

View file

@ -22,7 +22,7 @@ module.exports = class Level extends CocoModel
o.systems = @sortSystems o.systems, systemModels
@fillInDefaultSystemConfiguration o.systems
o.thangTypes = (original: tt.get('original'), name: tt.get('name') for tt in supermodel.getModels ThangType)
o.thangTypes = (original: tt.get('original'), name: tt.get('name'), components: tt.get('components') for tt in supermodel.getModels ThangType)
o
denormalize: (supermodel) ->

View file

@ -59,11 +59,12 @@ module.exports = class ThangComponentConfigView extends CocoView
'seconds': nodes.SecondsNode
'speed': nodes.SpeedNode
'acceleration': nodes.AccelerationNode
'item-thang-type': nodes.ItemThangTypeNode
@editThangTreema = @$el.find('.treema').treema treemaOptions
@editThangTreema.build()
@editThangTreema.open(2)
if _.isEqual(@config, {}) and not @editThangTreema.canAddChild()
if _.isEqual(@editThangTreema.data, {}) and not @editThangTreema.canAddChild()
@$el.find('.panel-body').hide()
onConfigEdited: =>

View file

@ -200,7 +200,7 @@ module.exports.ThangTypeNode = class ThangTypeNode extends TreemaNode.nodeMap.st
constructor: (args...) ->
super args...
@thangType = _.find @settings.supermodel.getModels(ThangType), (m) => m.get('original') is @data if @data
console.log 'ThangTypeNode found ThangType', @thangType, 'for data', @data
#console.log 'ThangTypeNode found ThangType', @thangType, 'for data', @data
buildValueForDisplay: (valEl) ->
@buildValueForDisplaySimply(valEl, @thangType?.get('name') or 'None')
@ -219,3 +219,12 @@ module.exports.ThangTypeNode = class ThangTypeNode extends TreemaNode.nodeMap.st
@data = @thangType.get('original')
else
@data = null
module.exports.ItemThangTypeNode = class ThangTypeNode extends ThangTypeNode
valueClass: 'treema-item-thang-type'
buildValueForEditing: (valEl) ->
super(valEl)
thangTypeNames = (m.get('name') for m in @settings.supermodel.getModels ThangType when m.get('kind') is 'Item')
input = valEl.find('input').autocomplete(source: thangTypeNames, minLength: 0, delay: 0, autoFocus: true)
input.val(@thangType?.get('name') or 'None')
valEl