mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-26 05:53:39 -04:00
Working on the ladder and team views.
This commit is contained in:
parent
452a43cae9
commit
cacf6539c1
3 changed files with 54 additions and 5 deletions
app
|
@ -1,4 +1,7 @@
|
|||
#ladder-team-view
|
||||
#rank-button
|
||||
margin-top: 15px
|
||||
|
||||
#competitors-column .well
|
||||
font-size: 16px
|
||||
font-weight: bold
|
||||
|
|
|
@ -8,11 +8,25 @@ block content
|
|||
a(href="/play/ladder/#{levelID}")= level.get('name')
|
||||
li.active= teamName
|
||||
|
||||
|
||||
p
|
||||
| In this level, you play against everyone who has ever written strategies for the opposing forces.
|
||||
| Choose from the suggested players on the right, playing as many and as long as you like,
|
||||
| and when you're ready to test your grand strategy against the whole ladder, return and click the rank button.
|
||||
|
||||
p
|
||||
| After your first submission, your code will also continuously run against other players as they rank themselves.
|
||||
|
||||
div#columns.row
|
||||
div#matches-column.col-md-6
|
||||
h3 Ranked Games
|
||||
h3.pull-left Ranked Games
|
||||
button.btn.btn-warning.pull-right#rank-button
|
||||
span.unavailable.hidden No New Code to Rank
|
||||
span.rank.hidden Rank My Game!
|
||||
span.ranking.hidden Submitting...
|
||||
span.ranked.hidden Submitted for Ranking
|
||||
span.failed.hidden Failed to Rank
|
||||
|
||||
hr.clearfix(style="clear: both")
|
||||
|
||||
if matches.length
|
||||
table.table.table-bordered.table-condensed
|
||||
|
|
|
@ -3,11 +3,14 @@ Level = require 'models/Level'
|
|||
LevelSession = require 'models/LevelSession'
|
||||
LeaderboardCollection = require 'collections/LeaderboardCollection'
|
||||
|
||||
module.exports = class LadderView extends RootView
|
||||
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) ->
|
||||
|
@ -68,6 +71,7 @@ module.exports = class LadderView extends RootView
|
|||
ctx.teamName = _.string.titleize @team
|
||||
ctx.teamID = @team
|
||||
ctx.challengers = if not @startsLoading then @getChallengers() else {}
|
||||
ctx.readyToRank = @readyToRank()
|
||||
|
||||
convertMatch = (match) ->
|
||||
opponent = match.opponent[0]
|
||||
|
@ -83,9 +87,17 @@ module.exports = class LadderView extends RootView
|
|||
}
|
||||
|
||||
ctx.matches = (convertMatch(match) for match in @session.get('matches') or [])
|
||||
console.log 'context is', ctx
|
||||
ctx
|
||||
|
||||
|
||||
afterRender: ->
|
||||
super()
|
||||
@setRankingButtonText(if @readyToRank() then 'rank' else 'unavailable')
|
||||
|
||||
readyToRank: ->
|
||||
c1 = @session.get('code')
|
||||
c2 = @session.get('submittedCode')
|
||||
c1 and not _.isEqual(c1, c2)
|
||||
|
||||
getChallengers: ->
|
||||
# make an object of challengers to everything needed to link to them
|
||||
challengers = {}
|
||||
|
@ -108,6 +120,7 @@ module.exports = class LadderView extends RootView
|
|||
|
||||
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
|
||||
|
@ -130,7 +143,26 @@ module.exports = class LadderView extends RootView
|
|||
opponentName: opponent.userName or 'Anoner'
|
||||
opponentID: opponent.userID
|
||||
}
|
||||
|
||||
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')
|
||||
rankButton.find(".#{spanClass}").removeClass('hidden')
|
||||
rankButton.toggleClass 'disabled', spanClass isnt 'rank'
|
||||
|
||||
class ChallengersData
|
||||
constructor: (@level, @team, @session) ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue