mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-05-01 08:23:57 -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
|
#ladder-team-view
|
||||||
|
#rank-button
|
||||||
|
margin-top: 15px
|
||||||
|
|
||||||
#competitors-column .well
|
#competitors-column .well
|
||||||
font-size: 16px
|
font-size: 16px
|
||||||
font-weight: bold
|
font-weight: bold
|
||||||
|
|
|
@ -8,11 +8,25 @@ block content
|
||||||
a(href="/play/ladder/#{levelID}")= level.get('name')
|
a(href="/play/ladder/#{levelID}")= level.get('name')
|
||||||
li.active= teamName
|
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#columns.row
|
||||||
div#matches-column.col-md-6
|
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
|
if matches.length
|
||||||
table.table.table-bordered.table-condensed
|
table.table.table-bordered.table-condensed
|
||||||
|
|
|
@ -3,11 +3,14 @@ Level = require 'models/Level'
|
||||||
LevelSession = require 'models/LevelSession'
|
LevelSession = require 'models/LevelSession'
|
||||||
LeaderboardCollection = require 'collections/LeaderboardCollection'
|
LeaderboardCollection = require 'collections/LeaderboardCollection'
|
||||||
|
|
||||||
module.exports = class LadderView extends RootView
|
module.exports = class LadderTeamView extends RootView
|
||||||
id: 'ladder-team-view'
|
id: 'ladder-team-view'
|
||||||
template: require 'templates/play/ladder/team'
|
template: require 'templates/play/ladder/team'
|
||||||
startsLoading: true
|
startsLoading: true
|
||||||
|
|
||||||
|
events:
|
||||||
|
'click #rank-button': 'rankSession'
|
||||||
|
|
||||||
# PART 1: Loading Level/Session
|
# PART 1: Loading Level/Session
|
||||||
|
|
||||||
constructor: (options, @levelID, @team) ->
|
constructor: (options, @levelID, @team) ->
|
||||||
|
@ -68,6 +71,7 @@ module.exports = class LadderView extends RootView
|
||||||
ctx.teamName = _.string.titleize @team
|
ctx.teamName = _.string.titleize @team
|
||||||
ctx.teamID = @team
|
ctx.teamID = @team
|
||||||
ctx.challengers = if not @startsLoading then @getChallengers() else {}
|
ctx.challengers = if not @startsLoading then @getChallengers() else {}
|
||||||
|
ctx.readyToRank = @readyToRank()
|
||||||
|
|
||||||
convertMatch = (match) ->
|
convertMatch = (match) ->
|
||||||
opponent = match.opponent[0]
|
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 [])
|
ctx.matches = (convertMatch(match) for match in @session.get('matches') or [])
|
||||||
console.log 'context is', ctx
|
|
||||||
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: ->
|
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 = {}
|
||||||
|
@ -108,6 +120,7 @@ module.exports = class LadderView extends RootView
|
||||||
|
|
||||||
addChallenger: (info, challengers, title) ->
|
addChallenger: (info, challengers, title) ->
|
||||||
# check for duplicates first
|
# check for duplicates first
|
||||||
|
return unless info
|
||||||
for key, value of challengers
|
for key, value of challengers
|
||||||
return if value.sessionID is info.sessionID
|
return if value.sessionID is info.sessionID
|
||||||
challengers[title] = info
|
challengers[title] = info
|
||||||
|
@ -130,7 +143,26 @@ module.exports = class LadderView extends RootView
|
||||||
opponentName: opponent.userName or 'Anoner'
|
opponentName: opponent.userName or 'Anoner'
|
||||||
opponentID: opponent.userID
|
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
|
class ChallengersData
|
||||||
constructor: (@level, @team, @session) ->
|
constructor: (@level, @team, @session) ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue