Skip to content

Commit

Permalink
replace model.timeTransform with model.getTimeTransform(), #77
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed May 1, 2024
1 parent 89dc499 commit 661b968
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 8 additions & 12 deletions js/common/model/BaseModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bounds2>;

// is the sim playing?
Expand All @@ -60,9 +59,6 @@ export default class BaseModel implements TModel {
// the clock speed of the sim
public readonly timeSpeedProperty: EnumerationProperty<TimeSpeed>;

// transform between real time and sim time, initialized below
public timeTransform: TimeTransform;

public readonly stopwatch: Stopwatch;

protected constructor( providedOptions: BaseModelOptions ) {
Expand Down Expand Up @@ -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: {
Expand All @@ -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.
Expand All @@ -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 ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/BaseScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down

0 comments on commit 661b968

Please sign in to comment.