Made the wizard icons colored based on user settings.

This commit is contained in:
Scott Erickson 2014-03-03 10:21:51 -08:00
parent d3b6836a06
commit feaeb1dc98
4 changed files with 43 additions and 24 deletions

View file

@ -172,7 +172,10 @@ module.exports = class ThangType extends CocoModel
key = spriteOptionsOrKey
key = if _.isString(key) then key else @spriteSheetKey(@fillOptions(key))
spriteSheet = @spriteSheets[key]
spriteSheet ?= @buildSpriteSheet({portraitOnly:true})
if not spriteSheet
options = if _.isPlainObject spriteOptionsOrKey then spriteOptionsOrKey else {}
options.portraitOnly = true
spriteSheet = @buildSpriteSheet(options)
return unless spriteSheet
canvas = $("<canvas width='#{size}' height='#{size}'></canvas>")
stage = new createjs.Stage(canvas[0])

View file

@ -12,8 +12,8 @@ block modal-body-content
a(href="/play/level/#{levelID}?team=#{teamID}")
div.play-option
img(src=portraitSRC).my-icon
img(src=portraitSRC).opponent-icon
img(src=myPortrait).my-icon
img(src=genericPortrait).opponent-icon
div.my-name.name-label
span= myName
div.opponent-name.name-label
@ -25,8 +25,8 @@ block modal-body-content
if challengers.easy
a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{challengers.easy.sessionID}")
div.play-option.easy-option
img(src=portraitSRC).my-icon
img(src=portraitSRC).opponent-icon
img(src=myPortrait).my-icon
img(src=challengers.easy.opponentImageSource||genericPortrait).opponent-icon
div.my-name.name-label
span= myName
div.opponent-name.name-label
@ -38,8 +38,8 @@ block modal-body-content
if challengers.medium
a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{challengers.medium.sessionID}")
div.play-option.medium-option
img(src=portraitSRC).my-icon
img(src=portraitSRC).opponent-icon
img(src=myPortrait).my-icon
img(src=challengers.medium.opponentImageSource||genericPortrait).opponent-icon
div.my-name.name-label
span= myName
div.opponent-name.name-label
@ -51,8 +51,8 @@ block modal-body-content
if challengers.hard
a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{challengers.hard.sessionID}")
div.play-option.hard-option
img(src=portraitSRC).my-icon
img(src=portraitSRC).opponent-icon
img(src=myPortrait).my-icon
img(src=challengers.hard.opponentImageSource||genericPortrait).opponent-icon
div.my-name.name-label
span= myName
div.opponent-name.name-label

View file

@ -24,8 +24,8 @@ module.exports = class LadderPlayModal extends View
if matches?.length then @loadNames() else @loadChallengers()
loadChallengers: ->
@challengers = new ChallengersData(@level, @team, @otherTeam, @session)
@challengers.on 'sync', @loadNames, @
@challengersCollection = new ChallengersData(@level, @team, @otherTeam, @session)
@challengersCollection.on 'sync', @loadNames, @
# PART 2: Loading the names of the other users
@ -35,11 +35,12 @@ module.exports = class LadderPlayModal extends View
success = (@nameMap) =>
for challenger in _.values(@challengers)
challenger.opponentName = @nameMap[challenger.opponentID] or 'Anoner'
challenger.opponentName = @nameMap[challenger.opponentID]?.name or 'Anoner'
challenger.opponentWizard = @nameMap[challenger.opponentID]?.wizard or {}
@checkWizardLoaded()
$.ajax('/db/user/-/names', {
data: {ids: ids}
data: {ids: ids, wizard: true}
type: 'POST'
success: success
})
@ -62,9 +63,18 @@ module.exports = class LadderPlayModal extends View
ctx.teamName = _.string.titleize @team
ctx.teamID = @team
ctx.otherTeamID = @otherTeam
ctx.challengers = if not @startsLoading then @challengers else {}
ctx.portraitSRC = @wizardType.getPortraitSource()
ctx.challengers = @challengers or {}
for challenger in _.values ctx.challengers
continue unless challenger
if (not challenger.opponentImageSource) and challenger.opponentWizard?.colorConfig
challenger.opponentImageSource = @wizardType.getPortraitSource(
{colorConfig: challenger.opponentWizard.colorConfig})
ctx.genericPortrait = @wizardType.getPortraitSource()
ctx.myName = me.get('name') || 'Newcomer'
myColorConfig = me.get('wizard')?.colorConfig
ctx.myPortrait = if myColorConfig then @wizardType.getPortraitSource({colorConfig: myColorConfig}) else ctx.genericPortrait
ctx
# Choosing challengers
@ -72,10 +82,10 @@ module.exports = class LadderPlayModal extends View
getChallengers: ->
# make an object of challengers to everything needed to link to them
challengers = {}
if @challengers
easyInfo = @challengeInfoFromSession(@challengers.easyPlayer.models[0])
mediumInfo = @challengeInfoFromSession(@challengers.mediumPlayer.models[0])
hardInfo = @challengeInfoFromSession(@challengers.hardPlayer.models[0])
if @challengersCollection
easyInfo = @challengeInfoFromSession(@challengersCollection.easyPlayer.models[0])
mediumInfo = @challengeInfoFromSession(@challengersCollection.mediumPlayer.models[0])
hardInfo = @challengeInfoFromSession(@challengersCollection.hardPlayer.models[0])
else
matches = @session.get('matches')
won = (m for m in matches when m.metrics.rank < m.opponents[0].metrics.rank)
@ -127,10 +137,8 @@ class ChallengersData
@hardPlayer = new LeaderboardCollection(@level, {order:-1, scoreOffset: score + 5, limit: 1, team: @otherTeam})
@hardPlayer.fetch()
@hardPlayer.once 'sync', @challengerLoaded, @
console.log 'fetching challengers yes'
challengerLoaded: ->
console.log 'challenger loaded'
if @allLoaded()
@loaded = true
@trigger 'sync'

View file

@ -114,11 +114,19 @@ UserHandler = class UserHandler extends Handler
ids = ids.split(',') if _.isString ids
ids = _.uniq ids
# TODO: Extend and repurpose this handler to return other public info about a user more flexibly,
# say by a query parameter that lists public properties to return.
returnWizard = req.query.wizard or req.body.wizard
query = if returnWizard then {name:1, wizard:1} else {name:1}
makeFunc = (id) ->
(callback) ->
User.findById(id, {name:1}).exec (err, document) ->
User.findById(id, query).exec (err, document) ->
return done(err) if err
callback(null, document?.get('name') or '')
if document and returnWizard
callback(null, {name:document.get('name'), wizard:document.get('wizard') or {}})
else
callback(null, document?.get('name') or '')
funcs = {}
for id in ids