Skip to content

Commit

Permalink
simplify notSettingPhetioStateProperty, phetsims/tandem#294
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Kauzmann <[email protected]>
  • Loading branch information
zepumph committed Jun 13, 2023
1 parent 16be726 commit 1c9e296
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions js/sound-generators/SoundGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import isSettingPhetioStateProperty from '../../../tandem/js/isSettingPhetioStat
// constants
const DEFAULT_TIME_CONSTANT = soundConstants.DEFAULT_PARAM_CHANGE_TIME_CONSTANT;

let notSettingPhetioStateProperty: TReadOnlyProperty<boolean>;
const notSettingPhetioStateProperty = DerivedProperty.not( isSettingPhetioStateProperty );

export type SoundGeneratorOptions = {

Expand Down Expand Up @@ -170,29 +170,9 @@ abstract class SoundGenerator {
this.soundSourceDestination = audioNode;
}

// TODO: simplify this in https://github.com/phetsims/tandem/issues/294
// Make sure that this sound never plays when setting PhET-iO state
if ( Tandem.PHET_IO_ENABLED && !options.enabledDuringPhetioStateSetting ) {
if ( Tandem.launched ) {
assert && assert( notSettingPhetioStateProperty, 'Should exist after launch' );

// If this SoundGenerator is being constructed after PhET-iO has been started, add an enable-control Property to
// prevent sound during the setting of PhET-iO state.
this.addEnableControlProperty( notSettingPhetioStateProperty );
}
else {

// If this SoundGenerator is being constructed before PhET-iO is fully set up, add a listener, called once
// PhET-iO is ready, to then add an enable-control Property that will prevent sound during the setting of
// PhET-iO state.
Tandem.addLaunchListener( () => {
if ( !notSettingPhetioStateProperty ) {

// Store this for later instantiations of SoundGenerator
notSettingPhetioStateProperty = DerivedProperty.not( isSettingPhetioStateProperty );
}
this.addEnableControlProperty( notSettingPhetioStateProperty );
} );
}
this.addEnableControlProperty( notSettingPhetioStateProperty );
}

this.disposeSoundGenerator = () => {
Expand Down

0 comments on commit 1c9e296

Please sign in to comment.