Skip to content

Commit

Permalink
More mucking around with brackets`
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Faraday committed Oct 1, 2019
1 parent c131d2a commit 1923c98
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 29 deletions.
4 changes: 4 additions & 0 deletions brackets.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
<link rel="stylesheet" type="text/css" href="./lib/external/jquery.bracket.min.css"/>
<link rel="stylesheet" type="text/css" href="./style/bracket.css"/>
<script type="text/javascript" src="./lib/brackets/main.js"></script>
<script type="text/javascript" src="./lib/brackets/teams.js"></script>
</head>
<body>
<div id="tournament_brackets"></div>
<div class="team_display" id="green"></div>
<div class="team_display" id="red"></div>

<script type="text/javascript">
Brackets.init();
</script>
Expand Down
94 changes: 65 additions & 29 deletions lib/brackets/main.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,76 @@
Brackets = {
init: function () {
var minimalData = {
teams: [
[
{name: 'All Towards', gist: '808c86eb544d9efaf94a30efc91bdfaf'},
{name: 'Rotate', gist: '6634a7f381bb679ee7c2d90d93588d66'}
], /* first matchup */
[
{name: 'Long Random', gist: 'b9a0fe99060d9be1fc617bb7262f57be'},
{name: 'Faraday Cage', gist: 'd9eb9a70ad0dc0fb1885be0fce032adc'}
] /* second matchup */
]
};
init: function(results) {
if(typeof results == 'undefined') {
results = [];
}
var teams = [];
$.each(
Brackets.teams,
function(idx, team_data) {
var match_index = Math.floor(idx / 2);
var team_index = idx % 2;
// set team
if(typeof teams[match_index] == 'undefined') {
teams[match_index] = [];
}
teams[match_index][team_index] = team_data.name;
}
);

$('#tournament_brackets').bracket({
init: minimalData,
save: function (data) {
},
decorator: {
render: Brackets.render_fn,
edit: Brackets.edit_fn
save: function() {},
init: {
teams: teams,
results: results
},
disableToolbar: true,
disableTeamEdit: true,
teamWidth: 150
});

Brackets.init_team_display();
},
render_fn: function (container, data, score, state) {
if (data) {
container.append(data.name);
}
init_team_display: function() {
var select_options = [];
$.each(
Brackets.teams,
function(idx, team) {
select_options.push(
$('<option>')
.html(team.name)
.attr('value', team.gist)
);
}
);
$.each(
['green', 'red'],
function(idx, area) {
area = $('.team_display#' + area);
var select = $('<select>');
$.each(
select_options,
function(idx, option) {
select.append(option.clone());
}
);
select.on(
'change',
Brackets.show_team
);
area.append(select);
}
)
},
edit_fn: function (container, data, doneCb) {

show_team: function(e, x) {
var team_data = Brackets.get_team_data($(this).val());
console.log(team_data);
},

get_match: function (idx) {
var teams_data = $('#tournament_brackets').data().bracket.obj.data();

get_team_data: function(gist) {
return $.grep(
Brackets.teams,
function(team) {
return team.gist == gist;
}
)[0];
}
};
26 changes: 26 additions & 0 deletions lib/brackets/teams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Brackets.teams = [
{
name: 'All Towards',
gist: '808c86eb544d9efaf94a30efc91bdfaf',
description: 'This just goes towards the opposite corner.',
notes: ['Misses opponent', 'Original bot']
},
{
name: 'Rotate',
gist: '6634a7f381bb679ee7c2d90d93588d66',
description: 'Round and round and round...',
notes: []
},
{
name: 'Long Random',
gist: 'b9a0fe99060d9be1fc617bb7262f57be',
description: "Every 10 moves it goes a random direction.",
notes: ['Unpredictable']
},
{
name: 'Faraday Cage',
gist: 'd9eb9a70ad0dc0fb1885be0fce032adc',
description: 'A "sausage factory" which sends out high-value walkers',
notes: ['Named after Alan Faraday', 'Very hard to beat', 'Interrupt it early']
}
];
17 changes: 17 additions & 0 deletions style/bracket.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.team_display {
width: 45%;
float: left;
min-height: 50px;
margin: 1%;
border-radius: 10px;
padding:10px;
}

#green{
background-color: lightgreen;
}

#red {
background-color: lightpink;
}

0 comments on commit 1923c98

Please sign in to comment.