From 752803f29404ee84f72e32f646a78ec3c7240417 Mon Sep 17 00:00:00 2001 From: pixelzoom Date: Mon, 5 Jun 2023 14:47:24 -0600 Subject: [PATCH] collect derived strings in FMWDerivedStrings.ts, https://github.com/phetsims/fourier-making-waves/issues/235 --- js/common/FMWDerivedStrings.ts | 148 ++++++++++++++++++ js/common/view/AmplitudeKeypadDialog.ts | 14 +- js/common/view/AmplitudeNumberDisplay.ts | 9 +- js/common/view/DomainChartNode.ts | 26 ++- js/common/view/DomainComboBox.ts | 17 +- js/common/view/SumSymbolNode.ts | 1 + js/common/view/TickLabelUtils.ts | 1 + js/discrete/view/DiscreteInfoDialog.ts | 43 ++--- js/discrete/view/EquationComboBox.ts | 12 +- js/discrete/view/PeriodClockNode.ts | 4 +- js/waveGame/model/WaveGameLevel.ts | 33 ++-- js/waveGame/model/WaveGameModel.ts | 12 +- .../view/ComponentSpacingToolCheckbox.ts | 11 +- .../view/ComponentSpacingToolNode.ts | 9 +- js/wavepacket/view/WavePacketInfoDialog.ts | 39 ++--- 15 files changed, 242 insertions(+), 137 deletions(-) create mode 100644 js/common/FMWDerivedStrings.ts diff --git a/js/common/FMWDerivedStrings.ts b/js/common/FMWDerivedStrings.ts new file mode 100644 index 00000000..2e2fe57b --- /dev/null +++ b/js/common/FMWDerivedStrings.ts @@ -0,0 +1,148 @@ +// Copyright 2023, University of Colorado Boulder + +/** + * Derived strings used globally throughout this simulation. + * + * @author Chris Malley (PixelZoom, Inc.) + */ + +import fourierMakingWaves from '../fourierMakingWaves.js'; +import Tandem from '../../../tandem/js/Tandem.js'; +import FMWSymbols from './FMWSymbols.js'; +import PatternStringProperty from '../../../axon/js/PatternStringProperty.js'; +import FourierMakingWavesStrings from '../FourierMakingWavesStrings.js'; +import StringProperty from '../../../axon/js/StringProperty.js'; + +//TODO https://github.com/phetsims/tandem/issues/298 +const DERIVED_STRINGS_TANDEM = Tandem.GENERAL_MODEL.createTandem( 'strings' ).createTandem( 'fourierMakingWaves' ).createTandem( 'derivedStrings' ) + +const FMWDerivedStrings = { + + k1StringProperty: new PatternStringProperty( new StringProperty( '{{k}}1' ), { + k: FMWSymbols.kStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'k1StringProperty' ) + } ), + + omega1StringProperty: new PatternStringProperty( new StringProperty( '{{omega}}1' ), { + omega: FMWSymbols.omegaStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'omega1StringProperty' ) + } ), + + xMetersStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolUnitsStringProperty, { + symbol: FMWSymbols.xStringProperty, + units: FourierMakingWavesStrings.units.metersStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'xMetersStringProperty' ) + } ), + + xMillisecondsStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolUnitsStringProperty, { + symbol: FMWSymbols.tStringProperty, + units: FourierMakingWavesStrings.units.millisecondsStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'xMillisecondsStringProperty' ) + } ), + + spaceXStringProperty: new PatternStringProperty( FourierMakingWavesStrings.spaceSymbolStringProperty, { + symbol: FMWSymbols.xStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'spaceXStringProperty' ) + } ), + + timeTStringProperty: new PatternStringProperty( FourierMakingWavesStrings.timeSymbolStringProperty, { + symbol: FMWSymbols.tStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'timeTStringProperty' ) + } ), + + spaceAndTimeXTStringProperty: new PatternStringProperty( FourierMakingWavesStrings.spaceAndTimeSymbolsStringProperty, { + spaceSymbol: FMWSymbols.xStringProperty, + timeSymbol: FMWSymbols.tStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'spaceAndTimeXTStringProperty' ) + } ), + + lambdaAndTStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolAndSymbolStringProperty, { + symbol1: FMWSymbols.lambdaStringProperty, + symbol2: FMWSymbols.TStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'lambdaAndTStringProperty' ) + } ), + + kAndOmegaStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolAndSymbolStringProperty, { + symbol1: FMWSymbols.kStringProperty, + symbol2: FMWSymbols.omegaStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'kAndOmegaStringProperty' ) + } ), + + ADescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.AStringProperty, { + A: FMWSymbols.AStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'ADescriptionStringProperty' ) + } ), + + fDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.fStringProperty, { + f: FMWSymbols.fStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'fDescriptionStringProperty' ) + } ), + + lambdaDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.lambdaStringProperty, { + lambda: FMWSymbols.lambdaStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'lambdaDescriptionStringProperty' ) + } ), + + kDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.kStringProperty, { + k: FMWSymbols.kStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'kDescriptionStringProperty' ) + } ), + + LDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.LStringProperty, { + L: FMWSymbols.LStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'LDescriptionStringProperty' ) + } ), + + nDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.nStringProperty, { + n: FMWSymbols.nStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'nDescriptionStringProperty' ) + } ), + + tDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.tStringProperty, { + t: FMWSymbols.tStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'tDescriptionStringProperty' ) + } ), + + TDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.TStringProperty, { + T: FMWSymbols.TStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'TDescriptionStringProperty' ) + } ), + + omegaDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.omegaStringProperty, { + omega: FMWSymbols.omegaStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'omegaDescriptionStringProperty' ) + } ), + + sigmaDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.sigmaStringProperty, { + sigma: FMWSymbols.sigmaStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'sigmaDescriptionStringProperty' ) + } ), + + xDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.xStringProperty, { + x: FMWSymbols.xStringProperty + }, { + tandem: DERIVED_STRINGS_TANDEM.createTandem( 'xDescriptionStringProperty' ) + } ) +}; + +fourierMakingWaves.register( 'FMWDerivedStrings', FMWDerivedStrings ); +export default FMWDerivedStrings; \ No newline at end of file diff --git a/js/common/view/AmplitudeKeypadDialog.ts b/js/common/view/AmplitudeKeypadDialog.ts index 24c89129..24afcba9 100644 --- a/js/common/view/AmplitudeKeypadDialog.ts +++ b/js/common/view/AmplitudeKeypadDialog.ts @@ -27,7 +27,7 @@ import optionize, { combineOptions } from '../../../../phet-core/js/optionize.js import Bounds2 from '../../../../dot/js/Bounds2.js'; import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js'; import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js'; -import Tandem from '../../../../tandem/js/Tandem.js'; +import StringIO from '../../../../tandem/js/types/StringIO.js'; // constants const TITLE_FONT = new PhetFont( 18 ); @@ -104,8 +104,12 @@ export default class AmplitudeKeypadDialog extends Dialog { } ); // Title indicates which amplitude we're editing, e.g. A2. - const titleStringProperty = new DerivedProperty( [ FMWSymbols.AStringProperty, orderProperty ], - ( A, order ) => `${A}${order}` ); + const titleStringProperty = new DerivedProperty( + [ FMWSymbols.AStringProperty, orderProperty ], + ( A, order ) => `${A}${order}`, { + tandem: options.tandem.createTandem( 'titleStringProperty' ), + phetioValueType: StringIO + } ); const titleNode = new RichText( titleStringProperty, { font: TITLE_FONT, maxWidth: keypad.width @@ -115,7 +119,9 @@ export default class AmplitudeKeypadDialog extends Dialog { const rangeStringProperty = new PatternStringProperty( FourierMakingWavesStrings.minToMaxStringProperty, { min: Utils.toFixedNumber( amplitudeRange.min, options.decimalPlaces ), max: Utils.toFixedNumber( amplitudeRange.max, options.decimalPlaces ) - }, { tandem: Tandem.OPT_OUT } ); + }, { + tandem: options.tandem.createTandem( 'rangeStringProperty' ) + } ); const rangeNode = new Text( rangeStringProperty, { font: VALUE_FONT, maxWidth: keypad.width diff --git a/js/common/view/AmplitudeNumberDisplay.ts b/js/common/view/AmplitudeNumberDisplay.ts index 5b43cb7e..2b194c89 100644 --- a/js/common/view/AmplitudeNumberDisplay.ts +++ b/js/common/view/AmplitudeNumberDisplay.ts @@ -22,6 +22,7 @@ import AmplitudeKeypadDialog from './AmplitudeKeypadDialog.js'; import PickRequired from '../../../../phet-core/js/types/PickRequired.js'; import optionize from '../../../../phet-core/js/optionize.js'; import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js'; +import StringIO from '../../../../tandem/js/types/StringIO.js'; // constants const DEFAULT_FONT = new PhetFont( 14 ); @@ -61,8 +62,12 @@ export default class AmplitudeNumberDisplay extends InteractiveHighlighting( VBo const numberDisplay = new NumberDisplay( harmonic.amplitudeProperty, harmonic.amplitudeProperty.range, options.numberDisplayOptions ); - const labelStringProperty = new DerivedProperty( [ FMWSymbols.AStringProperty ], - A => `${A}${harmonic.order}` ); + const labelStringProperty = new DerivedProperty( + [ FMWSymbols.AStringProperty ], + A => `${A}${harmonic.order}`, { + tandem: options.tandem.createTandem( 'labelStringProperty' ), + phetioValueType: StringIO + } ); const labelNode = new RichText( labelStringProperty, { font: DEFAULT_FONT, diff --git a/js/common/view/DomainChartNode.ts b/js/common/view/DomainChartNode.ts index 5539b17a..92ec0357 100644 --- a/js/common/view/DomainChartNode.ts +++ b/js/common/view/DomainChartNode.ts @@ -14,7 +14,6 @@ import DerivedProperty from '../../../../axon/js/DerivedProperty.js'; import Multilink from '../../../../axon/js/Multilink.js'; -import PatternStringProperty from '../../../../axon/js/PatternStringProperty.js'; import AxisLine, { AxisLineOptions } from '../../../../bamboo/js/AxisLine.js'; import ChartRectangle, { ChartRectangleOptions } from '../../../../bamboo/js/ChartRectangle.js'; import ChartTransform, { ChartTransformOptions } from '../../../../bamboo/js/ChartTransform.js'; @@ -31,7 +30,6 @@ import fourierMakingWaves from '../../fourierMakingWaves.js'; import FourierMakingWavesStrings from '../../FourierMakingWavesStrings.js'; import FMWColors from '../FMWColors.js'; import FMWConstants from '../FMWConstants.js'; -import FMWSymbols from '../FMWSymbols.js'; import Domain from '../model/Domain.js'; import DomainChart from '../model/DomainChart.js'; import PickRequired from '../../../../phet-core/js/types/PickRequired.js'; @@ -39,17 +37,9 @@ import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js'; import NumberProperty from '../../../../axon/js/NumberProperty.js'; import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js'; import optionize from '../../../../phet-core/js/optionize.js'; -import Tandem from '../../../../tandem/js/Tandem.js'; - -// constants -const DEFAULT_X_SPACE_LABEL_PROPERTY = new PatternStringProperty( FourierMakingWavesStrings.symbolUnitsStringProperty, { - symbol: FMWSymbols.xStringProperty, - units: FourierMakingWavesStrings.units.metersStringProperty -}, { tandem: Tandem.OPT_OUT } ); -const DEFAULT_X_TIME_LABEL_PROPERTY = new PatternStringProperty( FourierMakingWavesStrings.symbolUnitsStringProperty, { - symbol: FMWSymbols.tStringProperty, - units: FourierMakingWavesStrings.units.millisecondsStringProperty -}, { tandem: Tandem.OPT_OUT } ); +import StringIO from '../../../../tandem/js/types/StringIO.js'; +import FMWDerivedStrings from '../FMWDerivedStrings.js'; + const DEFAULT_EDGE = 'min'; type SelfOptions = { @@ -107,8 +97,8 @@ export default class DomainChartNode extends Node { const options = optionize()( { // x-axis - xSpaceLabelProperty: DEFAULT_X_SPACE_LABEL_PROPERTY, - xTimeLabelProperty: DEFAULT_X_TIME_LABEL_PROPERTY, + xSpaceLabelProperty: FMWDerivedStrings.xMetersStringProperty, + xTimeLabelProperty: FMWDerivedStrings.xMillisecondsStringProperty, xGridLineSpacing: 1, xTickMarkSpacing: 1, xTickLabelSpacing: 1, @@ -172,8 +162,10 @@ export default class DomainChartNode extends Node { const xAxisLabelStringProperty = new DerivedProperty( [ domainProperty, options.xTimeLabelProperty, options.xSpaceLabelProperty ], - ( domain, xTimeLabel, xSpaceLabel ) => ( domain === Domain.TIME ) ? xTimeLabel : xSpaceLabel - ); + ( domain, xTimeLabel, xSpaceLabel ) => ( domain === Domain.TIME ) ? xTimeLabel : xSpaceLabel, { + tandem: options.tandem.createTandem( 'xAxisLabelStringProperty' ), + phetioValueType: StringIO + } ); // x-axis const xAxis = new AxisLine( chartTransform, Orientation.HORIZONTAL, options.axisLineOptions ); diff --git a/js/common/view/DomainComboBox.ts b/js/common/view/DomainComboBox.ts index 50a28d1f..80390a8a 100644 --- a/js/common/view/DomainComboBox.ts +++ b/js/common/view/DomainComboBox.ts @@ -7,39 +7,30 @@ * @author Chris Malley (PixelZoom, Inc.) */ -import PatternStringProperty from '../../../../axon/js/PatternStringProperty.js'; import { Node } from '../../../../scenery/js/imports.js'; import ComboBox from '../../../../sun/js/ComboBox.js'; import fourierMakingWaves from '../../fourierMakingWaves.js'; -import FourierMakingWavesStrings from '../../FourierMakingWavesStrings.js'; -import FMWSymbols from '../FMWSymbols.js'; import Domain from '../model/Domain.js'; import FMWComboBox, { FMWComboBoxChoice } from './FMWComboBox.js'; import Property from '../../../../axon/js/Property.js'; import Tandem from '../../../../tandem/js/Tandem.js'; +import FMWDerivedStrings from '../FMWDerivedStrings.js'; // This format is specific to FMWComboBox. const CHOICES: FMWComboBoxChoice[] = [ { value: Domain.SPACE, - stringProperty: new PatternStringProperty( FourierMakingWavesStrings.spaceSymbolStringProperty, { - symbol: FMWSymbols.xStringProperty - }, { tandem: Tandem.OPT_OUT } ), + stringProperty: FMWDerivedStrings.spaceXStringProperty, tandemName: `spaceItem${ComboBox.ITEM_TANDEM_NAME_SUFFIX}` }, { value: Domain.TIME, - stringProperty: new PatternStringProperty( FourierMakingWavesStrings.timeSymbolStringProperty, { - symbol: FMWSymbols.tStringProperty - }, { tandem: Tandem.OPT_OUT } ), + stringProperty: FMWDerivedStrings.timeTStringProperty, tandemName: `time${ComboBox.ITEM_TANDEM_NAME_SUFFIX}` }, { value: Domain.SPACE_AND_TIME, - stringProperty: new PatternStringProperty( FourierMakingWavesStrings.spaceAndTimeSymbolsStringProperty, { - spaceSymbol: FMWSymbols.xStringProperty, - timeSymbol: FMWSymbols.tStringProperty - }, { tandem: Tandem.OPT_OUT } ), + stringProperty: FMWDerivedStrings.spaceAndTimeXTStringProperty, tandemName: `spaceAndTime${ComboBox.ITEM_TANDEM_NAME_SUFFIX}` } ]; diff --git a/js/common/view/SumSymbolNode.ts b/js/common/view/SumSymbolNode.ts index 72856c54..d9a81c0a 100644 --- a/js/common/view/SumSymbolNode.ts +++ b/js/common/view/SumSymbolNode.ts @@ -63,6 +63,7 @@ export default class SumSymbolNode extends Node { font: options.symbolFont } ); + // Not instrumented for PhET-iO. const nEqualsStringProperty = new DerivedProperty( [ indexSymbolProperty ], indexSymbol => `${indexSymbol} ${MathSymbols.EQUAL_TO} ` ); diff --git a/js/common/view/TickLabelUtils.ts b/js/common/view/TickLabelUtils.ts index b136ef24..ce377e78 100644 --- a/js/common/view/TickLabelUtils.ts +++ b/js/common/view/TickLabelUtils.ts @@ -61,6 +61,7 @@ const TickLabelUtils = { const symbolStringProperty = ( typeof symbol === 'string' ) ? new StringProperty( symbol ) : symbol; + // Not instrumented for PhET-iO. richTextArgument = new DerivedProperty( [ symbolStringProperty ], symbol => { let text = ''; if ( sign === -1 ) { diff --git a/js/discrete/view/DiscreteInfoDialog.ts b/js/discrete/view/DiscreteInfoDialog.ts index e6467934..85ef40e2 100644 --- a/js/discrete/view/DiscreteInfoDialog.ts +++ b/js/discrete/view/DiscreteInfoDialog.ts @@ -7,14 +7,13 @@ */ import DerivedProperty from '../../../../axon/js/DerivedProperty.js'; -import PatternStringProperty from '../../../../axon/js/PatternStringProperty.js'; import { RichText, Text } from '../../../../scenery/js/imports.js'; import Dialog from '../../../../sun/js/Dialog.js'; import FMWConstants from '../../common/FMWConstants.js'; -import FMWSymbols from '../../common/FMWSymbols.js'; import fourierMakingWaves from '../../fourierMakingWaves.js'; import FourierMakingWavesStrings from '../../FourierMakingWavesStrings.js'; import Tandem from '../../../../tandem/js/Tandem.js'; +import FMWDerivedStrings from '../../common/FMWDerivedStrings.js'; // constants const MAX_WIDTH = 800; // determined empirically @@ -30,36 +29,16 @@ export default class DiscreteInfoDialog extends Dialog { // For each translated string describing a symbol, fill in the symbol. const stringProperties = [ - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.AStringProperty, { - A: FMWSymbols.AStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.fStringProperty, { - f: FMWSymbols.fStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.lambdaStringProperty, { - lambda: FMWSymbols.lambdaStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.kStringProperty, { - k: FMWSymbols.kStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.LStringProperty, { - L: FMWSymbols.LStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.nStringProperty, { - n: FMWSymbols.nStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.tStringProperty, { - t: FMWSymbols.tStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.TStringProperty, { - T: FMWSymbols.TStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.omegaStringProperty, { - omega: FMWSymbols.omegaStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.xStringProperty, { - x: FMWSymbols.xStringProperty - }, { tandem: Tandem.OPT_OUT } ) + FMWDerivedStrings.ADescriptionStringProperty, + FMWDerivedStrings.fDescriptionStringProperty, + FMWDerivedStrings.lambdaDescriptionStringProperty, + FMWDerivedStrings.kDescriptionStringProperty, + FMWDerivedStrings.LDescriptionStringProperty, + FMWDerivedStrings.nDescriptionStringProperty, + FMWDerivedStrings.tDescriptionStringProperty, + FMWDerivedStrings.TDescriptionStringProperty, + FMWDerivedStrings.omegaDescriptionStringProperty, + FMWDerivedStrings.xDescriptionStringProperty ]; // Put a line break between each of the above strings. diff --git a/js/discrete/view/EquationComboBox.ts b/js/discrete/view/EquationComboBox.ts index b6f164c4..4663db10 100644 --- a/js/discrete/view/EquationComboBox.ts +++ b/js/discrete/view/EquationComboBox.ts @@ -8,7 +8,6 @@ */ import EnumerationProperty from '../../../../axon/js/EnumerationProperty.js'; -import PatternStringProperty from '../../../../axon/js/PatternStringProperty.js'; import { Node } from '../../../../scenery/js/imports.js'; import ComboBox from '../../../../sun/js/ComboBox.js'; import FMWConstants from '../../common/FMWConstants.js'; @@ -19,6 +18,7 @@ import fourierMakingWaves from '../../fourierMakingWaves.js'; import FourierMakingWavesStrings from '../../FourierMakingWavesStrings.js'; import EquationForm from '../model/EquationForm.js'; import Tandem from '../../../../tandem/js/Tandem.js'; +import FMWDerivedStrings from '../../common/FMWDerivedStrings.js'; const MATH_TEXT_OPTIONS = { font: FMWConstants.MATH_CONTROL_FONT, @@ -65,19 +65,13 @@ const CHOICES: FMWComboBoxChoice[] = [ }, { value: EquationForm.WAVELENGTH_AND_PERIOD, - stringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolAndSymbolStringProperty, { - symbol1: FMWSymbols.lambdaStringProperty, - symbol2: FMWSymbols.TStringProperty - }, { tandem: Tandem.OPT_OUT } ), + stringProperty: FMWDerivedStrings.lambdaAndTStringProperty, textOptions: MATH_TEXT_OPTIONS, tandemName: `wavelengthAndPeriod${ComboBox.ITEM_TANDEM_NAME_SUFFIX}` }, { value: EquationForm.SPATIAL_WAVE_NUMBER_AND_ANGULAR_WAVE_NUMBER, - stringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolAndSymbolStringProperty, { - symbol1: FMWSymbols.kStringProperty, - symbol2: FMWSymbols.omegaStringProperty - }, { tandem: Tandem.OPT_OUT } ), + stringProperty: FMWDerivedStrings.kAndOmegaStringProperty, textOptions: MATH_TEXT_OPTIONS, tandemName: `spatialWaveNumberAndAngularWaveNumber${ComboBox.ITEM_TANDEM_NAME_SUFFIX}` }, diff --git a/js/discrete/view/PeriodClockNode.ts b/js/discrete/view/PeriodClockNode.ts index 95242059..741c2627 100644 --- a/js/discrete/view/PeriodClockNode.ts +++ b/js/discrete/view/PeriodClockNode.ts @@ -50,7 +50,9 @@ export default class PeriodClockNode extends DiscreteMeasurementToolNode { const clockFaceNode = new ClockFaceNode( harmonicProperty, tProperty ); const labelStringProperty = new DerivedProperty( [ FMWSymbols.TStringProperty, harmonicProperty ], - ( T, harmonic ) => `${T}${harmonic.order}` ); + ( T, harmonic ) => `${T}${harmonic.order}`, { + tandem: providedOptions.tandem.createTandem( 'labelStringProperty' ) + } ); const labelNode = new RichText( labelStringProperty, { font: FMWConstants.TOOL_LABEL_FONT, diff --git a/js/waveGame/model/WaveGameLevel.ts b/js/waveGame/model/WaveGameLevel.ts index fc524ccc..f6f78d8f 100644 --- a/js/waveGame/model/WaveGameLevel.ts +++ b/js/waveGame/model/WaveGameLevel.ts @@ -34,7 +34,7 @@ import WaveGameAmplitudesChart from './WaveGameAmplitudesChart.js'; import WaveGameHarmonicsChart from './WaveGameHarmonicsChart.js'; import WaveGameSumChart from './WaveGameSumChart.js'; import isSettingPhetioStateProperty from '../../../../tandem/js/isSettingPhetioStateProperty.js'; -import Tandem from '../../../../tandem/js/Tandem.js'; +import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js'; // constants @@ -119,21 +119,12 @@ export default class WaveGameLevel extends PhetioObject { assert && assert( Number.isInteger( levelNumber ) && levelNumber > 0 ); // numbered starting from 1 - const options = optionize()( { + const options = optionize, PhetioObjectOptions>()( { // SelfOptions getNumberOfNonZeroHarmonics: () => levelNumber, - statusBarMessageProperty: new PatternStringProperty( FourierMakingWavesStrings.matchUsingNHarmonicsStringProperty, { - levelNumber: levelNumber, - numberOfHarmonics: levelNumber - }, { tandem: Tandem.OPT_OUT } ), - - infoDialogDescriptionProperty: new PatternStringProperty( FourierMakingWavesStrings.infoNHarmonicsStringProperty, { - levelNumber: levelNumber, - numberOfHarmonics: levelNumber - }, { tandem: Tandem.OPT_OUT } ), - + // PhetioObjectOptions phetioType: WaveGameLevel.WaveGameLevelIO, phetioState: false }, providedOptions ); @@ -141,6 +132,24 @@ export default class WaveGameLevel extends PhetioObject { assert && assert( Number.isInteger( options.defaultNumberOfAmplitudeControls ) && options.defaultNumberOfAmplitudeControls >= 0 ); assert && assert( options.defaultNumberOfAmplitudeControls >= levelNumber && options.defaultNumberOfAmplitudeControls <= FMWConstants.MAX_HARMONICS ); + if ( !options.statusBarMessageProperty ) { + options.statusBarMessageProperty = new PatternStringProperty( FourierMakingWavesStrings.matchUsingNHarmonicsStringProperty, { + levelNumber: levelNumber, + numberOfHarmonics: levelNumber + }, { + tandem: options.tandem.createTandem( 'statusBarMessageProperty' ) + } ); + } + + if ( !options.infoDialogDescriptionProperty ) { + options.infoDialogDescriptionProperty = new PatternStringProperty( FourierMakingWavesStrings.infoNHarmonicsStringProperty, { + levelNumber: levelNumber, + numberOfHarmonics: levelNumber + }, { + tandem: options.tandem.createTandem( 'infoDialogDescriptionProperty' ) + } ); + } + super( options ); this.levelNumber = levelNumber; diff --git a/js/waveGame/model/WaveGameModel.ts b/js/waveGame/model/WaveGameModel.ts index 6dbc74b0..ea12b7ad 100644 --- a/js/waveGame/model/WaveGameModel.ts +++ b/js/waveGame/model/WaveGameModel.ts @@ -33,6 +33,8 @@ export default class WaveGameModel implements TModel { this.rewardScore = FMWQueryParameters.rewardScore; + const level5Tandem = tandem.createTandem( 'level5' ); + // There's some duplication of level number constants here. But the specification for levels changed SO many times, // that this brute force initialization ended up being easier to change and maintain. So I'm willing to make a // trade-off here, sacrificing some duplication for a more straightforward implementation. @@ -71,12 +73,16 @@ export default class WaveGameModel implements TModel { statusBarMessageProperty: new PatternStringProperty( FourierMakingWavesStrings.matchUsingNOrMoreHarmonicsStringProperty, { levelNumber: 5, numberOfHarmonics: 5 - }, { tandem: Tandem.OPT_OUT } ), + }, { + tandem: level5Tandem.createTandem( 'statusBarMessageProperty' ) + } ), infoDialogDescriptionProperty: new PatternStringProperty( FourierMakingWavesStrings.infoNOrMoreHarmonicsStringProperty, { levelNumber: 5, numberOfHarmonics: 5 - }, { tandem: Tandem.OPT_OUT } ), - tandem: tandem.createTandem( 'level5' ) + }, { + tandem: level5Tandem.createTandem( 'infoDialogDescriptionProperty' ) + } ), + tandem: level5Tandem } ) ]; assert && assert( this.levels.length === FMWConstants.NUMBER_OF_GAME_LEVELS ); diff --git a/js/wavepacket/view/ComponentSpacingToolCheckbox.ts b/js/wavepacket/view/ComponentSpacingToolCheckbox.ts index 5b7094a9..23bdb16e 100644 --- a/js/wavepacket/view/ComponentSpacingToolCheckbox.ts +++ b/js/wavepacket/view/ComponentSpacingToolCheckbox.ts @@ -7,27 +7,20 @@ * @author Chris Malley (PixelZoom, Inc.) */ -import DerivedProperty from '../../../../axon/js/DerivedProperty.js'; import FMWColors from '../../common/FMWColors.js'; -import FMWSymbols from '../../common/FMWSymbols.js'; import fourierMakingWaves from '../../fourierMakingWaves.js'; import CaliperCheckbox from './CaliperCheckbox.js'; import EnumerationProperty from '../../../../axon/js/EnumerationProperty.js'; import Domain from '../../common/model/Domain.js'; import Property from '../../../../axon/js/Property.js'; import Tandem from '../../../../tandem/js/Tandem.js'; +import FMWDerivedStrings from '../../common/FMWDerivedStrings.js'; export default class ComponentSpacingToolCheckbox extends CaliperCheckbox { public constructor( visibleProperty: Property, domainProperty: EnumerationProperty, tandem: Tandem ) { - const spaceSymbolStringProperty = new DerivedProperty( [ FMWSymbols.kStringProperty ], - k => `${k}1` ); - - const timeSymbolStringProperty = new DerivedProperty( [ FMWSymbols.omegaStringProperty ], - omega => `${omega}1` ); - - super( visibleProperty, domainProperty, spaceSymbolStringProperty, timeSymbolStringProperty, { + super( visibleProperty, domainProperty, FMWDerivedStrings.k1StringProperty, FMWDerivedStrings.omega1StringProperty, { calipersNodeOptions: { pathOptions: { fill: FMWColors.componentSpacingToolFillProperty diff --git a/js/wavepacket/view/ComponentSpacingToolNode.ts b/js/wavepacket/view/ComponentSpacingToolNode.ts index 6b2a0cb9..41fd9c86 100644 --- a/js/wavepacket/view/ComponentSpacingToolNode.ts +++ b/js/wavepacket/view/ComponentSpacingToolNode.ts @@ -7,9 +7,7 @@ * @author Chris Malley (PixelZoom, Inc.) */ -import DerivedProperty from '../../../../axon/js/DerivedProperty.js'; import FMWColors from '../../common/FMWColors.js'; -import FMWSymbols from '../../common/FMWSymbols.js'; import fourierMakingWaves from '../../fourierMakingWaves.js'; import WavePacketMeasurementToolNode, { WavePacketMeasurementToolNodeOptions } from './WavePacketMeasurementToolNode.js'; import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js'; @@ -18,6 +16,7 @@ import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js'; import ChartTransform from '../../../../bamboo/js/ChartTransform.js'; import EnumerationProperty from '../../../../axon/js/EnumerationProperty.js'; import Domain from '../../common/model/Domain.js'; +import FMWDerivedStrings from '../../common/FMWDerivedStrings.js'; type SelfOptions = EmptySelfOptions; @@ -35,10 +34,8 @@ export default class ComponentSpacingToolNode extends WavePacketMeasurementToolN // WavePacketMeasurementToolNodeOptions fill: FMWColors.componentSpacingToolFillProperty, - spaceSymbolStringProperty: new DerivedProperty( [ FMWSymbols.kStringProperty ], - k => `${k}1` ), - timeSymbolStringProperty: new DerivedProperty( [ FMWSymbols.omegaStringProperty ], - omega => `${omega}1` ) + spaceSymbolStringProperty: FMWDerivedStrings.k1StringProperty, + timeSymbolStringProperty: FMWDerivedStrings.omega1StringProperty }, providedOptions ); super( componentSpacingProperty, chartTransform, domainProperty, options ); diff --git a/js/wavepacket/view/WavePacketInfoDialog.ts b/js/wavepacket/view/WavePacketInfoDialog.ts index a49004df..3c0e2b62 100644 --- a/js/wavepacket/view/WavePacketInfoDialog.ts +++ b/js/wavepacket/view/WavePacketInfoDialog.ts @@ -7,14 +7,13 @@ */ import DerivedProperty from '../../../../axon/js/DerivedProperty.js'; -import PatternStringProperty from '../../../../axon/js/PatternStringProperty.js'; import { RichText, Text } from '../../../../scenery/js/imports.js'; import Dialog from '../../../../sun/js/Dialog.js'; import FMWConstants from '../../common/FMWConstants.js'; -import FMWSymbols from '../../common/FMWSymbols.js'; import fourierMakingWaves from '../../fourierMakingWaves.js'; import FourierMakingWavesStrings from '../../FourierMakingWavesStrings.js'; import Tandem from '../../../../tandem/js/Tandem.js'; +import FMWDerivedStrings from '../../common/FMWDerivedStrings.js'; // constants const MAX_WIDTH = 800; // determined empirically @@ -30,33 +29,15 @@ export default class WavePacketInfoDialog extends Dialog { // For each translated string describing a symbol, fill in the symbol. const stringProperties = [ - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.AStringProperty, { - A: FMWSymbols.AStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.lambdaStringProperty, { - lambda: FMWSymbols.lambdaStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.kStringProperty, { - k: FMWSymbols.kStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.sigmaStringProperty, { - sigma: FMWSymbols.sigmaStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.nStringProperty, { - n: FMWSymbols.nStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.tStringProperty, { - t: FMWSymbols.tStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.TStringProperty, { - T: FMWSymbols.TStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.omegaStringProperty, { - omega: FMWSymbols.omegaStringProperty - }, { tandem: Tandem.OPT_OUT } ), - new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.xStringProperty, { - x: FMWSymbols.xStringProperty - }, { tandem: Tandem.OPT_OUT } ) + FMWDerivedStrings.ADescriptionStringProperty, + FMWDerivedStrings.lambdaDescriptionStringProperty, + FMWDerivedStrings.kDescriptionStringProperty, + FMWDerivedStrings.sigmaDescriptionStringProperty, + FMWDerivedStrings.nDescriptionStringProperty, + FMWDerivedStrings.tDescriptionStringProperty, + FMWDerivedStrings.TDescriptionStringProperty, + FMWDerivedStrings.omegaDescriptionStringProperty, + FMWDerivedStrings.xDescriptionStringProperty ]; // Put a line break between each of the above strings.