Skip to content

Commit

Permalink
create NumberPairsPreferences, add initial Property values to NumberP…
Browse files Browse the repository at this point in the history
…airsQueryParameters, #22
  • Loading branch information
pixelzoom committed Dec 3, 2024
1 parent c60c5d8 commit 6ef8a6c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
11 changes: 9 additions & 2 deletions js/common/NumberPairsQueryParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ import logGlobal from '../../../phet-core/js/logGlobal.js';
import numberPairs from '../numberPairs.js';

const SCHEMA_MAP = {
//TODO add schemas for query parameters
};

// Specifies a second locale for the speech synthesis feature.
// Values are a locale code, e.g. "en" or "zh_CN". null means no second locale.
secondLocale: {
public: true,
type: 'string',
defaultValue: null
}
} as const;

const NumberPairsQueryParameters = QueryStringMachine.getAll( SCHEMA_MAP );

Expand Down
61 changes: 61 additions & 0 deletions js/common/model/NumberPairsPreferences.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2024, University of Colorado Boulder

/**
* NumberPairsPreferences is the model for sim-specific preferences, accessed via the Preferences dialog.
* These preferences are global, affect all screens, and are not affected by 'reset all'.
*
* @author Chris Malley (PixelZoom, Inc.)
*/

import numberPairs from '../../numberPairs.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import localeProperty, { Locale, LocaleProperty } from '../../../../joist/js/i18n/localeProperty.js';
import Property from '../../../../axon/js/Property.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import NumberPairsQueryParameters from '../NumberPairsQueryParameters.js';
import Tandem from '../../../../tandem/js/Tandem.js';

//TODO https://github.com/phetsims/number-pairs/issues/22 second or secondary? Other sims in the suite are very inconsistent.

// As with the primary locale, use initialize-globals checkAndRemapLocale() to check validity of the second locale.
// This potentially either falls back to 'en', or remaps from 3-character locales to PhET locales.
let secondLocale = NumberPairsQueryParameters.secondLocale;
if ( secondLocale !== null ) {
const remappedLocale = phet.chipper.remapLocale( secondLocale, false );
secondLocale = phet.chipper.getValidRuntimeLocale( remappedLocale );
}

const secondLocaleProperty = new LocaleProperty( secondLocale as Locale || localeProperty.value, {
tandem: Tandem.PREFERENCES.createTandem( 'secondLocaleProperty' ),
phetioFeatured: true
} );

const NumberPairsPreferences = {

// second locale
secondLocaleProperty: secondLocaleProperty,

// voice of the primary locale
//TODO https://github.com/phetsims/number-pairs/issues/22 Cannot instrument because there is no IOType for SpeechSynthesisVoice.
primaryVoiceProperty: new Property<SpeechSynthesisVoice | null>( null ),

// voice of the second locale
//TODO https://github.com/phetsims/number-pairs/issues/22 Cannot instrument because there is no IOType for SpeechSynthesisVoice.
secondVoiceProperty: new Property<SpeechSynthesisVoice | null>( null ),

//TODO https://github.com/phetsims/number-pairs/issues/22 Properties below here are global, but do not belong in Preferences.

// If a valid secondary locale was provided via a query parameter, display the secondary locale on sim startup.
showSecondLocaleProperty: new BooleanProperty( !!NumberPairsQueryParameters.secondLocale ),

// Whether the sim is using its primary locale or secondary locale on screens that support two locales.
isPrimaryLocaleProperty: new BooleanProperty( true ),

// Strings for the current secondLocale.
secondLocaleStringsProperty: new DerivedProperty( [ secondLocaleProperty ], secondLocale => {
return phet.chipper.strings[ secondLocale ];
} )
};

numberPairs.register( 'NumberPairsPreferences', NumberPairsPreferences );
export default NumberPairsPreferences;

0 comments on commit 6ef8a6c

Please sign in to comment.