import { ObservableReflexScreen , ObservableScaleXCommand , ObservableStopAndResetCommand , ObservableStopCommand , Observer , } from '@ulangi/ulangi-observable' ; import { config } from '../../constants/config' ; export class TimerDelegate { private observer : Observer ; public observableScreen : ObservableReflexScreen ; public constructor ( observer , observableScreen ) { this . observer = observer ; this . observableScreen = observableScreen ; } public startTimer ( callback ) { const timerCommand = new ObservableScaleXCommand ( 0 , this . observableScreen . gameState . remainingTime ) ; this . observableScreen . gameState . timerCommandList . commands . push ( timerCommand ) ; this . observer . when ( ( ) : boolean => timerCommand . state === 'completed' , callback . onTimeUp ) ; } public stopTimer ( ) { this . observableScreen . gameState . timerCommandList . commands . push ( new ObservableStopCommand ( ) ) ; } public stopAndResetTimer ( ) { this . observableScreen . gameState . remainingTime = config . reflex . timePerQuestion ; this . observableScreen . gameState . timerCommandList . commands . push ( new ObservableStopAndResetCommand ( ) ) ; } }