mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-16 00:19:50 -05:00
Fix for opponent teams not working.
This commit is contained in:
parent
f54fcfe6c0
commit
1c82fc5bb0
1 changed files with 25 additions and 24 deletions
|
@ -7,10 +7,10 @@ module.exports = class LadderTeamView extends RootView
|
|||
id: 'ladder-team-view'
|
||||
template: require 'templates/play/ladder/team'
|
||||
startsLoading: true
|
||||
|
||||
|
||||
events:
|
||||
'click #rank-button': 'rankSession'
|
||||
|
||||
|
||||
# PART 1: Loading Level/Session
|
||||
|
||||
constructor: (options, @levelID, @team) ->
|
||||
|
@ -18,7 +18,7 @@ module.exports = class LadderTeamView extends RootView
|
|||
@level = new Level(_id:@levelID)
|
||||
@level.fetch()
|
||||
@level.once 'sync', @onLevelLoaded, @
|
||||
|
||||
|
||||
url = "/db/level/#{@levelID}/session?team=#{@team}"
|
||||
@session = new LevelSession()
|
||||
@session.url = -> url
|
||||
|
@ -27,20 +27,20 @@ module.exports = class LadderTeamView extends RootView
|
|||
|
||||
onLevelLoaded: -> @startLoadingChallengersMaybe()
|
||||
onSessionLoaded: -> @startLoadingChallengersMaybe()
|
||||
|
||||
|
||||
# PART 2: Loading some challengers if we don't have any matches yet
|
||||
|
||||
startLoadingChallengersMaybe: ->
|
||||
return unless @level.loaded and @session.loaded
|
||||
matches = @session.get('matches')
|
||||
if matches?.length then @loadNames() else @loadChallengers()
|
||||
if matches?.length then @loadNames() else @loadChallengers()
|
||||
|
||||
loadChallengers: ->
|
||||
@challengers = new ChallengersData(@level, @team, @session)
|
||||
@challengers.on 'sync', @loadNames, @
|
||||
|
||||
|
||||
# PART 3: Loading the names of the other users
|
||||
|
||||
|
||||
loadNames: ->
|
||||
ids = []
|
||||
ids.push match.opponents[0].userID for match in @session.get('matches') or []
|
||||
|
@ -51,13 +51,13 @@ module.exports = class LadderTeamView extends RootView
|
|||
opponent = match.opponents[0]
|
||||
opponent.userName = @nameMap[opponent.userID]
|
||||
@finishRendering()
|
||||
|
||||
|
||||
$.ajax('/db/user/-/names', {
|
||||
data: {ids: ids}
|
||||
type: 'POST'
|
||||
success: success
|
||||
})
|
||||
|
||||
|
||||
# PART 4: Rendering
|
||||
|
||||
finishRendering: ->
|
||||
|
@ -72,7 +72,7 @@ module.exports = class LadderTeamView extends RootView
|
|||
ctx.teamID = @team
|
||||
ctx.challengers = if not @startsLoading then @getChallengers() else {}
|
||||
ctx.readyToRank = @readyToRank()
|
||||
|
||||
|
||||
convertMatch = (match) ->
|
||||
opponent = match.opponent[0]
|
||||
state = 'win'
|
||||
|
@ -85,14 +85,14 @@ module.exports = class LadderTeamView extends RootView
|
|||
when: moment(match.date).fromNow()
|
||||
sessionID: opponent.sessionID
|
||||
}
|
||||
|
||||
|
||||
ctx.matches = (convertMatch(match) for match in @session.get('matches') or [])
|
||||
ctx
|
||||
|
||||
|
||||
afterRender: ->
|
||||
super()
|
||||
@setRankingButtonText(if @readyToRank() then 'rank' else 'unavailable')
|
||||
|
||||
|
||||
readyToRank: ->
|
||||
c1 = @session.get('code')
|
||||
c2 = @session.get('submittedCode')
|
||||
|
@ -117,14 +117,14 @@ module.exports = class LadderTeamView extends RootView
|
|||
@addChallenger mediumInfo, challengers, 'medium'
|
||||
@addChallenger hardInfo, challengers, 'hard'
|
||||
challengers
|
||||
|
||||
|
||||
addChallenger: (info, challengers, title) ->
|
||||
# check for duplicates first
|
||||
return unless info
|
||||
for key, value of challengers
|
||||
return if value.sessionID is info.sessionID
|
||||
challengers[title] = info
|
||||
|
||||
|
||||
challengeInfoFromSession: (session) ->
|
||||
# given a model from the db, return info needed for a link to the match
|
||||
return unless session
|
||||
|
@ -147,17 +147,17 @@ module.exports = class LadderTeamView extends RootView
|
|||
rankSession: ->
|
||||
return unless @readyToRank()
|
||||
@setRankingButtonText('ranking')
|
||||
|
||||
|
||||
success = => @setRankingButtonText('ranked')
|
||||
failure = => @setRankingButtonText('failed')
|
||||
|
||||
|
||||
$.ajax '/queue/scoring', {
|
||||
type: 'POST'
|
||||
data: { session: @session.id }
|
||||
success: success
|
||||
failure: failure
|
||||
}
|
||||
|
||||
|
||||
setRankingButtonText: (spanClass) ->
|
||||
rankButton = $('#rank-button')
|
||||
rankButton.find('span').addClass('hidden')
|
||||
|
@ -168,13 +168,14 @@ class ChallengersData
|
|||
constructor: (@level, @team, @session) ->
|
||||
_.extend @, Backbone.Events
|
||||
score = @session?.get('totalScore') or 25
|
||||
@easyPlayer = new LeaderboardCollection(@level, {order:1, scoreOffset: score - 5, limit: 1, team: @team})
|
||||
otherTeam = if @team is 'ogres' then 'humans' else 'ogres'
|
||||
@easyPlayer = new LeaderboardCollection(@level, {order:1, scoreOffset: score - 5, limit: 1, team: otherTeam})
|
||||
@easyPlayer.fetch()
|
||||
@easyPlayer.once 'sync', @challengerLoaded, @
|
||||
@mediumPlayer = new LeaderboardCollection(@level, {order:1, scoreOffset: score, limit: 1, team: @team})
|
||||
@mediumPlayer = new LeaderboardCollection(@level, {order:1, scoreOffset: score, limit: 1, team: otherTeam})
|
||||
@mediumPlayer.fetch()
|
||||
@mediumPlayer.once 'sync', @challengerLoaded, @
|
||||
@hardPlayer = new LeaderboardCollection(@level, {order:-1, scoreOffset: score + 5, limit: 1, team: @team})
|
||||
@hardPlayer = new LeaderboardCollection(@level, {order:-1, scoreOffset: score + 5, limit: 1, team: otherTeam})
|
||||
@hardPlayer.fetch()
|
||||
@hardPlayer.once 'sync', @challengerLoaded, @
|
||||
|
||||
|
@ -182,10 +183,10 @@ class ChallengersData
|
|||
if @allLoaded()
|
||||
@loaded = true
|
||||
@trigger 'sync'
|
||||
|
||||
|
||||
playerIDs: ->
|
||||
collections = [@easyPlayer, @mediumPlayer, @hardPlayer]
|
||||
(c.models[0].get('creator') for c in collections when c?.models[0])
|
||||
|
||||
|
||||
allLoaded: ->
|
||||
_.all [@easyPlayer.loaded, @mediumPlayer.loaded, @hardPlayer.loaded]
|
||||
_.all [@easyPlayer.loaded, @mediumPlayer.loaded, @hardPlayer.loaded]
|
||||
|
|
Loading…
Reference in a new issue