Can now equip items added from inventory on the Surface side. Sorted out ThangTypes' Components schema defaults and ordering when serializing Levels.

This commit is contained in:
Nick Winter 2014-08-11 16:15:46 -07:00
parent b3572dfad9
commit 9a5cd22069
2 changed files with 23 additions and 5 deletions
app

View file

@ -183,9 +183,7 @@ module.exports = class SpriteBoss extends CocoClass
updateCache = false
itemsJustEquipped = []
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
itemsJustEquipped = itemsJustEquipped.concat @equipNewItems thang
if sprite = @sprites[thang.id]
sprite.setThang thang # make sure Sprite has latest Thang
else
@ -206,6 +204,21 @@ module.exports = class SpriteBoss extends CocoClass
if @willSelectThang and @sprites[@willSelectThang[0]]
@selectThang @willSelectThang...
equipNewItems: (thang) ->
itemsJustEquipped = []
if thang.equip and not thang.equipped
thang.equip() # Pretty hacky, but needed since initialize may not be called if we're not running Systems.
itemsJustEquipped.push thang
if thang.inventoryIDs
# Even hackier: these items were only created/equipped during simulation, so we reequip here.
for slot, itemID of thang.inventoryIDs
item = @world.getThangByID itemID
unless item.equipped
#console.log thang.id, 'equipping', item, 'in', thang.slot, 'Surface-side'
item.equip()
itemsJustEquipped.push item
return itemsJustEquipped
cache: (update=false) ->
return if @cached and not update
wallSprites = (sprite for sprite in @spriteArray when sprite.thangType?.get('name').search(/(dungeon|indoor).wall/i) isnt -1)

View file

@ -22,7 +22,11 @@ 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'), components: tt.get('components') for tt in supermodel.getModels ThangType)
# Figure out ThangTypes' Components
o.thangTypes = (original: tt.get('original'), name: tt.get('name'), components: $.extend(true, [], tt.get('components')) for tt in supermodel.getModels ThangType)
@sortThangComponents o.thangTypes, o.levelComponents
@fillInDefaultComponentConfiguration o.thangTypes, o.levelComponents
o
denormalize: (supermodel) ->
@ -76,7 +80,8 @@ module.exports = class Level extends CocoModel
visit = (c) ->
return if c in sorted
lc = _.find levelComponents, {original: c.original}
console.error thang.id, 'couldn\'t find lc for', c unless lc
console.error thang.id, 'couldn\'t find lc for', c, 'of', levelComponents unless lc
return unless lc
if lc.name is 'Programmable'
# Programmable always comes last
visit c2 for c2 in _.without thang.components, c