diff --git a/build.gradle b/build.gradle index 9f14080..7ef353e 100644 --- a/build.gradle +++ b/build.gradle @@ -85,7 +85,7 @@ dependencies { implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.20.0' - testImplementation group: 'org.slf4j', name: 'slf4j-jdk14', version: '2.0.0-alpha0' + testImplementation group: 'org.slf4j', name: 'slf4j-jdk14', version: '2.0.7' implementation("org.hibernate:hibernate-core:5.3.23.Final") implementation("mysql:mysql-connector-java:8.0.27") diff --git a/frontend/src/app/auth.service.ts b/frontend/src/app/auth.service.ts index f5905a6..2f382ac 100644 --- a/frontend/src/app/auth.service.ts +++ b/frontend/src/app/auth.service.ts @@ -45,6 +45,17 @@ export class AuthService { return this._cookieService.get("token"); } + public getUsername() { + let token = this._cookieService.get("token"); + + if(token) { + let decodedJWT = JSON.parse(window.atob(token.split('.')[1])); + return decodedJWT.username; + } + + return '' + } + public isLoggedIn(): boolean { let token = this._cookieService.get("token"); return token != null && !this.jwtHelper.isTokenExpired(token); diff --git a/frontend/src/app/components/player-status/player-status.component.html b/frontend/src/app/components/player-status/player-status.component.html index 750db09..c071c55 100644 --- a/frontend/src/app/components/player-status/player-status.component.html +++ b/frontend/src/app/components/player-status/player-status.component.html @@ -58,11 +58,16 @@
-

S1mple133

+

{{username}}

-
- - +
+
+ + +
+
+ +
diff --git a/frontend/src/app/components/player-status/player-status.component.ts b/frontend/src/app/components/player-status/player-status.component.ts index ca68573..555f7bd 100644 --- a/frontend/src/app/components/player-status/player-status.component.ts +++ b/frontend/src/app/components/player-status/player-status.component.ts @@ -33,8 +33,13 @@ export class PlayerStatusComponent implements OnInit, OnChanges { element: "", matrik: 0 } - heartRows: number[] = [] + heartHeartsPerRowArr: number[] = [] + heartRows: number[] = []; @Input() playerName: string = ''; + username: string = ''; + heartsInLastRow: number[] = []; + + HEALTH_HEARTS_PER_ROW = 10; constructor(private _authService: AuthService, private _statsService: StatsService) { @@ -52,25 +57,42 @@ export class PlayerStatusComponent implements OnInit, OnChanges { updateData(playerName: string) { if(playerName == '') { this._statsService.getSkinName().subscribe((skin: any) => { - genSkin(skin.skin, 300, 500); + genSkin(skin.skin, 300, 350); }); this._statsService.getLatestPlayerStats().subscribe(stats => { this.latestPlayerStats = stats; - while(this.heartRows.length < stats.health) { - this.heartRows.push(0) - } + this.calculateHealthRows(this.latestPlayerStats.health); }) + + this.username = this._authService.getUsername() } else { - genSkin(playerName, 300, 500); + genSkin(playerName, 300, 350); this._statsService.getMatrixDexPlayerStats(playerName).subscribe(stats => { this.latestPlayerStats = stats; - while(this.heartRows.length < stats.health) { - this.heartRows.push(0) - } + this.calculateHealthRows(this.latestPlayerStats.health); }) + + this.username = playerName + } + } + + private calculateHealthRows(health: number) { + health = 25 + const amountFullRows = Math.floor(health / this.HEALTH_HEARTS_PER_ROW); + const amountHearthsInLastRow = health-(amountFullRows*this.HEALTH_HEARTS_PER_ROW) + while (this.heartHeartsPerRowArr.length < this.HEALTH_HEARTS_PER_ROW ) { + this.heartHeartsPerRowArr.push(0) + } + this.heartRows = []; + while (this.heartRows.length < amountFullRows ) { + this.heartRows.push(0) + } + this.heartsInLastRow = []; + while (this.heartsInLastRow.length < amountHearthsInLastRow ) { + this.heartsInLastRow.push(0) } } diff --git a/frontend/src/app/home/home.component.ts b/frontend/src/app/home/home.component.ts index b374bf3..057bc93 100644 --- a/frontend/src/app/home/home.component.ts +++ b/frontend/src/app/home/home.component.ts @@ -6,9 +6,6 @@ import {DOCUMENT, NgFor} from "@angular/common"; import {PlayerStats} from "../models/player-stats"; import { NgForm } from '@angular/forms'; import {PlayerKill} from "../models/player-kill"; - -declare const genSkin: any; - @Component({ selector: 'app-home', templateUrl: './home.component.html',