mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Moved ready-to-rank logic to LevelSession where it can be shared across victory and multiplayer modals and My Matches tab.
This commit is contained in:
parent
8d67e28977
commit
0e0ca785d9
7 changed files with 51 additions and 45 deletions
|
@ -246,6 +246,7 @@
|
|||
multiplayer_hint_label: "Hint:"
|
||||
multiplayer_hint: " Click the link to select all, then press ⌘-C or Ctrl-C to copy the link."
|
||||
multiplayer_coming_soon: "More multiplayer features to come!"
|
||||
multiplayer_sign_in_leaderboard: "Sign in or create an account and get your solution on the leaderboard."
|
||||
guide_title: "Guide"
|
||||
tome_minion_spells: "Your Minions' Spells"
|
||||
tome_read_only_spells: "Read-Only Spells"
|
||||
|
@ -710,4 +711,4 @@
|
|||
user_names: "User Names"
|
||||
files: "Files"
|
||||
top_simulators: "Top Simulators"
|
||||
source_document: "Source Document"
|
||||
source_document: "Source Document"
|
||||
|
|
|
@ -24,3 +24,15 @@ module.exports = class LevelSession extends CocoModel
|
|||
code = @get('code')
|
||||
parts = spellKey.split '/'
|
||||
code?[parts[0]]?[parts[1]]
|
||||
|
||||
readyToRank: ->
|
||||
return false unless @get('levelID') # If it hasn't been denormalized, then it's not ready.
|
||||
return false unless c1 = @get('code')
|
||||
return false unless team = @get('team')
|
||||
return true unless c2 = @get('submittedCode')
|
||||
thangSpellArr = (s.split("/") for s in @get('teamSpells')[team])
|
||||
for item in thangSpellArr
|
||||
thang = item[0]
|
||||
spell = item[1]
|
||||
return true if c1[thang][spell] isnt c2[thang][spell]
|
||||
false
|
||||
|
|
|
@ -27,10 +27,11 @@ block modal-body-content
|
|||
|
||||
if ladderGame
|
||||
if me.get('anonymous')
|
||||
p Sign in or create an account and get your solution on the leaderboard!
|
||||
p(data-i18n="play_level.multiplayer_sign_in_leaderboard") Sign in or create an account and get your solution on the leaderboard.
|
||||
else if readyToRank
|
||||
button.btn.btn-success.rank-game-button(data-i18n="play_level.victory_rank_my_game") Rank My Game
|
||||
else
|
||||
a#go-to-leaderboard-button.btn.btn-primary(href="/play/ladder/#{levelSlug}#my-matches") Go to the leaderboard!
|
||||
p You can submit your game to be ranked from the leaderboard page.
|
||||
a.btn.btn-primary(href="/play/ladder/#{levelSlug}#my-matches", data-i18n="play_level.victory_go_ladder") Return to Ladder
|
||||
|
||||
block modal-footer-content
|
||||
a(href='#', data-dismiss="modal", aria-hidden="true", data-i18n="modal.close").btn.btn-primary Close
|
||||
|
|
|
@ -72,7 +72,7 @@ module.exports = class MyMatchesTabView extends CocoView
|
|||
|
||||
for team in @teams
|
||||
team.session = (s for s in @sessions.models when s.get('team') is team.id)[0]
|
||||
team.readyToRank = @readyToRank(team.session)
|
||||
team.readyToRank = team.session?.readyToRank()
|
||||
team.isRanking = team.session?.get('isRanking')
|
||||
team.matches = (convertMatch(match, team.session.get('submitDate')) for match in team.session?.get('matches') or [])
|
||||
team.matches.reverse()
|
||||
|
@ -84,7 +84,7 @@ module.exports = class MyMatchesTabView extends CocoView
|
|||
if scoreHistory?.length > 1
|
||||
team.scoreHistory = scoreHistory
|
||||
scoreHistory = _.last scoreHistory, 100 # Chart URL needs to be under 2048 characters for GET
|
||||
|
||||
|
||||
team.currentScore = Math.round scoreHistory[scoreHistory.length - 1][1] * 100
|
||||
team.chartColor = team.primaryColor.replace '#', ''
|
||||
#times = (s[0] for s in scoreHistory)
|
||||
|
@ -108,36 +108,35 @@ module.exports = class MyMatchesTabView extends CocoView
|
|||
sessionID = button.data('session-id')
|
||||
session = _.find @sessions.models, {id: sessionID}
|
||||
rankingState = 'unavailable'
|
||||
if @readyToRank session
|
||||
if session.readyToRank()
|
||||
rankingState = 'rank'
|
||||
else if session.get 'isRanking'
|
||||
rankingState = 'ranking'
|
||||
@setRankingButtonText button, rankingState
|
||||
|
||||
|
||||
@$el.find('.score-chart-wrapper').each (i, el) =>
|
||||
scoreWrapper = $(el)
|
||||
team = _.find @teams, name: scoreWrapper.data('team-name')
|
||||
@generateScoreLineChart(scoreWrapper.attr('id'), team.scoreHistory, team.name)
|
||||
|
||||
|
||||
generateScoreLineChart: (wrapperID, scoreHistory,teamName) =>
|
||||
margin =
|
||||
margin =
|
||||
top: 20
|
||||
right: 20
|
||||
bottom: 30
|
||||
left: 50
|
||||
|
||||
|
||||
width = 450 - margin.left - margin.right
|
||||
height = 125
|
||||
x = d3.time.scale().range([0,width])
|
||||
y = d3.scale.linear().range([height,0])
|
||||
|
||||
|
||||
xAxis = d3.svg.axis().scale(x).orient("bottom").ticks(4).outerTickSize(0)
|
||||
yAxis = d3.svg.axis().scale(y).orient("left").ticks(4).outerTickSize(0)
|
||||
|
||||
|
||||
line = d3.svg.line().x(((d) -> x(d.date))).y((d) -> y(d.close))
|
||||
selector = "#" + wrapperID
|
||||
|
||||
|
||||
svg = d3.select(selector).append("svg")
|
||||
.attr("width", width + margin.left + margin.right)
|
||||
.attr("height", height + margin.top + margin.bottom)
|
||||
|
@ -150,12 +149,10 @@ module.exports = class MyMatchesTabView extends CocoView
|
|||
date: time
|
||||
close: d[1] * 100
|
||||
}
|
||||
|
||||
|
||||
x.domain(d3.extent(data, (d) -> d.date))
|
||||
y.domain(d3.extent(data, (d) -> d.close))
|
||||
|
||||
|
||||
|
||||
|
||||
svg.append("g")
|
||||
.attr("class", "y axis")
|
||||
.call(yAxis)
|
||||
|
@ -172,21 +169,6 @@ module.exports = class MyMatchesTabView extends CocoView
|
|||
.datum(data)
|
||||
.attr("class",lineClass)
|
||||
.attr("d",line)
|
||||
|
||||
|
||||
|
||||
|
||||
readyToRank: (session) ->
|
||||
return false unless session?.get('levelID') # If it hasn't been denormalized, then it's not ready.
|
||||
return false unless c1 = session.get('code')
|
||||
return false unless team = session.get('team')
|
||||
return true unless c2 = session.get('submittedCode')
|
||||
thangSpellArr = (s.split("/") for s in session.get('teamSpells')[team])
|
||||
for item in thangSpellArr
|
||||
thang = item[0]
|
||||
spell = item[1]
|
||||
return true if c1[thang][spell] isnt c2[thang][spell]
|
||||
return false
|
||||
|
||||
rankSession: (e) ->
|
||||
button = $(e.target).closest('.rank-button')
|
||||
|
@ -202,7 +184,6 @@ module.exports = class MyMatchesTabView extends CocoView
|
|||
@setRankingButtonText(button, 'failed')
|
||||
|
||||
ajaxData = {session: sessionID, levelID: @level.id, originalLevelID: @level.attributes.original, levelMajorVersion: @level.attributes.version.major}
|
||||
console.log "Posting game for ranking from My Matches view."
|
||||
$.ajax '/queue/scoring', {
|
||||
type: 'POST'
|
||||
data: ajaxData
|
||||
|
|
|
@ -56,7 +56,6 @@ module.exports = class ControlBarView extends View
|
|||
c.multiplayerEnabled = @session.get('multiplayer')
|
||||
c.ladderGame = @level.get('type') is 'ladder'
|
||||
c.spectateGame = @spectateGame
|
||||
console.log "level type is", @level.get('type')
|
||||
if @level.get('type') in ['ladder', 'ladder-tutorial']
|
||||
c.homeLink = '/play/ladder/' + @level.get('slug').replace /\-tutorial$/, ''
|
||||
else
|
||||
|
|
|
@ -9,7 +9,7 @@ module.exports = class MultiplayerModal extends View
|
|||
events:
|
||||
'click textarea': 'onClickLink'
|
||||
'change #multiplayer': 'updateLinkSection'
|
||||
|
||||
'click .rank-game-button': 'onRankGame'
|
||||
|
||||
constructor: (options) ->
|
||||
super(options)
|
||||
|
@ -17,20 +17,20 @@ module.exports = class MultiplayerModal extends View
|
|||
@level = options.level
|
||||
@listenTo(@session, 'change:multiplayer', @updateLinkSection)
|
||||
@playableTeams = options.playableTeams
|
||||
@ladderGame = options.ladderGame
|
||||
console.log 'ladder game is', @ladderGame
|
||||
|
||||
getRenderData: ->
|
||||
c = super()
|
||||
c.joinLink = (document.location.href.replace(/\?.*/, '').replace('#', '') +
|
||||
'?session=' +
|
||||
@session.id)
|
||||
c.multiplayer = @session.get('multiplayer')
|
||||
c.multiplayer = @session.get 'multiplayer'
|
||||
c.team = @session.get 'team'
|
||||
c.levelSlug = @level?.get('slug')
|
||||
c.levelSlug = @level?.get 'slug'
|
||||
c.playableTeams = @playableTeams
|
||||
c.ladderGame = @ladderGame
|
||||
# For now, ladderGame will disallow multiplayer, because session code combining doesn't play nice yet.
|
||||
if @level?.get('type') is 'ladder'
|
||||
c.ladderGame = true
|
||||
c.readyToRank = @session?.readyToRank()
|
||||
c
|
||||
|
||||
afterRender: ->
|
||||
|
@ -50,5 +50,20 @@ module.exports = class MultiplayerModal extends View
|
|||
multiplayer = Boolean(@$el.find('#multiplayer').prop('checked'))
|
||||
@session.set('multiplayer', multiplayer)
|
||||
|
||||
onRankGame: (e) ->
|
||||
button = @$el.find('.rank-game-button')
|
||||
button.text($.i18n.t('play_level.victory_ranking_game', defaultValue: 'Submitting...'))
|
||||
button.prop 'disabled', true
|
||||
ajaxData = session: @session.id, levelID: @level.id, originalLevelID: @level.get('original'), levelMajorVersion: @level.get('version').major
|
||||
ladderURL = "/play/ladder/#{@level.get('slug')}#my-matches"
|
||||
goToLadder = -> Backbone.Mediator.publish 'router:navigate', route: ladderURL
|
||||
$.ajax '/queue/scoring',
|
||||
type: 'POST'
|
||||
data: ajaxData
|
||||
success: goToLadder
|
||||
failure: (response) ->
|
||||
console.error "Couldn't submit game for ranking:", response
|
||||
goToLadder()
|
||||
|
||||
destroy: ->
|
||||
super()
|
||||
|
|
|
@ -65,7 +65,6 @@ module.exports = class VictoryModal extends View
|
|||
ajaxData = session: @session.id, levelID: @level.id, originalLevelID: @level.get('original'), levelMajorVersion: @level.get('version').major
|
||||
ladderURL = "/play/ladder/#{@level.get('slug')}#my-matches"
|
||||
goToLadder = -> Backbone.Mediator.publish 'router:navigate', route: ladderURL
|
||||
console.log "Posting game for ranking from victory modal."
|
||||
$.ajax '/queue/scoring',
|
||||
type: 'POST'
|
||||
data: ajaxData
|
||||
|
@ -82,9 +81,7 @@ module.exports = class VictoryModal extends View
|
|||
c.levelName = utils.i18n @level.attributes, 'name'
|
||||
c.level = @level
|
||||
if c.level.get('type') is 'ladder'
|
||||
c1 = @session?.get('code')
|
||||
c2 = @session?.get('submittedCode')
|
||||
c.readyToRank = @session.get('levelID') and c1 and not _.isEqual(c1, c2)
|
||||
c.readyToRank = @session.readyToRank()
|
||||
if me.get 'hourOfCode'
|
||||
# Show the Hour of Code "I'm Done" tracking pixel after they played for 30 minutes
|
||||
elapsed = (new Date() - new Date(me.get('dateCreated')))
|
||||
|
|
Loading…
Reference in a new issue