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 _CpuRepository _instances , _CpuRepository _cpuList , _CpuRepository _currentCPU , _CpuRepository _nextCPU , _CpuRepository _getRandomInt ;
2023-04-19 21:54:42 +02:00
export class CpuRepository {
2023-04-21 22:41:22 +02:00
constructor ( ) {
_CpuRepository _instances . add ( this ) ;
_CpuRepository _cpuList . set ( this , void 0 ) ;
_CpuRepository _currentCPU . set ( this , void 0 ) ;
_CpuRepository _nextCPU . set ( this , void 0 ) ;
}
2023-04-19 19:57:22 +02:00
async init ( ) {
const fetchResult = await fetch ( "./js/data.json" ) ;
2023-04-21 22:41:22 +02:00
_ _classPrivateFieldSet ( this , _CpuRepository _cpuList , await fetchResult . json ( ) , "f" ) ;
_ _classPrivateFieldSet ( this , _CpuRepository _currentCPU , this . getRandomCpu ( ) , "f" ) ;
_ _classPrivateFieldSet ( this , _CpuRepository _nextCPU , this . getRandomCpu ( ) , "f" ) ;
2023-04-19 19:57:22 +02:00
}
get currentCpu ( ) {
2023-04-21 22:41:22 +02:00
return _ _classPrivateFieldGet ( this , _CpuRepository _currentCPU , "f" ) ;
2023-04-19 19:57:22 +02:00
}
get nextCpu ( ) {
2023-04-21 22:41:22 +02:00
return _ _classPrivateFieldGet ( this , _CpuRepository _nextCPU , "f" ) ;
2023-04-19 19:57:22 +02:00
}
getRandomCpu ( ) {
2023-04-21 23:23:32 +02:00
let randomIndex ;
do {
randomIndex = _ _classPrivateFieldGet ( this , _CpuRepository _instances , "m" , _CpuRepository _getRandomInt ) . call ( this , 0 , _ _classPrivateFieldGet ( this , _CpuRepository _cpuList , "f" ) . length ) ;
} while ( _ _classPrivateFieldGet ( this , _CpuRepository _cpuList , "f" ) [ randomIndex ] [ "value" ] == null || _ _classPrivateFieldGet ( this , _CpuRepository _cpuList , "f" ) [ randomIndex ] [ "type" ] == null ) ;
2023-04-21 22:41:22 +02:00
_ _classPrivateFieldGet ( this , _CpuRepository _cpuList , "f" ) [ randomIndex ] [ "name" ] = _ _classPrivateFieldGet ( this , _CpuRepository _cpuList , "f" ) [ randomIndex ] [ "name" ] . split ( '@' ) [ 0 ] ;
return _ _classPrivateFieldGet ( this , _CpuRepository _cpuList , "f" ) [ randomIndex ] ;
2023-04-19 19:57:22 +02:00
}
2023-04-21 23:23:32 +02:00
nextRound ( ) {
_ _classPrivateFieldSet ( this , _CpuRepository _currentCPU , _ _classPrivateFieldGet ( this , _CpuRepository _nextCPU , "f" ) , "f" ) ;
_ _classPrivateFieldSet ( this , _CpuRepository _nextCPU , this . getRandomCpu ( ) , "f" ) ;
}
2023-04-21 22:41:22 +02:00
}
_CpuRepository _cpuList = new WeakMap ( ) , _CpuRepository _currentCPU = new WeakMap ( ) , _CpuRepository _nextCPU = new WeakMap ( ) , _CpuRepository _instances = new WeakSet ( ) , _CpuRepository _getRandomInt = function _CpuRepository _getRandomInt ( min , max ) {
min = Math . ceil ( min ) ;
max = Math . floor ( max ) ;
return Math . floor ( Math . random ( ) * ( max - min ) + min ) ; // The maximum is exclusive and the minimum is inclusive
} ;