Skip to content

Commit

Permalink
eliminate dependency on preference class or type in SecondLanguageCon…
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Dec 9, 2024
1 parent 953a627 commit f78cd73
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
12 changes: 9 additions & 3 deletions js/common/view/NumberSuiteCommonPreferencesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ export default class NumberSuiteCommonPreferencesNode extends HBox {
align: 'top'
}, providedOptions );

const secondLanguageControl = new SecondLanguageControl( preferences, preferences.allURL, utteranceQueue, {
visible: options.secondLanguageControlEnabled
} );
const secondLanguageControl = new SecondLanguageControl(
preferences.secondLocaleProperty,
preferences.secondVoiceProperty,
preferences.showSecondLocaleProperty,
preferences.isPrimaryLocaleProperty,
preferences.allURL,
utteranceQueue, {
visible: options.secondLanguageControlEnabled
} );

const showOnesControl = new ShowOnesControl( preferences.showLabOnesProperty, {
visible: NumberSuiteCommonPreferencesNode.hasScreenType( LabScreen )
Expand Down
36 changes: 11 additions & 25 deletions js/common/view/SecondLanguageControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,13 @@ import Property from '../../../../axon/js/Property.js';
type SelfOptions = EmptySelfOptions;
type SecondLanguageControlOptions = SelfOptions & StrictOmit<VBoxOptions, 'children'>;

export type SecondLanguageProperties = {
showSecondLocaleProperty: Property<boolean>;
isPrimaryLocaleProperty: Property<boolean>;
secondLocaleProperty: LocaleProperty;
secondVoiceProperty: Property<SpeechSynthesisVoice | null>;
};

export default class SecondLanguageControl extends VBox {

/**
* @param secondLanguageProperties
* @param allURL - URL to the {REPO}_all.html file for this simulation.
* @param utteranceQueue
* @param [providedOptions]
*/
public constructor( secondLanguageProperties: SecondLanguageProperties,
allURL: string,
public constructor( secondLocaleProperty: LocaleProperty,
secondVoiceProperty: Property<SpeechSynthesisVoice | null>,
showSecondLocaleProperty: Property<boolean>,
isPrimaryLocaleProperty: Property<boolean>,
allURL: string, // URL to the {REPO}_all.html file for this simulation.
utteranceQueue: NumberSuiteCommonUtteranceQueue,
providedOptions?: SecondLanguageControlOptions ) {

Expand All @@ -62,7 +52,7 @@ export default class SecondLanguageControl extends VBox {
const descriptionText = new Text( NumberSuiteCommonStrings.secondLanguageDescriptionStringProperty,
PreferencesDialogConstants.CONTROL_DESCRIPTION_OPTIONS );

const toggleSwitch = new ToggleSwitch( secondLanguageProperties.showSecondLocaleProperty, false, true,
const toggleSwitch = new ToggleSwitch( showSecondLocaleProperty, false, true,
PreferencesDialogConstants.TOGGLE_SWITCH_OPTIONS );

// Control for showing or hiding the languageAndVoiceControl
Expand All @@ -78,13 +68,9 @@ export default class SecondLanguageControl extends VBox {
const additionalDescriptionNode = new AdditionalDescriptionNode( !preferencesControl.enabled, allURL );

// Control for choosing a second language and associated voice
const languageAndVoiceControl = new LanguageAndVoiceControl(
secondLanguageProperties.secondLocaleProperty,
secondLanguageProperties.secondVoiceProperty,
utteranceQueue, {
visibleProperty: secondLanguageProperties.showSecondLocaleProperty
}
);
const languageAndVoiceControl = new LanguageAndVoiceControl( secondLocaleProperty, secondVoiceProperty, utteranceQueue, {
visibleProperty: showSecondLocaleProperty
} );

options.children = [
new VBox( {
Expand All @@ -98,9 +84,9 @@ export default class SecondLanguageControl extends VBox {
super( options );

// If we turn off the secondLocale, switch back to the primary locale.
secondLanguageProperties.showSecondLocaleProperty.lazyLink( showSecondLocale => {
showSecondLocaleProperty.lazyLink( showSecondLocale => {
if ( !showSecondLocale ) {
secondLanguageProperties.isPrimaryLocaleProperty.value = true;
isPrimaryLocaleProperty.value = true;

// When we turn off the second locale and switch back to the primary locale, if autoHear is on, the speechData
// is spoken in NumberCompare because it changed from a language change. For consistency with Number Play,
Expand Down

0 comments on commit f78cd73

Please sign in to comment.