Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
feat(tournaments): Added Masters tournaments
Browse files Browse the repository at this point in the history
closes #1
  • Loading branch information
seiyria committed Oct 10, 2015
1 parent 124a309 commit 7f36870
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Expand Up @@ -18,6 +18,7 @@
"Duel": true,
"GroupStage": true,
"FFA": true,
"Masters": true,
"$": true,
"jsPDF": true
},
Expand Down
9 changes: 9 additions & 0 deletions src/jade/partials/tournaments/not-started.jade
Expand Up @@ -60,6 +60,8 @@ script(type="text/ng-template", id="/tournaments/not-started")
md-tooltip A round-robin style tournament
md-radio-button.md-primary(flex="25", value="ffa") Free For All
md-tooltip A free-for-all tournament
md-radio-button.md-primary(flex="25", value="masters") Masters
md-tooltip A subset of free-for-all where only knockouts per round are calculated

md-list-item(ng-if="tournamentOptions.type === 'singles' || tournamentOptions.type === 'doubles'")
ng-md-icon(icon="help", size="24")
Expand Down Expand Up @@ -110,6 +112,13 @@ script(type="text/ng-template", id="/tournaments/not-started")
ng-md-icon.margin-right-5(icon="error", size="24")
p.error You can't have more advancer entries than round entries.

md-list-item(ng-if="tournamentOptions.type === 'masters'")
ng-md-icon.margin-right-5(icon="help", size="24")
md-tooltip The number of people knocked out each round
md-input-container(ng-init="tournamentOptions.knockoutsString = '1'")
label Knockouts
input(ng-model="tournamentOptions.advancersString", ng-change="setStringArrValue('knockouts', 'knockoutsString')")

md-list-item(flex)

md-list-item
Expand Down
38 changes: 38 additions & 0 deletions src/jade/partials/tournaments/types/masters.jade
@@ -0,0 +1,38 @@

script(type="text/ng-template", id="tournament-masters")

.match-column-container.margin-bottom-10(layout="row")
.match-column.round-header.md-subhead.subhead(ng-repeat="match in maxMatches track by $index", scroll-observe="{{$index}}") Round {{$index+1}}

.match-area(layout="row")

.match-column(
ng-repeat="match in maxMatches track by $index",
ng-init="thisIndex=$index+1",
flex,
layout="column",
layout-align="space-around center")

md-card.match(
ng-repeat="match in trn.matches | inRound:thisIndex",
ng-init="match.score = match.score || []",
ng-class="{ unplayable: invalidMatch(match), complete: match.m }")

div(ng-if="noRender(match)", flex)
div(ng-show="false") {{getIdForMatch(match)}}
.match-data(ng-if="!noRender(match)", layout="row", layout-align="center center")
.round-type.subhead {{match.id.s}}-{{toCharacter(getIdForMatch(match))}}

.match-name(layout="column")
.member.padding-5(ng-repeat="p in match.p track by $index", class="member-{{$index}}", hover-highlight, hover-name="{{getName(match.p[$index]-1)}}") {{getName(match.p[$index]-1) || getString(match.id, $index) || '???'}}
md-tooltip(ng-if="bucket[match.p[$index]-1]") {{bucket[match.p[$index]-1].alias || 'no alias'}}: {{bucket[match.p[$index]-1].name}}

.scores.text-center(layout="column", ng-if="!invalidMatch(match)")
score.score-container.padding-5(ng-repeat="p in match.p track by $index", value="match.score[$index]", hover-name="{{getName(match.p[$index]-1)}}", can-click="{{hasAccess}}")

.scores.text-center(layout="column", ng-if="invalidMatch(match)")
.score-container.padding-5(ng-repeat="p in match.p track by $index", hover-name="{{getName(match.p[$index]-1)}}")
.score-value -

div.margin-right-10.margin-left-10.confirm-score
ng-md-icon(size="24", icon="check_circle", ng-click="confirmScore(match)", ng-if="!invalidMatch(match) && !scoresEqual(match)", style="fill: {{match.m ? '#ccc' : '#000'}}")
2 changes: 1 addition & 1 deletion src/js/controllers/dialogs/resultsDialogCtrl.js
Expand Up @@ -7,7 +7,7 @@ site.controller('resultsDialogController', ($scope, $mdDialog, tournamentName, r
$scope.tournamentName = tournamentName;
$scope.results = results;
$scope.players = players;

$scope.nameString = (idx) => {
const player = $scope.players[idx-1];
if(player.alias) return `${player.alias} (${player.name})`;
Expand Down
12 changes: 8 additions & 4 deletions src/js/controllers/tournaments/inProgressCtrl.js
Expand Up @@ -26,12 +26,12 @@ site.controller('inProgressController', ($scope, $timeout, EnsureLoggedIn, Sideb
$scope.includedTemplate = 'duel';

const determineTemplate = (options) => {
const hash = { singles: 'duel', doubles: 'duel', groupstage: 'groupstage', ffa: 'ffa' };
const hash = { singles: 'duel', doubles: 'duel', groupstage: 'groupstage', ffa: 'ffa', masters: 'masters' };
return options.last ? 'duel' : hash[options.type]; // backwards compatibility. damn alpha testers
};

const determineTournament = (options) => {
const hash = { singles: Duel, doubles: Duel, groupstage: GroupStage, ffa: FFA };
const hash = { singles: Duel, doubles: Duel, groupstage: GroupStage, ffa: FFA , masters: Masters };
return options.last ? Duel : hash[options.type]; // backwards compatibility. damn alpha testers
};

Expand Down Expand Up @@ -194,7 +194,11 @@ site.controller('inProgressController', ($scope, $timeout, EnsureLoggedIn, Sideb

$scope.invalidMatch = (match) => !$scope.trn.isPlayable(match);
$scope.noRender = (match) => _.any(match.p, p => p === -1);
$scope.scoresEqual = (match) => match.score && match.score.length === match.p.length ? match.score.length !== _.compact(_.uniq(match.score)).length : true;
$scope.scoresEqual = (match) => {
if(match.score && match.score.length === 1 || _.compact(match.score).length !== match.p.length) return true;
const sorted = _.sortBy(match.score).reverse();
return sorted[0] === sorted[1];
};

$scope.confirmScore = (match) => {
$scope.trn.score(match.id, _.map(match.score, i => +i));
Expand All @@ -208,7 +212,7 @@ site.controller('inProgressController', ($scope, $timeout, EnsureLoggedIn, Sideb
$scope.ref.$save();
};

if(!_.contains(['groupstage', 'ffa'], $scope.includedTemplate)) {
if(!_.contains(['groupstage', 'ffa', 'masters'], $scope.includedTemplate)) {
$timeout($scope.loadTournamentWinnerStrings, 0);
}
});
Expand Down
1 change: 1 addition & 0 deletions src/js/controllers/tournaments/notStartedCtrl.js
Expand Up @@ -39,6 +39,7 @@ site.controller('notStartedController', ($scope, EnsureLoggedIn, UserStatus, Sha
if(type === 'singles' || type === 'doubles') return Duel.invalid($scope.bucket.length, $scope.getOptions());
if(type === 'groupstage') return GroupStage.invalid($scope.bucket.length, $scope.getOptions());
if(type === 'ffa') return FFA.invalid($scope.bucket.length, $scope.getOptions());
if(type === 'masters') return Masters.invalid($scope.bucket.length, $scope.getOptions());
return true;
};

Expand Down

0 comments on commit 7f36870

Please sign in to comment.