Skip to content

Commit f8d83ee

Browse files
committed
Updated config interface and vocabulary
1 parent 57011bc commit f8d83ee

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/main.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Participant, Match, MatchResults, ParticipantResult, ViewerData } from
33
import { splitBy, getRanking, rankingHeader } from "./helpers";
44

55
type ConnectionType = 'square' | 'straight' | false;
6-
type Placement = 'before' | 'after';
6+
type Placement = 'none' | 'before' | 'after';
77

88
interface Connection {
99
connectPrevious?: ConnectionType,
@@ -12,21 +12,21 @@ interface Connection {
1212

1313
interface Config {
1414
/**
15-
* Where the position of a participant is placed.
15+
* Where the position of a participant is placed relative to its name.
1616
* - If `before`, the position is prepended before the team name. "#1 Team"
1717
* - If `after`, the position is appended after the team name, in parentheses. "Team (#1)"
1818
*/
19-
participantPositionPlacement: Placement,
19+
participantOriginPlacement: Placement,
2020

2121
/**
22-
* Whether to show the position of a participant wherever possible.
22+
* Whether to show the origin of a slot (wherever possible).
2323
*/
24-
showParticipantPosition: boolean,
24+
showSlotsOrigin: boolean,
2525

2626
/**
27-
* Whether to show the position of a participant in the lower bracket of an elimination stage.
27+
* Whether to show the origin of a slot (in the lower bracket of an elimination stage).
2828
*/
29-
showLowerBracketParticipantPosition: boolean,
29+
showLowerBracketSlotsOrigin: boolean,
3030
}
3131

3232
class BracketsViewer {
@@ -43,9 +43,9 @@ class BracketsViewer {
4343
}
4444

4545
this.config = {
46-
participantPositionPlacement: config && config.participantPositionPlacement || 'before',
47-
showParticipantPosition: config && config.showParticipantPosition || true,
48-
showLowerBracketParticipantPosition: config && config.showLowerBracketParticipantPosition || false,
46+
participantOriginPlacement: config && config.participantOriginPlacement || 'before',
47+
showSlotsOrigin: config && config.showSlotsOrigin || true,
48+
showLowerBracketSlotsOrigin: config && config.showLowerBracketSlotsOrigin || false,
4949
};
5050

5151
switch (data.stage.type) {
@@ -252,10 +252,12 @@ class BracketsViewer {
252252
} else {
253253
const participant = this.participants.find(participant => participant.id === team.id);
254254

255-
nameDOM.text(participant === undefined ? 'TBD' : participant.name);
256-
resultDOM.text(team.score === undefined ? '-' : team.score);
255+
if (participant) {
256+
nameDOM.text(participant.name);
257+
this.renderTeamOrigin(nameDOM, team, lowerBracket);
258+
}
257259

258-
this.renderTeamPosition(nameDOM, team, lowerBracket);
260+
resultDOM.text(team.score === undefined ? '-' : team.score);
259261

260262
if (team.result && team.result === 'win') {
261263
nameDOM.addClass('win');
@@ -290,18 +292,19 @@ class BracketsViewer {
290292
return teamDOM;
291293
}
292294

293-
private renderTeamPosition(name: JQuery, team: ParticipantResult, lowerBracket: boolean) {
295+
private renderTeamOrigin(name: JQuery, team: ParticipantResult, lowerBracket: boolean) {
294296
if (team.position === undefined) return;
295-
if (!this.config.showParticipantPosition) return;
296-
if (!this.config.showLowerBracketParticipantPosition && lowerBracket) return;
297+
if (this.config.participantOriginPlacement === 'none') return;
298+
if (!this.config.showSlotsOrigin) return;
299+
if (!this.config.showLowerBracketSlotsOrigin && lowerBracket) return;
297300

298301
// 'P' for position (where the participant comes from) and '#' for actual seeding.
299302
const text = lowerBracket ? `P${team.position}` : `#${team.position}`;
300303

301-
this.addPosition(name, text, this.config.participantPositionPlacement);
304+
this.addTeamOrigin(name, text, this.config.participantOriginPlacement);
302305
}
303306

304-
private addPosition(name: JQuery, text: string, placement: Placement,) {
307+
private addTeamOrigin(name: JQuery, text: string, placement: Placement) {
305308
if (placement === 'before')
306309
name.prepend($('<span>').text(`${text} `));
307310
else

0 commit comments

Comments
 (0)