diff --git a/js/common/model/BaseModel.ts b/js/common/model/BaseModel.ts index aad7d83d..4f7729ef 100644 --- a/js/common/model/BaseModel.ts +++ b/js/common/model/BaseModel.ts @@ -51,7 +51,6 @@ export default class BaseModel implements TModel { // Bounds of the entire space that the model knows about. // This corresponds to the browser window, and doesn't have a valid value until the view is created. - //TODO https://github.com/phetsims/gas-properties/issues/77 PhET-iO instrumentation? public readonly modelBoundsProperty: Property; // is the sim playing? @@ -60,9 +59,6 @@ export default class BaseModel implements TModel { // the clock speed of the sim public readonly timeSpeedProperty: EnumerationProperty; - // transform between real time and sim time, initialized below - public timeTransform: TimeTransform; - public readonly stopwatch: Stopwatch; protected constructor( providedOptions: BaseModelOptions ) { @@ -97,13 +93,6 @@ export default class BaseModel implements TModel { tandem: options.tandem.createTandem( 'timeSpeedProperty' ) } ); - this.timeTransform = TimeTransform.NORMAL; - - // Adjust the time transform - this.timeSpeedProperty.link( speed => { - this.timeTransform = ( speed === TimeSpeed.SLOW ) ? TimeTransform.SLOW : TimeTransform.NORMAL; - } ); - this.stopwatch = new Stopwatch( { position: options.stopwatchPosition, timePropertyOptions: { @@ -128,6 +117,13 @@ export default class BaseModel implements TModel { this.stopwatch.reset(); } + /** + * Gets the transform between real time and sim time. + */ + public getTimeTransform(): TimeTransform { + return ( this.timeSpeedProperty.value === TimeSpeed.SLOW ) ? TimeTransform.SLOW : TimeTransform.NORMAL; + } + /** * Steps the model using real time units. * This should be called directly only by Sim.js, and is a no-op when the sim is paused. @@ -149,7 +145,7 @@ export default class BaseModel implements TModel { */ public stepRealTime( dt: number ): void { assert && assert( dt > 0, `invalid dt: ${dt}` ); - this.stepModelTime( this.timeTransform.evaluate( dt ) ); + this.stepModelTime( this.getTimeTransform().evaluate( dt ) ); } /** diff --git a/js/common/view/BaseScreenView.ts b/js/common/view/BaseScreenView.ts index 3f051096..fc1d61fc 100644 --- a/js/common/view/BaseScreenView.ts +++ b/js/common/view/BaseScreenView.ts @@ -73,7 +73,7 @@ export default abstract class BaseScreenView extends ScreenView { // when the Step button is pressed listener: () => { - const seconds = model.timeTransform.inverse( GasPropertiesConstants.MODEL_TIME_STEP ); + const seconds = model.getTimeTransform().inverse( GasPropertiesConstants.MODEL_TIME_STEP ); model.stepRealTime( seconds ); this.stepView( seconds ); }