@@ -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
0 commit comments