Skip to content

Commit f4a9e47

Browse files
committed
fix: fix heart columns and skin size
1 parent 5bc4080 commit f4a9e47

4 files changed

Lines changed: 51 additions & 16 deletions

File tree

frontend/src/app/auth.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ export class AuthService {
4545
return this._cookieService.get("token");
4646
}
4747

48+
public getUsername() {
49+
let token = this._cookieService.get("token");
50+
51+
if(token) {
52+
let decodedJWT = JSON.parse(window.atob(token.split('.')[1]));
53+
return decodedJWT.username;
54+
}
55+
56+
return ''
57+
}
58+
4859
public isLoggedIn(): boolean {
4960
let token = this._cookieService.get("token");
5061
return token != null && !this.jwtHelper.isTokenExpired(token);

frontend/src/app/components/player-status/player-status.component.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@
5858
</div>
5959
</div>
6060
<div class="flex items-center flex-col mt-8">
61-
<h1 style="font-size: 30px">S1mple133</h1>
61+
<h1 style="font-size: 30px">{{username}}</h1>
6262
<div id="skinContainer"></div>
63-
<div class="flex justify-between items-center mt-4">
64-
<img *ngFor="let i of heartRows" ngSrc="assets/img/minecraft-heart.webp" width="35" height="35">
65-
<!--<img *ngFor="let i of [1,2,3]" ngSrc="assets/img/minecraft-heart-black.png" width="35" height="35" >-->
63+
<div class="flex items-start flex-col">
64+
<div *ngFor="let i of heartRows" class="flex justify-between items-center mt-4">
65+
<img *ngFor="let i of heartHeartsPerRowArr" ngSrc="assets/img/minecraft-heart.webp" width="20" height="20">
66+
<!--<img *ngFor="let i of [1,2,3]" ngSrc="assets/img/minecraft-heart-black.png" width="35" height="35" >-->
67+
</div>
68+
<div class="flex justify-between items-start mt-4">
69+
<img *ngFor="let i of heartsInLastRow" ngSrc="assets/img/minecraft-heart.webp" width="20" height="20">
70+
</div>
6671
</div>
6772
</div>
6873
</div>

frontend/src/app/components/player-status/player-status.component.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ export class PlayerStatusComponent implements OnInit, OnChanges {
3333
element: "",
3434
matrik: 0
3535
}
36-
heartRows: number[] = []
36+
heartHeartsPerRowArr: number[] = []
37+
heartRows: number[] = [];
3738
@Input() playerName: string = '';
39+
username: string = '';
40+
heartsInLastRow: number[] = [];
41+
42+
HEALTH_HEARTS_PER_ROW = 10;
3843

3944
constructor(private _authService: AuthService,
4045
private _statsService: StatsService) {
@@ -52,25 +57,42 @@ export class PlayerStatusComponent implements OnInit, OnChanges {
5257
updateData(playerName: string) {
5358
if(playerName == '') {
5459
this._statsService.getSkinName().subscribe((skin: any) => {
55-
genSkin(skin.skin, 300, 500);
60+
genSkin(skin.skin, 300, 350);
5661
});
5762

5863
this._statsService.getLatestPlayerStats().subscribe(stats => {
5964
this.latestPlayerStats = stats;
60-
while(this.heartRows.length < stats.health) {
61-
this.heartRows.push(0)
62-
}
65+
this.calculateHealthRows(this.latestPlayerStats.health);
6366
})
67+
68+
this.username = this._authService.getUsername()
6469
}
6570
else {
66-
genSkin(playerName, 300, 500);
71+
genSkin(playerName, 300, 350);
6772

6873
this._statsService.getMatrixDexPlayerStats(playerName).subscribe(stats => {
6974
this.latestPlayerStats = stats;
70-
while(this.heartRows.length < stats.health) {
71-
this.heartRows.push(0)
72-
}
75+
this.calculateHealthRows(this.latestPlayerStats.health);
7376
})
77+
78+
this.username = playerName
79+
}
80+
}
81+
82+
private calculateHealthRows(health: number) {
83+
health = 25
84+
const amountFullRows = Math.floor(health / this.HEALTH_HEARTS_PER_ROW);
85+
const amountHearthsInLastRow = health-(amountFullRows*this.HEALTH_HEARTS_PER_ROW)
86+
while (this.heartHeartsPerRowArr.length < this.HEALTH_HEARTS_PER_ROW ) {
87+
this.heartHeartsPerRowArr.push(0)
88+
}
89+
this.heartRows = [];
90+
while (this.heartRows.length < amountFullRows ) {
91+
this.heartRows.push(0)
92+
}
93+
this.heartsInLastRow = [];
94+
while (this.heartsInLastRow.length < amountHearthsInLastRow ) {
95+
this.heartsInLastRow.push(0)
7496
}
7597
}
7698

frontend/src/app/home/home.component.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import {DOCUMENT, NgFor} from "@angular/common";
66
import {PlayerStats} from "../models/player-stats";
77
import { NgForm } from '@angular/forms';
88
import {PlayerKill} from "../models/player-kill";
9-
10-
declare const genSkin: any;
11-
129
@Component({
1310
selector: 'app-home',
1411
templateUrl: './home.component.html',

0 commit comments

Comments
 (0)