Skip to content

Commit

Permalink
reset concentration alerter when rest of sim is reset, see #176
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Jul 1, 2022
1 parent aec3b7f commit 49a85e2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
16 changes: 14 additions & 2 deletions js/common/view/GasConcentrationAlerter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const DATE_CHANGE_UTTERANCE_OPTIONS = {

class GasConcentrationAlerter extends Alerter {

// reference to the model, used in the methods
private readonly model: ConcentrationModel;

// Time that has passed since last alert, when this equals ALERT_INTERVAL, a new alert is sent the UtteranceQueue.
private timeSinceLastAlert: number;

Expand Down Expand Up @@ -77,8 +80,6 @@ class GasConcentrationAlerter extends Alerter {
private netEnergyProperty: IReadOnlyProperty<number>;
private previousNetInflowOfEnergy: number;

private model: ConcentrationModel;

public constructor( model: ConcentrationModel, providedOptions?: AlerterOptions ) {

const options = optionize<AlerterOptions, EmptyObjectType, AlerterOptions>()( {
Expand All @@ -89,6 +90,7 @@ class GasConcentrationAlerter extends Alerter {

super( options );

this.model = model;
this.useVerboseSurfaceTemperatureAlert = true;
this.temperatureChangeAlertCount = 0;
this.timeSinceLastAlert = 0;
Expand Down Expand Up @@ -276,6 +278,16 @@ class GasConcentrationAlerter extends Alerter {
this.timeSinceLastAlert = 0;
}
}

/**
* Reset this to its initial state. For this to work properly, the model must be reset prior to calling this method.
*/
public reset(): void {
this.temperatureChangeAlertCount = 0;
this.timeSinceLastAlert = 0;
this.previousNetInflowOfEnergy = this.model.netInflowOfEnergyProperty.value;
this.previousConcentration = this.model.concentrationProperty.value;
}
}

greenhouseEffect.register( 'GasConcentrationAlerter', GasConcentrationAlerter );
Expand Down
4 changes: 4 additions & 0 deletions js/common/view/GreenhouseEffectObservationWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ class GreenhouseEffectObservationWindow extends Node {
// Does nothing in the base class, override as necessary in subclasses.
}

public reset(): void {
// Does nothing in the base class, override as necessary in subclasses.
}

// static values
public static SIZE: Dimension2 = SIZE;
public static CONTROL_AND_INSTRUMENT_INSET: number = CONTROL_AND_INSTRUMENT_INSET;
Expand Down
4 changes: 4 additions & 0 deletions js/common/view/LandscapeObservationWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ class LandscapeObservationWindow extends GreenhouseEffectObservationWindow {
public override step( dt: number ): void {
this.gasConcentrationAlerter.step( dt );
}

public override reset(): void {
this.gasConcentrationAlerter.reset();
}
}

greenhouseEffect.register( 'LandscapeObservationWindow', LandscapeObservationWindow );
Expand Down
1 change: 1 addition & 0 deletions js/waves/view/WavesScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ class WavesScreenView extends GreenhouseEffectScreenView {

public override reset(): void {
super.reset();
this.observationWindow.reset();
}
}

Expand Down

0 comments on commit 49a85e2

Please sign in to comment.