Refactored the universal wizard loading to happen silently when you import ThangType.

This commit is contained in:
Scott Erickson 2014-03-03 10:42:11 -08:00
parent feaeb1dc98
commit 0d054bec8e
3 changed files with 21 additions and 13 deletions

View file

@ -214,9 +214,11 @@ module.exports = class ThangType extends CocoModel
onFileUploaded: => onFileUploaded: =>
console.log 'Image uploaded' console.log 'Image uploaded'
wizOriginal = "52a00d55cf1818f2be00000b" @loadUniversalWizard: ->
url = "/db/thang_type/#{wizOriginal}/version" return @wizardType if @wizardType
wizardType = new module.exports() wizOriginal = "52a00d55cf1818f2be00000b"
wizardType.url = -> url url = "/db/thang_type/#{wizOriginal}/version"
wizardType.fetch() @wizardType = new module.exports()
module.exports.wizardType = wizardType @wizardType.url = -> url
@wizardType.fetch()
@wizardType

View file

@ -11,6 +11,10 @@ module.exports = class HomeView extends View
events: events:
'mouseover #beginner-campaign': 'onMouseOverButton' 'mouseover #beginner-campaign': 'onMouseOverButton'
'mouseout #beginner-campaign': 'onMouseOutButton' 'mouseout #beginner-campaign': 'onMouseOutButton'
constructor: ->
super(arguments...)
ThangType.loadUniversalWizard()
getRenderData: -> getRenderData: ->
c = super() c = super()

View file

@ -8,14 +8,14 @@ module.exports = class LadderPlayModal extends View
id: "ladder-play-modal" id: "ladder-play-modal"
template: template template: template
closeButton: true closeButton: true
startsLoading = true startsLoading: true
constructor: (options, @level, @session, @team) -> constructor: (options, @level, @session, @team) ->
super(options) super(options)
@nameMap = {} @nameMap = {}
@otherTeam = if team is 'ogres' then 'humans' else 'ogres' @otherTeam = if team is 'ogres' then 'humans' else 'ogres'
@startLoadingChallengersMaybe() @startLoadingChallengersMaybe()
@wizardType = ThangType.wizardType @wizardType = ThangType.loadUniversalWizard()
# PART 1: Load challengers from the db unless some are in the matches # PART 1: Load challengers from the db unless some are in the matches
@ -66,15 +66,17 @@ module.exports = class LadderPlayModal extends View
ctx.challengers = @challengers or {} ctx.challengers = @challengers or {}
for challenger in _.values ctx.challengers for challenger in _.values ctx.challengers
continue unless challenger continue unless challenger and @wizardType.loaded
if (not challenger.opponentImageSource) and challenger.opponentWizard?.colorConfig if (not challenger.opponentImageSource) and challenger.opponentWizard?.colorConfig
challenger.opponentImageSource = @wizardType.getPortraitSource( challenger.opponentImageSource = @wizardType.getPortraitSource(
{colorConfig: challenger.opponentWizard.colorConfig}) {colorConfig: challenger.opponentWizard.colorConfig})
ctx.genericPortrait = @wizardType.getPortraitSource() if @wizardType.loaded
ctx.genericPortrait = @wizardType.getPortraitSource()
myColorConfig = me.get('wizard')?.colorConfig
ctx.myPortrait = if myColorConfig then @wizardType.getPortraitSource({colorConfig: myColorConfig}) else ctx.genericPortrait
ctx.myName = me.get('name') || 'Newcomer' ctx.myName = me.get('name') || 'Newcomer'
myColorConfig = me.get('wizard')?.colorConfig
ctx.myPortrait = if myColorConfig then @wizardType.getPortraitSource({colorConfig: myColorConfig}) else ctx.genericPortrait
ctx ctx
# Choosing challengers # Choosing challengers