Spell list updates based on the existence of thangs now.

This commit is contained in:
Scott Erickson 2014-02-15 09:22:13 -08:00
parent 597ace25cc
commit 663a09ed4b
3 changed files with 12 additions and 4 deletions

View file

@ -31,7 +31,7 @@ module.exports = class SpellListEntryView extends View
context = super context
context.spell = @spell
context.parameters = (@spell.parameters or []).join ', '
context.thangNames = (thangID for thangID of @spell.thangs).join(', ') # + ", Marcus, Robert, Phoebe, Will Smith, Zap Brannigan, You, Gandaaaaalf"
context.thangNames = (thangID for thangID, spellThang of @spell.thangs when spellThang.thang.exists).join(', ') # + ", Marcus, Robert, Phoebe, Will Smith, Zap Brannigan, You, Gandaaaaalf"
context.showTopDivider = @showTopDivider
context
@ -40,12 +40,14 @@ module.exports = class SpellListEntryView extends View
spellThang = _.find @spell.thangs, (spellThang) => spellThang.thang.id is @lastSelectedThang.id
return spellThang if spellThang
for thangID, spellThang of @spell.thangs
continue unless spellThang.thang.exists
return spellThang # Just do the first one else
afterRender: ->
super()
return unless @options.showTopDivider # Don't repeat Thang avatars when not changed from previous entry
return unless spellThang = @getPrimarySpellThang()
return @$el.hide() unless spellThang = @getPrimarySpellThang()
@$el.show()
@avatar?.destroy()
@avatar = new ThangAvatarView thang: spellThang.thang, includeName: false, supermodel: @supermodel
@$el.prepend @avatar.el # Before rendering, so render can use parent for popover
@ -71,7 +73,9 @@ module.exports = class SpellListEntryView extends View
showThangs: ->
clearTimeout @hideThangsTimeout if @hideThangsTimeout
return if @thangsView
@thangsView = new SpellListEntryThangsView thangs: (spellThang.thang for thangID, spellThang of @spell.thangs), thang: @getPrimarySpellThang().thang, spell: @spell, supermodel: @supermodel
spellThang = @getPrimarySpellThang()
return unless spellThang
@thangsView = new SpellListEntryThangsView thangs: (spellThang.thang for thangID, spellThang of @spell.thangs), thang: spellTHang.thang, spell: @spell, supermodel: @supermodel
@thangsView.render()
@$el.append @thangsView.el
@thangsView.$el.mouseenter (e) => @onMouseEnterAvatar()

View file

@ -66,6 +66,9 @@ module.exports = class SpellListView extends View
for entry in newEntries
@$el.append entry.el
entry.render() # Render after appending so that we can access parent container for popover
rerenderEntries: ->
entry.render() for entry in @entries
onNewWorld: (e) ->
@thang = e.world.thangMap[@thang.id] if @thang

View file

@ -134,6 +134,7 @@ module.exports = class TomeView extends View
Backbone.Mediator.publish 'tome:cast-spells', spells: @spells
onToggleSpellList: (e) ->
@spellList.rerenderEntries()
@spellList.$el.toggle()
onSpellViewClick: (e) ->