2023-04-28 22:13:19 +02:00
var _ _classPrivateFieldSet = ( this && this . _ _classPrivateFieldSet ) || function ( receiver , state , value , kind , f ) {
if ( kind === "m" ) throw new TypeError ( "Private method is not writable" ) ;
if ( kind === "a" && ! f ) throw new TypeError ( "Private accessor was defined without a setter" ) ;
if ( typeof state === "function" ? receiver !== state || ! f : ! state . has ( receiver ) ) throw new TypeError ( "Cannot write private member to an object whose class did not declare it" ) ;
return ( kind === "a" ? f . call ( receiver , value ) : f ? f . value = value : state . set ( receiver , value ) ) , value ;
} ;
var _ _classPrivateFieldGet = ( this && this . _ _classPrivateFieldGet ) || function ( receiver , state , kind , f ) {
if ( kind === "a" && ! f ) throw new TypeError ( "Private accessor was defined without a getter" ) ;
if ( typeof state === "function" ? receiver !== state || ! f : ! state . has ( receiver ) ) throw new TypeError ( "Cannot read private member from an object whose class did not declare it" ) ;
return kind === "m" ? f : kind === "a" ? f . call ( receiver ) : f ? f . value : state . get ( receiver ) ;
} ;
var _Stats _score , _Stats _highScore , _Stats _highScoreStorageKey ;
export class Stats {
constructor ( highScoreStorageKey ) {
var _a ;
_Stats _score . set ( this , void 0 ) ;
_Stats _highScore . set ( this , void 0 ) ;
_Stats _highScoreStorageKey . set ( this , void 0 ) ;
// used as key for localStorage
_ _classPrivateFieldSet ( this , _Stats _highScoreStorageKey , highScoreStorageKey , "f" ) ;
_ _classPrivateFieldSet ( this , _Stats _score , 0 , "f" ) ;
_ _classPrivateFieldSet ( this , _Stats _highScore , ( _a = Number ( localStorage . getItem ( _ _classPrivateFieldGet ( this , _Stats _highScoreStorageKey , "f" ) ) ) ) !== null && _a !== void 0 ? _a : 0 , "f" ) ;
}
incrementScore ( value = 1 ) {
_ _classPrivateFieldSet ( this , _Stats _score , _ _classPrivateFieldGet ( this , _Stats _score , "f" ) + value , "f" ) ;
2023-04-28 22:55:00 +02:00
this . checkHighScore ( ) ;
2023-04-28 22:13:19 +02:00
}
resetScore ( ) {
_ _classPrivateFieldSet ( this , _Stats _score , 0 , "f" ) ;
}
updateScore ( value ) {
_ _classPrivateFieldSet ( this , _Stats _score , _ _classPrivateFieldGet ( this , _Stats _score , "f" ) + value , "f" ) ;
2023-04-28 22:55:00 +02:00
this . checkHighScore ( ) ;
2023-04-28 22:13:19 +02:00
}
checkHighScore ( ) {
2023-04-28 22:55:00 +02:00
console . log ( "Highscore: " + _ _classPrivateFieldGet ( this , _Stats _highScore , "f" ) + " | Score: " + _ _classPrivateFieldGet ( this , _Stats _score , "f" ) ) ;
2023-04-28 22:13:19 +02:00
if ( _ _classPrivateFieldGet ( this , _Stats _highScore , "f" ) < _ _classPrivateFieldGet ( this , _Stats _score , "f" ) ) {
_ _classPrivateFieldSet ( this , _Stats _highScore , _ _classPrivateFieldGet ( this , _Stats _score , "f" ) , "f" ) ;
localStorage . setItem ( _ _classPrivateFieldGet ( this , _Stats _highScoreStorageKey , "f" ) , _ _classPrivateFieldGet ( this , _Stats _highScore , "f" ) . toString ( ) ) ;
}
}
get highScore ( ) {
return _ _classPrivateFieldGet ( this , _Stats _highScore , "f" ) ;
}
get score ( ) {
return _ _classPrivateFieldGet ( this , _Stats _score , "f" ) ;
}
}
_Stats _score = new WeakMap ( ) , _Stats _highScore = new WeakMap ( ) , _Stats _highScoreStorageKey = new WeakMap ( ) ;