Transfer teamSpellMap from tome to levelBus

This commit is contained in:
Michael Schmatz 2014-02-10 16:18:39 -08:00
parent 465ea22b1a
commit cc3b93a0f8
3 changed files with 27 additions and 5 deletions

View file

@ -26,6 +26,7 @@ module.exports = class LevelBus extends Bus
constructor: ->
super(arguments...)
@changedSessionProperties = {}
console.log "Level bus constructed!"
@saveSession = _.debounce(@saveSession, 1000, {maxWait: 5000})
init: ->
@ -101,13 +102,12 @@ module.exports = class LevelBus extends Bus
@saveSession()
onSpellCreated: (e) ->
#return unless @onPoint()
teamSpells = @session.get 'teamSpells'
return unless @onPoint()
spellTeam = e.spell.team
teamSpells[spellTeam] ?= []
@teamSpellMap[spellTeam] ?= []
unless e.spell.spellKey in teamSpells[spellTeam]
teamSpells[spellTeam].push e.spell.spellKey
unless e.spell.spellKey in @teamSpellMap[spellTeam]
@teamSpellMap[spellTeam].push e.spell.spellKey
console.log "Assigned spell #{e.spell.spellKey} to team #{spellTeam}"
@ -231,3 +231,7 @@ module.exports = class LevelBus extends Bus
# don't let what the server returns overwrite changes since the save began
tempSession = new LevelSession _id:@session.id
tempSession.save(patch, {patch: true})
setTeamSpellMap: (spellMap) ->
@teamSpellMap = spellMap
console.log @teamSpellMap

View file

@ -62,6 +62,8 @@ module.exports = class TomeView extends View
@spellList = @insertSubView new SpellListView spells: @spells, supermodel: @supermodel
@thangList = @insertSubView new ThangListView spells: @spells, thangs: @options.thangs, supermodel: @supermodel
@castButton = @insertSubView new CastButtonView spells: @spells
@teamSpellMap = @generateTeamSpellMap(@spells)
console.log "Team spell map generated", @teamSpellMap
else
@cast()
console.warn "Warning: There are no Programmable Thangs in this level, which makes it unplayable."
@ -74,6 +76,21 @@ module.exports = class TomeView extends View
@thangList.adjustThangs @spells, thangs
@spellList.adjustSpells @spells
generateTeamSpellMap: (spellObject) ->
teamSpellMap = {}
for spellName, spell of spellObject
teamName = spell.team
teamSpellMap[teamName] ?= []
spellNameElements = spellName.split '/'
thangName = spellNameElements[0]
spellName = spellNameElements[1]
teamSpellMap[teamName].push thangName if thangName not in teamSpellMap[teamName]
return teamSpellMap
createSpells: (programmableThangs, world) ->
pathPrefixComponents = ['play', 'level', @options.levelID, @options.session.id, 'code']
@spells ?= {}

View file

@ -358,6 +358,7 @@ module.exports = class PlayLevelView extends View
register: ->
@bus = LevelBus.get(@levelID, @session.id)
@bus.setSession(@session)
@bus.setTeamSpellMap @tome.teamSpellMap
@bus.connect() if @session.get('multiplayer')
onSessionWillSave: (e) ->