2023-04-21 22:41:22 +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 ;
2023-04-19 20:03:14 +02:00
export class Stats {
2023-04-19 19:56:51 +02:00
constructor ( highScoreStorageKey ) {
2023-04-21 22:41:22 +02:00
var _a ;
_Stats _score . set ( this , void 0 ) ;
_Stats _highScore . set ( this , void 0 ) ;
_Stats _highScoreStorageKey . set ( this , void 0 ) ;
2023-04-21 23:23:32 +02:00
// used as key for localStorage
2023-04-21 22:41:22 +02:00
_ _classPrivateFieldSet ( this , _Stats _highScoreStorageKey , highScoreStorageKey , "f" ) ;
_ _classPrivateFieldSet ( this , _Stats _score , 0 , "f" ) ;
2023-04-21 23:23:32 +02:00
_ _classPrivateFieldSet ( this , _Stats _highScore , ( _a = Number ( localStorage . getItem ( _ _classPrivateFieldGet ( this , _Stats _highScoreStorageKey , "f" ) ) ) ) !== null && _a !== void 0 ? _a : 0 , "f" ) ;
2023-04-19 19:56:51 +02:00
}
incrementScore ( value = 1 ) {
2023-04-21 22:41:22 +02:00
_ _classPrivateFieldSet ( this , _Stats _score , _ _classPrivateFieldGet ( this , _Stats _score , "f" ) + value , "f" ) ;
if ( _ _classPrivateFieldGet ( this , _Stats _highScore , "f" ) < _ _classPrivateFieldGet ( this , _Stats _score , "f" ) ) {
_ _classPrivateFieldSet ( this , _Stats _highScore , _ _classPrivateFieldGet ( this , _Stats _score , "f" ) , "f" ) ;
2023-04-21 23:23:32 +02:00
localStorage . setItem ( _ _classPrivateFieldGet ( this , _Stats _highScoreStorageKey , "f" ) , _ _classPrivateFieldGet ( this , _Stats _highScore , "f" ) . toString ( ) ) ;
2023-04-19 19:56:51 +02:00
}
}
2023-04-19 20:48:51 +02:00
resetScore ( ) {
2023-04-21 22:41:22 +02:00
_ _classPrivateFieldSet ( this , _Stats _score , 0 , "f" ) ;
2023-04-19 20:48:51 +02:00
}
2023-04-19 20:03:14 +02:00
get highScore ( ) {
2023-04-21 22:41:22 +02:00
return _ _classPrivateFieldGet ( this , _Stats _highScore , "f" ) ;
2023-04-19 20:03:14 +02:00
}
get score ( ) {
2023-04-21 22:41:22 +02:00
return _ _classPrivateFieldGet ( this , _Stats _score , "f" ) ;
2023-04-19 20:03:14 +02:00
}
2023-04-21 22:41:22 +02:00
}
_Stats _score = new WeakMap ( ) , _Stats _highScore = new WeakMap ( ) , _Stats _highScoreStorageKey = new WeakMap ( ) ;