-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port over leaderboard stuff from old site
- Loading branch information
Showing
8 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import {Component, Input, OnInit} from '@angular/core'; | ||
import {Level} from "../../api/types/levels/level"; | ||
import {ContainerTitleComponent} from "../ui/text/container-title.component"; | ||
import {DividerComponent} from "../ui/divider.component"; | ||
import {Score} from "../../api/types/levels/score"; | ||
import {ClientService} from "../../api/client.service"; | ||
import {ScorePreviewComponent} from "./score-preview.component"; | ||
|
||
@Component({ | ||
selector: 'app-level-leaderboard', | ||
standalone: true, | ||
imports: [ | ||
ContainerTitleComponent, | ||
DividerComponent, | ||
ScorePreviewComponent | ||
], | ||
template: ` | ||
<app-container-title>Leaderboard</app-container-title> | ||
<app-divider></app-divider> | ||
@for(score of scores; track score.scoreId) { | ||
<app-score-preview [score]="score"></app-score-preview> | ||
} | ||
`, | ||
styles: `` | ||
}) | ||
export class LevelLeaderboardComponent implements OnInit { | ||
@Input({required: true}) public level: Level = null!; | ||
scores: Score[] = []; | ||
|
||
scoreType: string = "1"; | ||
|
||
constructor(private client: ClientService) { | ||
} | ||
|
||
ngOnInit(): void { | ||
this.getScores(); | ||
} | ||
|
||
getScores(clear: boolean = true, skip: number = 0) { | ||
this.client.getScoresForLevel(this.level.levelId, Number(this.scoreType), skip) | ||
.subscribe((data) => { | ||
if (data === undefined) return; | ||
|
||
if (clear || this.scores == undefined) { | ||
this.scores = data.data; | ||
} else { | ||
this.scores = this.scores.concat(data.data); | ||
} | ||
|
||
let rank = 0; | ||
let i = 0; | ||
for (let score of this.scores) { | ||
const lastScore: Score | undefined = this.scores[i - 1]; | ||
if (lastScore?.score == score.score) { | ||
rank -= 1; | ||
} | ||
|
||
rank++; | ||
i++; | ||
score.rank = rank; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {Component, Input} from '@angular/core'; | ||
import {RouterLink} from "@angular/router"; | ||
import { Score } from '../../api/types/levels/score'; | ||
import {UserLinkComponent} from "../ui/text/links/user-link.component"; | ||
import {DateComponent} from "../ui/info/date.component"; | ||
|
||
@Component({ | ||
selector: 'app-score-preview', | ||
standalone: true, | ||
imports: [ | ||
RouterLink, | ||
UserLinkComponent, | ||
DateComponent | ||
], | ||
template: ` | ||
<div class="my-5 px-2.5"> | ||
<a [routerLink]="'/score/' + score.scoreId" class="flex items-center"> | ||
<div class="text-2xl mr-2"> | ||
@switch (score.rank) { | ||
@case(1) { | ||
<span class="text-rank-gold">#{{ score.rank }}</span> | ||
} | ||
@case(2) { | ||
<span class="text-rank-silver">#{{ score.rank }}</span> | ||
} | ||
@case(3) { | ||
<span class="text-rank-bronze">#{{ score.rank }}</span> | ||
} | ||
@default() { | ||
<span class="text-rank-other">#{{ score.rank }}</span> | ||
} | ||
} | ||
</div> | ||
<div class="flex flex-col"> | ||
<span class="text-lg">{{ score.score.toLocaleString(undefined) }} points</span> | ||
<span class="text-sm"> | ||
Achieved by | ||
<b><app-user-link [user]="score.players[0]"></app-user-link></b> | ||
<app-date [date]="score.scoreSubmitted"></app-date> | ||
</span> | ||
</div> | ||
</a> | ||
</div> | ||
` | ||
}) | ||
export class ScorePreviewComponent { | ||
@Input({required: true}) score: Score = null!; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/app/components/ui/layouts/two-pane-layout.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {Component, ContentChildren, ElementRef, QueryList, TemplateRef, ViewChildren} from '@angular/core'; | ||
import {NgTemplateOutlet} from "@angular/common"; | ||
|
||
@Component({ | ||
selector: 'app-two-pane-layout', | ||
standalone: true, | ||
imports: [ | ||
NgTemplateOutlet | ||
], | ||
template: ` | ||
<div class="grid grid-cols-2 sm:grid-cols-1 md:grid-cols-1 gap-2.5"> | ||
<ng-content></ng-content> | ||
</div> | ||
` | ||
}) | ||
export class TwoPaneLayoutComponent {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters