#3138 #3488 refactor LadderPlayModal

This commit is contained in:
duybkict 2016-06-07 18:05:06 +07:00
parent c191f63c15
commit c1f1b4a048
2 changed files with 68 additions and 84 deletions

View file

@ -9,81 +9,81 @@ block modal-body-content
h4.language-selection(data-i18n="ladder.select_your_language") Select your language! h4.language-selection(data-i18n="ladder.select_your_language") Select your language!
.form-group.select-group .form-group.select-group
select#tome-language(name="language") select#tome-language(name="language")
for option in languages for option in view.languages
option(value=option.id selected=(language === option.id))= option.name option(value=option.id selected=(view.language === option.id))= option.name
div#noob-view.secret div#noob-view.secret
a(href="/play/level/#{levelID}-tutorial" + (league ? "?league=" + league.id : "")).btn.btn-success.btn-block.btn-lg a(href="/play/level/#{view.levelID}-tutorial" + (view.options.league ? "?league=" + view.options.league.id : "")).btn.btn-success.btn-block.btn-lg
p p
strong(data-i18n="ladder.tutorial_play") Play Tutorial strong(data-i18n="ladder.tutorial_play") Play Tutorial
span(data-i18n="ladder.tutorial_recommended") Recommended if you've never played before span(data-i18n="ladder.tutorial_recommended") Recommended if you've never played before
span.btn.btn-primary.btn-block.btn-lg#skip-tutorial-button(data-i18n="ladder.tutorial_skip") Skip Tutorial span.btn.btn-primary.btn-block.btn-lg#skip-tutorial-button(data-i18n="ladder.tutorial_skip") Skip Tutorial
div#normal-view div#normal-view
if tutorialLevelExists if view.tutorialLevelExists
p.tutorial-suggestion p.tutorial-suggestion
strong(data-i18n="ladder.tutorial_not_sure") Not sure what's going on? strong(data-i18n="ladder.tutorial_not_sure") Not sure what's going on?
| |
a(href="/play/level/#{levelID}-tutorial" + (league ? "?league=" + league.id : ""), data-i18n="ladder.tutorial_play_first") Play the tutorial first. a(href="/play/level/#{view.levelID}-tutorial" + (view.options.league ? "?league=" + view.options.league.id : ""), data-i18n="ladder.tutorial_play_first") Play the tutorial first.
a(href="/play/level/#{levelID}?team=#{teamID}" + (league ? "&league=" + league.id : "")) a(href="/play/level/#{view.levelID}?team=#{view.team}" + (view.options.league ? "&league=" + view.options.league.id : ""))
div.play-option div.play-option
img(src=myPortrait).my-icon.only-one img(src=view.myPortrait).my-icon.only-one
img(src="/images/pages/play/ladder/"+teamID+"_ladder_tutorial.png", style="border: 1px solid #{teamColor}; background: #{teamBackgroundColor}").my-team-icon.img-circle.only-one img(src="/images/pages/play/ladder/#{view.team}_ladder_tutorial.png", style="border: 1px solid #{view.teamColor}; background: #{view.teamBackgroundColor}").my-team-icon.img-circle.only-one
img(src=genericPortrait).opponent-icon img(src=view.genericPortrait).opponent-icon
img(src="/images/pages/play/ladder/"+otherTeamID+"_ladder_tutorial.png", style="border: 1px solid #{opponentTeamColor}; background: #{opponentTeamBackgroundColor}").opponent-team-icon.img-circle img(src="/images/pages/play/ladder/#{view.otherTeam}_ladder_tutorial.png", style="border: 1px solid #{view.opponentTeamColor}; background: #{view.opponentTeamBackgroundColor}").opponent-team-icon.img-circle
div.my-name.name-label.only-one div.my-name.name-label.only-one
span= myName span= view.myName
div.opponent-name.name-label div.opponent-name.name-label
span(data-i18n="ladder.simple_ai") span(data-i18n="ladder.simple_ai")
//span.code-language(style="background-image: url(/images/common/code_languages/javascript_small.png)") //span.code-language(style="background-image: url(/images/common/code_languages/javascript_small.png)")
div.difficulty div.difficulty
span(data-i18n="ladder.warmup") Warmup span(data-i18n="ladder.warmup") Warmup
if challengers.easy if view.challengers && view.challengers.easy
a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{challengers.easy.sessionID}" + (league ? "&league=" + league.id : "")) a(href="/play/level/#{view.levelID}?team=#{view.team}&opponent=#{view.challengers.easy.sessionID}" + (view.options.league ? "&league=" + view.options.league.id : ""))
div.play-option.easy-option div.play-option.easy-option
img(src=myPortrait).my-icon.only-one img(src=view.myPortrait).my-icon.only-one
img(src="/images/pages/play/ladder/"+teamID+"_ladder_easy.png", style="border: 1px solid #{teamColor}; background: #{teamBackgroundColor}").my-team-icon.img-circle.only-one img(src="/images/pages/play/ladder/#{view.team}_ladder_easy.png", style="border: 1px solid #{view.teamColor}; background: #{view.teamBackgroundColor}").my-team-icon.img-circle.only-one
img(src=challengers.easy.opponentImageSource||genericPortrait).opponent-icon img(src=view.challengers.easy.opponentImageSource||view.genericPortrait).opponent-icon
img(src="/images/pages/play/ladder/"+otherTeamID+"_ladder_easy.png", style="border: 1px solid #{opponentTeamColor}; background: #{opponentTeamBackgroundColor}").opponent-team-icon.img-circle img(src="/images/pages/play/ladder/#{view.otherTeam}_ladder_easy.png", style="border: 1px solid #{view.opponentTeamColor}; background: #{view.opponentTeamBackgroundColor}").opponent-team-icon.img-circle
div.my-name.name-label.only-one div.my-name.name-label.only-one
span= myName span= view.myName
div.opponent-name.name-label div.opponent-name.name-label
span= challengers.easy.opponentName span= view.challengers.easy.opponentName
if challengers.easy.codeLanguage if view.challengers.easy.codeLanguage
span.code-language(style="background-image: url(/images/common/code_languages/" + challengers.easy.codeLanguage + "_small.png)") span.code-language(style="background-image: url(/images/common/code_languages/#{view.challengers.easy.codeLanguage}_small.png)")
div.difficulty div.difficulty
span(data-i18n="general.easy") Easy span(data-i18n="general.easy") Easy
if challengers.medium if view.challengers && view.challengers.medium
a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{challengers.medium.sessionID}" + (league ? "&league=" + league.id : "")) a(href="/play/level/#{view.levelID}?team=#{view.team}&opponent=#{view.challengers.medium.sessionID}" + (view.options.league ? "&league=" + view.options.league.id : ""))
div.play-option.medium-option div.play-option.medium-option
img(src=myPortrait).my-icon.only-one img(src=view.myPortrait).my-icon.only-one
img(src="/images/pages/play/ladder/"+teamID+"_ladder_medium.png", style="border: 1px solid #{teamColor}; background: #{teamBackgroundColor}").my-team-icon.img-circle.only-one img(src="/images/pages/play/ladder/#{view.team}_ladder_medium.png", style="border: 1px solid #{view.teamColor}; background: #{view.teamBackgroundColor}").my-team-icon.img-circle.only-one
img(src=challengers.medium.opponentImageSource||genericPortrait).opponent-icon img(src=view.challengers.medium.opponentImageSource||view.genericPortrait).opponent-icon
img(src="/images/pages/play/ladder/"+otherTeamID+"_ladder_medium.png", style="border: 1px solid #{opponentTeamColor}; background: #{opponentTeamBackgroundColor}").opponent-team-icon.img-circle img(src="/images/pages/play/ladder/#{view.otherTeam}_ladder_medium.png", style="border: 1px solid #{view.opponentTeamColor}; background: #{view.opponentTeamBackgroundColor}").opponent-team-icon.img-circle
div.my-name.name-label.only-one div.my-name.name-label.only-one
span= myName span= view.myName
div.opponent-name.name-label div.opponent-name.name-label
span= challengers.medium.opponentName span= view.challengers.medium.opponentName
if challengers.medium.codeLanguage if view.challengers.medium.codeLanguage
span.code-language(style="background-image: url(/images/common/code_languages/" + challengers.medium.codeLanguage + "_small.png)") span.code-language(style="background-image: url(/images/common/code_languages/#{view.challengers.medium.codeLanguage}_small.png)")
div.difficulty div.difficulty
span(data-i18n="general.medium") Medium span(data-i18n="general.medium") Medium
if challengers.hard if view.challengers && view.challengers.hard
a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{challengers.hard.sessionID}" + (league ? "&league=" + league.id : "")) a(href="/play/level/#{view.levelID}?team=#{view.team}&opponent=#{view.challengers.hard.sessionID}" + (view.options.league ? "&league=" + view.options.league.id : ""))
div.play-option.hard-option div.play-option.hard-option
img(src=myPortrait).my-icon.only-one img(src=view.myPortrait).my-icon.only-one
img(src="/images/pages/play/ladder/"+teamID+"_ladder_hard.png", style="border: 1px solid #{teamColor}; background: #{teamBackgroundColor}").my-team-icon.img-circle.only-one img(src="/images/pages/play/ladder/#{view.team}_ladder_hard.png", style="border: 1px solid #{view.teamColor}; background: #{view.teamBackgroundColor}").my-team-icon.img-circle.only-one
img(src=challengers.hard.opponentImageSource||genericPortrait).opponent-icon img(src=view.challengers.hard.opponentImageSource||view.genericPortrait).opponent-icon
img(src="/images/pages/play/ladder/"+otherTeamID+"_ladder_hard.png", style="border: 1px solid #{opponentTeamColor}; background: #{opponentTeamBackgroundColor}").opponent-team-icon.img-circle img(src="/images/pages/play/ladder/#{view.otherTeam}_ladder_hard.png", style="border: 1px solid #{view.opponentTeamColor}; background: #{view.opponentTeamBackgroundColor}").opponent-team-icon.img-circle
div.my-name.name-label.only-one div.my-name.name-label.only-one
span= myName span= view.myName
div.opponent-name.name-label div.opponent-name.name-label
span= challengers.hard.opponentName span= view.challengers.hard.opponentName
if challengers.hard.codeLanguage if view.challengers.hard.codeLanguage
span.code-language(style="background-image: url(/images/common/code_languages/" + challengers.hard.codeLanguage + "_small.png)") span.code-language(style="background-image: url(/images/common/code_languages/#{view.challengers.hard.codeLanguage}_small.png)")
div.difficulty div.difficulty
span(data-i18n="general.hard") Hard span(data-i18n="general.hard") Hard

View file

@ -24,12 +24,27 @@ module.exports = class LadderPlayModal extends ModalView
behaviors: false behaviors: false
liveCompletion: true liveCompletion: true
constructor: (options, @level, @session, @team) -> initialize: (options, @level, @session, @team) ->
super(options)
@nameMap = {}
@otherTeam = if @team is 'ogres' then 'humans' else 'ogres' @otherTeam = if @team is 'ogres' then 'humans' else 'ogres'
@startLoadingChallengersMaybe() @startLoadingChallengersMaybe()
@wizardType = ThangType.loadUniversalWizard() @wizardType = ThangType.loadUniversalWizard()
@levelID = @level.get('slug') or @level.id
@language = @session?.get('codeLanguage') ? me.get('aceConfig')?.language ? 'python'
@languages = [
{id: 'python', name: 'Python'}
{id: 'javascript', name: 'JavaScript'}
{id: 'coffeescript', name: 'CoffeeScript (Experimental)'}
{id: 'lua', name: 'Lua'}
{id: 'java', name: 'Java'}
]
@myName = me.get('name') || 'Newcomer'
teams = []
teams[t.id] = t for t in teamDataFromLevel @level
@teamColor = teams[@team].primaryColor
@teamBackgroundColor = teams[@team].bgColor
@opponentTeamColor = teams[@otherTeam].primaryColor
@opponentTeamBackgroundColor = teams[@otherTeam].bgColor
updateLanguage: -> updateLanguage: ->
aceConfig = _.cloneDeep me.get('aceConfig') ? {} aceConfig = _.cloneDeep me.get('aceConfig') ? {}
@ -59,6 +74,12 @@ module.exports = class LadderPlayModal extends ModalView
@challengers = @getChallengers() @challengers = @getChallengers()
ids = (challenger.opponentID for challenger in _.values @challengers) ids = (challenger.opponentID for challenger in _.values @challengers)
for challenger in _.values @challengers
continue unless challenger and @wizardType.loaded
if (not challenger.opponentImageSource) and challenger.opponentWizard?.colorConfig
challenger.opponentImageSource = @wizardType.getPortraitSource(
{colorConfig: challenger.opponentWizard.colorConfig})
success = (@nameMap) => success = (@nameMap) =>
for challenger in _.values(@challengers) for challenger in _.values(@challengers)
challenger.opponentName = @nameMap[challenger.opponentID]?.name or 'Anonymous' challenger.opponentName = @nameMap[challenger.opponentID]?.name or 'Anonymous'
@ -86,46 +107,9 @@ module.exports = class LadderPlayModal extends ModalView
@tutorialLevelExists = exists @tutorialLevelExists = exists
@render() @render()
@maybeShowTutorialButtons() @maybeShowTutorialButtons()
@genericPortrait = @wizardType.getPortraitSource()
getRenderData: -> myColorConfig = me.get('wizard')?.colorConfig
ctx = super() @myPortrait = if myColorConfig then @wizardType.getPortraitSource({colorConfig: myColorConfig}) else @genericPortrait
ctx.level = @level
ctx.levelID = @level.get('slug') or @level.id
ctx.teamName = _.string.titleize @team
ctx.teamID = @team
ctx.otherTeamID = @otherTeam
ctx.tutorialLevelExists = @tutorialLevelExists
ctx.language = @session?.get('codeLanguage') ? me.get('aceConfig')?.language ? 'python'
ctx.languages = [
{id: 'python', name: 'Python'}
{id: 'javascript', name: 'JavaScript'}
{id: 'coffeescript', name: 'CoffeeScript (Experimental)'}
{id: 'lua', name: 'Lua'}
{id: 'java', name: 'Java'}
]
ctx.league = @options.league
teamsList = teamDataFromLevel @level
teams = {}
teams[team.id] = team for team in teamsList
ctx.teamColor = teams[@team].primaryColor
ctx.teamBackgroundColor = teams[@team].bgColor
ctx.opponentTeamColor = teams[@otherTeam].primaryColor
ctx.opponentTeamBackgroundColor = teams[@otherTeam].bgColor
ctx.challengers = @challengers or {}
for challenger in _.values ctx.challengers
continue unless challenger and @wizardType.loaded
if (not challenger.opponentImageSource) and challenger.opponentWizard?.colorConfig
challenger.opponentImageSource = @wizardType.getPortraitSource(
{colorConfig: challenger.opponentWizard.colorConfig})
if @wizardType.loaded
ctx.genericPortrait = @wizardType.getPortraitSource()
myColorConfig = me.get('wizard')?.colorConfig
ctx.myPortrait = if myColorConfig then @wizardType.getPortraitSource({colorConfig: myColorConfig}) else ctx.genericPortrait
ctx.myName = me.get('name') || 'Newcomer'
ctx
maybeShowTutorialButtons: -> maybeShowTutorialButtons: ->
return if @session or LadderPlayModal.shownTutorialButton or not @tutorialLevelExists return if @session or LadderPlayModal.shownTutorialButton or not @tutorialLevelExists