mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 15:48:11 -05:00
Removed the old team view cruft.
This commit is contained in:
parent
ff3f3e5a07
commit
65d39e658d
6 changed files with 1 additions and 327 deletions
|
@ -19,7 +19,7 @@ module.exports = class CocoRouter extends Backbone.Router
|
|||
'editor/:model(/:slug_or_id)(/:subview)': 'editorModelView'
|
||||
|
||||
# Experimenting with direct links
|
||||
'play/ladder/:levelID/team/:team': go('play/ladder/team_view')
|
||||
# 'play/ladder/:levelID/team/:team': go('play/ladder/team_view')
|
||||
|
||||
# db and file urls call the server directly
|
||||
'db/*path': 'routeToServer'
|
||||
|
|
|
@ -12,10 +12,6 @@
|
|||
margin-bottom: 10px
|
||||
background-image: none
|
||||
|
||||
.intro-button
|
||||
width: 45%
|
||||
margin: 0 2.5%
|
||||
|
||||
.name-col-cell
|
||||
max-width: 300px
|
||||
text-overflow: ellipsis
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
#ladder-team-view
|
||||
#rank-button
|
||||
margin-top: 15px
|
||||
|
||||
#competitors-column .well
|
||||
font-size: 18px
|
||||
padding: 7px
|
||||
|
||||
#your-score
|
||||
margin-top: 20px
|
||||
text-align: center
|
||||
font-size: 20px
|
|
@ -3,9 +3,6 @@ block content
|
|||
|
||||
div#level-column
|
||||
h1= level.get('name')
|
||||
|
||||
//if !me.get('anonymous')
|
||||
// a(href="/play/level/brawlwood-tutorial").intro-button.btn.btn-primary.btn-lg Play the Tutorial
|
||||
|
||||
if me.get('anonymous')
|
||||
div#must-log-in
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
extends /templates/base
|
||||
block content
|
||||
|
||||
ol.breadcrumb
|
||||
li
|
||||
a(href="/") Home
|
||||
li
|
||||
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 are 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.
|
||||
|
||||
if matches.length
|
||||
p#your-score
|
||||
span Your Current Score:
|
||||
span
|
||||
strong= score
|
||||
|
||||
|
||||
div#columns.row
|
||||
div#matches-column.col-md-6
|
||||
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
|
||||
tr
|
||||
th Result
|
||||
th Opponent
|
||||
th When
|
||||
for match in matches
|
||||
tr
|
||||
td.state-cell
|
||||
if match.state === 'win'
|
||||
span.win Win
|
||||
if match.state === 'loss'
|
||||
span.loss Loss
|
||||
if match.state === 'tie'
|
||||
span.tie Tie
|
||||
td.name-cell= match.opponentName || "Anonymous"
|
||||
td.time-cell= match.when
|
||||
td.battle-cell
|
||||
- var text = match.state === 'win' ? 'Watch your victory' : 'Defeat the ' + otherTeamID
|
||||
a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{match.sessionID}")= text
|
||||
|
||||
else
|
||||
div.alert.alert-warning
|
||||
| No ranked matches played yet!
|
||||
| Play some competitors on the right and then come back to get your game ranked.
|
||||
|
||||
// finish this once matches are available
|
||||
|
||||
div#competitors-column.col-md-6
|
||||
h3 Your Competitors
|
||||
|
||||
.well.text-muted
|
||||
div.row
|
||||
div.col-md-2
|
||||
span.warmup Warmup
|
||||
span :
|
||||
div.col-md-10
|
||||
a(href="/play/level/#{levelID}?team=#{teamID}")
|
||||
span.warmup Play #{teamID} vs Default #{otherTeamID}
|
||||
|
||||
if challengers.easy
|
||||
.well
|
||||
div.row.text-info.bg-info
|
||||
div.col-md-2
|
||||
span.easy Easy
|
||||
span :
|
||||
div.col-md-10
|
||||
a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{challengers.easy.sessionID}")
|
||||
span Play #{teamID} vs
|
||||
strong= challengers.easy.opponentName
|
||||
span #{otherTeamID}
|
||||
|
||||
if challengers.medium
|
||||
.well
|
||||
div.row.text-warning.bg-warning
|
||||
div.col-md-2
|
||||
span.medium Medium
|
||||
span :
|
||||
div.col-md-10
|
||||
a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{challengers.medium.sessionID}")
|
||||
span Play #{teamID} vs
|
||||
strong= challengers.medium.opponentName
|
||||
span #{otherTeamID}
|
||||
|
||||
if challengers.hard
|
||||
.well
|
||||
div.row.text-danger.bg-danger
|
||||
div.col-md-2
|
||||
span.hard Hard
|
||||
span :
|
||||
div.col-md-10
|
||||
a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{challengers.hard.sessionID}")
|
||||
span Play #{teamID} vs
|
||||
strong= challengers.hard.opponentName
|
||||
span #{otherTeamID}
|
|
@ -1,195 +0,0 @@
|
|||
RootView = require 'views/kinds/RootView'
|
||||
Level = require 'models/Level'
|
||||
LevelSession = require 'models/LevelSession'
|
||||
LeaderboardCollection = require 'collections/LeaderboardCollection'
|
||||
|
||||
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) ->
|
||||
super(options)
|
||||
@otherTeam = if team is 'ogres' then 'humans' else 'ogres'
|
||||
@level = new Level(_id:@levelID)
|
||||
@level.fetch()
|
||||
@level.once 'sync', @onLevelLoaded, @
|
||||
|
||||
url = "/db/level/#{@levelID}/session?team=#{@team}"
|
||||
@session = new LevelSession()
|
||||
@session.url = -> url
|
||||
@session.fetch()
|
||||
@session.once 'sync', @onSessionLoaded, @
|
||||
|
||||
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()
|
||||
|
||||
loadChallengers: ->
|
||||
@challengers = new ChallengersData(@level, @team, @otherTeam, @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 []
|
||||
ids = ids.concat(@challengers.playerIDs()) if @challengers
|
||||
|
||||
success = (@nameMap) =>
|
||||
for match in @session.get('matches') or []
|
||||
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: ->
|
||||
@startsLoading = false
|
||||
@render()
|
||||
|
||||
getRenderData: ->
|
||||
ctx = super()
|
||||
ctx.level = @level
|
||||
ctx.levelID = @levelID
|
||||
ctx.teamName = _.string.titleize @team
|
||||
ctx.teamID = @team
|
||||
ctx.otherTeamID = @otherTeam
|
||||
ctx.challengers = if not @startsLoading then @getChallengers() else {}
|
||||
ctx.readyToRank = @readyToRank()
|
||||
|
||||
convertMatch = (match) =>
|
||||
opponent = match.opponents[0]
|
||||
state = 'win'
|
||||
state = 'loss' if match.metrics.rank > opponent.metrics.rank
|
||||
state = 'tie' if match.metrics.rank is opponent.metrics.rank
|
||||
{
|
||||
state: state
|
||||
opponentName: @nameMap[opponent.userID]
|
||||
opponentID: opponent.userID
|
||||
when: moment(match.date).fromNow()
|
||||
sessionID: opponent.sessionID
|
||||
}
|
||||
|
||||
ctx.matches = (convertMatch(match) for match in @session.get('matches') or [])
|
||||
ctx.matches.reverse()
|
||||
ctx.score = (@session.get('totalScore') or 10).toFixed(2)
|
||||
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 = {}
|
||||
if @challengers
|
||||
easyInfo = @challengeInfoFromSession(@challengers.easyPlayer.models[0])
|
||||
mediumInfo = @challengeInfoFromSession(@challengers.mediumPlayer.models[0])
|
||||
hardInfo = @challengeInfoFromSession(@challengers.hardPlayer.models[0])
|
||||
else
|
||||
matches = @session.get('matches')
|
||||
won = (m for m in matches when m.metrics.rank < m.opponents[0].metrics.rank)
|
||||
lost = (m for m in matches when m.metrics.rank > m.opponents[0].metrics.rank)
|
||||
tied = (m for m in matches when m.metrics.rank is m.opponents[0].metrics.rank)
|
||||
easyInfo = @challengeInfoFromMatches(won)
|
||||
mediumInfo = @challengeInfoFromMatches(tied)
|
||||
hardInfo = @challengeInfoFromMatches(lost)
|
||||
@addChallenger easyInfo, challengers, 'easy'
|
||||
@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
|
||||
return {
|
||||
sessionID: session.id
|
||||
opponentName: @nameMap[session.get('creator')] or 'Anoner'
|
||||
opponentID: session.get('creator')
|
||||
}
|
||||
|
||||
challengeInfoFromMatches: (matches) ->
|
||||
return unless matches?.length
|
||||
match = _.sample matches
|
||||
opponent = match.opponents[0]
|
||||
return {
|
||||
sessionID: opponent.sessionID
|
||||
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, @otherTeam, @session) ->
|
||||
_.extend @, Backbone.Events
|
||||
score = @session?.get('totalScore') or 25
|
||||
@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: @otherTeam})
|
||||
@mediumPlayer.fetch()
|
||||
@mediumPlayer.once 'sync', @challengerLoaded, @
|
||||
@hardPlayer = new LeaderboardCollection(@level, {order:-1, scoreOffset: score + 5, limit: 1, team: @otherTeam})
|
||||
@hardPlayer.fetch()
|
||||
@hardPlayer.once 'sync', @challengerLoaded, @
|
||||
|
||||
challengerLoaded: ->
|
||||
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]
|
Loading…
Reference in a new issue