Skip to content

Commit

Permalink
Update instrumentation for preferences, see phetsims/buoyancy#126
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Apr 10, 2024
1 parent 2600a15 commit 4d5609c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
3 changes: 2 additions & 1 deletion js/common/DensityBuoyancyCommonQueryParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
*/

import densityBuoyancyCommon from '../densityBuoyancyCommon.js';
import packageJSON from '../../../joist/js/packageJSON.js';

export const VolumeUnitsValues = [ 'liters', 'decimetersCubed' ] as const;
export type VolumeUnits = ( typeof VolumeUnitsValues )[number];

// In Buoyancy Basics, the percentage submerged readout is shown by default as an additional cue to the student.
// In Buoyancy, it can be enabled in the preferences menu or via a query parameter.
const defaultPercentageSubmergedVisible = phet.joist.packageJSON.name === 'buoyancy-basics';
const defaultPercentageSubmergedVisible = packageJSON.name === 'buoyancy-basics';

const DensityBuoyancyCommonQueryParameters = QueryStringMachine.getAll( {

Expand Down
5 changes: 4 additions & 1 deletion js/common/model/DensityBuoyancyCommonPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import densityBuoyancyCommon from '../../densityBuoyancyCommon.js';
import StringUnionProperty from '../../../../axon/js/StringUnionProperty.js';
import DensityBuoyancyCommonQueryParameters, { VolumeUnits, VolumeUnitsValues } from '../DensityBuoyancyCommonQueryParameters.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import packageJSON from '../../../../joist/js/packageJSON.js';

export const supportsPercentageSubmergedVisible = packageJSON.name !== 'density';

const DensityBuoyancyCommonPreferences = {
volumeUnitsProperty: new StringUnionProperty<VolumeUnits>( DensityBuoyancyCommonQueryParameters.volumeUnits as VolumeUnits, {
Expand All @@ -19,7 +22,7 @@ const DensityBuoyancyCommonPreferences = {
phetioFeatured: true
} ),
percentageSubmergedVisibleProperty: new BooleanProperty( DensityBuoyancyCommonQueryParameters.percentageSubmergedVisible, {
tandem: Tandem.PREFERENCES.createTandem( 'percentageSubmergedProperty' ),
tandem: supportsPercentageSubmergedVisible ? Tandem.PREFERENCES.createTandem( 'percentageSubmergedProperty' ) : Tandem.OPT_OUT,
phetioFeatured: true
} )
};
Expand Down
41 changes: 17 additions & 24 deletions js/common/view/DensityBuoyancyCommonPreferencesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import { RichText, Text, VBox, VBoxOptions } from '../../../../scenery/js/imports.js';
import densityBuoyancyCommon from '../../densityBuoyancyCommon.js';
import DensityBuoyancyCommonPreferences from '../model/DensityBuoyancyCommonPreferences.js';
import DensityBuoyancyCommonPreferences, { supportsPercentageSubmergedVisible } from '../model/DensityBuoyancyCommonPreferences.js';
import VolumeUnitsControl from './VolumeUnitsControl.js';
import PreferencesControl from '../../../../joist/js/preferences/PreferencesControl.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import PreferencesDialogConstants from '../../../../joist/js/preferences/PreferencesDialogConstants.js';
import ToggleSwitch from '../../../../sun/js/ToggleSwitch.js';
import DensityBuoyancyCommonStrings from '../../DensityBuoyancyCommonStrings.js';
Expand All @@ -36,32 +35,26 @@ export default class DensityBuoyancyCommonPreferencesNode extends VBox {
phetioVisiblePropertyInstrumented: false
}, providedOptions );

const volumeUnitsControl = new VolumeUnitsControl( DensityBuoyancyCommonPreferences.volumeUnitsProperty, {
options.children = [ new VolumeUnitsControl( DensityBuoyancyCommonPreferences.volumeUnitsProperty, {
tandem: options.tandem.createTandem( 'volumeUnitsControl' )
} );

const percentageSubmergedVisibleControl = new PercentageSubmergedVisibleControl( options.tandem.createTandem( 'percentageSubmergedVisibleControl' ) );

options.children = [
volumeUnitsControl,
percentageSubmergedVisibleControl
];
} ) ];

if ( supportsPercentageSubmergedVisible ) {
const percentageSubmergedVisibleControl = new PreferencesControl( {
isDisposable: false,
labelNode: new Text( DensityBuoyancyCommonStrings.preferences.percentageSubmerged.titleStringProperty, PreferencesDialogConstants.CONTROL_LABEL_OPTIONS ),
descriptionNode: new RichText( DensityBuoyancyCommonStrings.preferences.percentageSubmerged.descriptionStringProperty,
PreferencesDialogConstants.CONTROL_DESCRIPTION_OPTIONS ),
controlNode: new ToggleSwitch( DensityBuoyancyCommonPreferences.percentageSubmergedVisibleProperty, false, true, PreferencesDialogConstants.TOGGLE_SWITCH_OPTIONS ),
tandem: options.tandem.createTandem( 'percentageSubmergedVisibleControl' )
} );
percentageSubmergedVisibleControl.addLinkedElement( DensityBuoyancyCommonPreferences.percentageSubmergedVisibleProperty );

options.children.push( percentageSubmergedVisibleControl );
}

super( options );
}
}

class PercentageSubmergedVisibleControl extends PreferencesControl {
public constructor( tandem: Tandem ) {
super( {
isDisposable: false,
labelNode: new Text( DensityBuoyancyCommonStrings.preferences.percentageSubmerged.titleStringProperty, PreferencesDialogConstants.CONTROL_LABEL_OPTIONS ),
descriptionNode: new RichText( DensityBuoyancyCommonStrings.preferences.percentageSubmerged.descriptionStringProperty,
PreferencesDialogConstants.CONTROL_DESCRIPTION_OPTIONS ),
controlNode: new ToggleSwitch( DensityBuoyancyCommonPreferences.percentageSubmergedVisibleProperty, false, true, PreferencesDialogConstants.TOGGLE_SWITCH_OPTIONS ),
tandem: tandem
} );
}
}

densityBuoyancyCommon.register( 'DensityBuoyancyCommonPreferencesNode', DensityBuoyancyCommonPreferencesNode );
3 changes: 1 addition & 2 deletions js/common/view/VolumeUnitsControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export default class VolumeUnitsControl extends HBox {
}, providedOptions );

const labelText = new Text( DensityBuoyancyCommonStrings.volumeUnitsStringProperty, {
font: PreferencesDialog.CONTENT_FONT,
tandem: options.tandem.createTandem( 'labelText' )
font: PreferencesDialog.CONTENT_FONT
} );

const radioButtonGroup = new VolumeUnitsRadioButtonGroup( beakerUnitsProperty, {
Expand Down

0 comments on commit 4d5609c

Please sign in to comment.