mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-28 22:00:25 -04:00
Updates for ThangsList refreshing its Thangs.
This commit is contained in:
parent
cc3465fd6f
commit
2a8d0eb694
2 changed files with 11 additions and 13 deletions
app/views/play/level/tome
|
@ -52,7 +52,7 @@ module.exports = class ThangListView extends View
|
|||
super()
|
||||
@addThangListEntries()
|
||||
|
||||
addThangListEntries: (forThangs) ->
|
||||
addThangListEntries: ->
|
||||
@entries = []
|
||||
for [thangs, section, permission] in [
|
||||
[@readwriteThangs, "#readwrite-thangs", "readwrite"] # Your Minions
|
||||
|
@ -60,7 +60,7 @@ module.exports = class ThangListView extends View
|
|||
[@muggleThangs, "#muggle-thangs", null] # Non-Castable
|
||||
]
|
||||
section = @$el.find(section).toggle thangs.length > 0
|
||||
for thang in thangs when not forThangs or thang in forThangs
|
||||
for thang in thangs
|
||||
spells = _.filter @spells, (s) -> thang.id of s.thangs
|
||||
entry = new ThangListEntryView thang: thang, spells: spells, permission: permission, supermodel: @supermodel
|
||||
section.find('.thang-list').append entry.el # Render after appending so that we can access parent container for popover
|
||||
|
@ -72,11 +72,11 @@ module.exports = class ThangListView extends View
|
|||
return entry.spells[0]
|
||||
null
|
||||
|
||||
adjustThangs: (spells, thangs, toRemove, toAdd) ->
|
||||
for entry in @entries when _.find toRemove, {id: entry.thang.id}
|
||||
adjustThangs: (spells, thangs) ->
|
||||
@spells = @options.spells = spells
|
||||
for entry in @entries
|
||||
entry.$el.remove()
|
||||
entry.destroy()
|
||||
@spells = @options.spells = spells
|
||||
@thangs = @options.thangs = _.filter thangs, 'isSelectable'
|
||||
@thangs = @options.thangs = thangs
|
||||
@sortThangs()
|
||||
@addThangListEntries toAdd
|
||||
@addThangListEntries()
|
||||
|
|
|
@ -67,12 +67,10 @@ module.exports = class TomeView extends View
|
|||
console.warn "Warning: There are no Programmable Thangs in this level, which makes it unplayable."
|
||||
|
||||
onNewWorld: (e) ->
|
||||
oldThangs = @thangList.thangs
|
||||
newThangs = e.world.thangs
|
||||
toRemove = (thang for thang in oldThangs when not e.world.getThangByID thang.id)
|
||||
toAdd = (thang for thang in newThangs when not _.find oldThangs, id: thang.id)
|
||||
@createSpells toAdd, e.world
|
||||
@thangList.adjustThangs @spells, newThangs, toRemove, toAdd
|
||||
thangs = _.filter e.world.thangs, 'isSelectable'
|
||||
programmableThangs = _.filter thangs, 'isProgrammable'
|
||||
@createSpells programmableThangs, e.world
|
||||
@thangList.adjustThangs @spells, thangs
|
||||
@spellList.adjustSpells @spells
|
||||
|
||||
createSpells: (programmableThangs, world) ->
|
||||
|
|
Loading…
Add table
Reference in a new issue