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 = spriteOptionsOrKey
key = if _.isString(key) then key else @spriteSheetKey(@fillOptions(key)) key = if _.isString(key) then key else @spriteSheetKey(@fillOptions(key))
spriteSheet = @spriteSheets[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 return unless spriteSheet
canvas = $("<canvas width='#{size}' height='#{size}'></canvas>") canvas = $("<canvas width='#{size}' height='#{size}'></canvas>")
stage = new createjs.Stage(canvas[0]) stage = new createjs.Stage(canvas[0])

View file

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

View file

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

View file

@ -114,10 +114,18 @@ UserHandler = class UserHandler extends Handler
ids = ids.split(',') if _.isString ids ids = ids.split(',') if _.isString ids
ids = _.uniq 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) -> makeFunc = (id) ->
(callback) -> (callback) ->
User.findById(id, {name:1}).exec (err, document) -> User.findById(id, query).exec (err, document) ->
return done(err) if err return done(err) if err
if document and returnWizard
callback(null, {name:document.get('name'), wizard:document.get('wizard') or {}})
else
callback(null, document?.get('name') or '') callback(null, document?.get('name') or '')
funcs = {} funcs = {}