From 663a09ed4b68483b5b1ee8b52b3406fa66d90a6a Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Sat, 15 Feb 2014 09:22:13 -0800 Subject: [PATCH] Spell list updates based on the existence of thangs now. --- .../play/level/tome/spell_list_entry_view.coffee | 12 ++++++++---- app/views/play/level/tome/spell_list_view.coffee | 3 +++ app/views/play/level/tome/tome_view.coffee | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/views/play/level/tome/spell_list_entry_view.coffee b/app/views/play/level/tome/spell_list_entry_view.coffee index a2708c25c..48820d742 100644 --- a/app/views/play/level/tome/spell_list_entry_view.coffee +++ b/app/views/play/level/tome/spell_list_entry_view.coffee @@ -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() diff --git a/app/views/play/level/tome/spell_list_view.coffee b/app/views/play/level/tome/spell_list_view.coffee index b659708e4..137219c96 100644 --- a/app/views/play/level/tome/spell_list_view.coffee +++ b/app/views/play/level/tome/spell_list_view.coffee @@ -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 diff --git a/app/views/play/level/tome/tome_view.coffee b/app/views/play/level/tome/tome_view.coffee index 7154020cc..05cd4d113 100644 --- a/app/views/play/level/tome/tome_view.coffee +++ b/app/views/play/level/tome/tome_view.coffee @@ -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) ->