From c755036d0485663abd58343f56bd234e34ad1392 Mon Sep 17 00:00:00 2001 From: jbphet Date: Thu, 14 Apr 2022 16:38:33 -0600 Subject: [PATCH] converted JS to TS, see https://github.com/phetsims/tambo/issues/160 --- js/SoundLevelEnum.ts | 24 +++++++++++++----------- js/SoundScope.ts | 24 ------------------------ js/soundManager.ts | 18 +++++++----------- 3 files changed, 20 insertions(+), 46 deletions(-) delete mode 100644 js/SoundScope.ts diff --git a/js/SoundLevelEnum.ts b/js/SoundLevelEnum.ts index 286f1e3f..035c6219 100644 --- a/js/SoundLevelEnum.ts +++ b/js/SoundLevelEnum.ts @@ -1,22 +1,24 @@ // Copyright 2018-2020, University of Colorado Boulder -// ts-nocheck - /** - * enum for the different sound level settings + * This enum is used to describe whether a sound is part of the "basic" sounds or the "enhanced" sounds. * * @author John Blanco (PhET Interactive Simulations) */ +import Enumeration from '../../phet-core/js/Enumeration.js'; +import EnumerationValue from '../../phet-core/js/EnumerationValue.js'; import tambo from './tambo.js'; -const SoundLevelEnum = { - BASIC: 'BASIC', - ENHANCED: 'ENHANCED' -}; +class SoundScope extends EnumerationValue { + static BASIC = new SoundScope(); + static ENHANCED = new SoundScope(); -// in development mode, catch any attempted changes to the enum -if ( assert ) { Object.freeze( SoundLevelEnum ); } + // Gets a list of keys, values and mapping between them. For use by EnumerationProperty and PhET-iO. + static enumeration = new Enumeration( SoundScope, { + phetioDocumentation: 'describes whether a sound is considered part of the basic or the enhanced sounds for the sim' + } ); +} -tambo.register( 'SoundLevelEnum', SoundLevelEnum ); -export default SoundLevelEnum; \ No newline at end of file +tambo.register( 'SoundScope', SoundScope ); +export default SoundScope; \ No newline at end of file diff --git a/js/SoundScope.ts b/js/SoundScope.ts deleted file mode 100644 index 0e4b805d..00000000 --- a/js/SoundScope.ts +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2022, University of Colorado Boulder - -/** - * This enum is used to describe whether a sound is part of the "basic" sounds or the "enhanced" sounds. - * - * @author John Blanco (PhET Interactive Simulations) - */ - -import Enumeration from '../../phet-core/js/Enumeration.js'; -import EnumerationValue from '../../phet-core/js/EnumerationValue.js'; -import tambo from './tambo.js'; - -class SoundScope extends EnumerationValue { - static BASIC = new SoundScope(); - static ENHANCED = new SoundScope(); - - // Gets a list of keys, values and mapping between them. For use by EnumerationProperty and PhET-iO. - static enumeration = new Enumeration( SoundScope, { - phetioDocumentation: 'describes whether a sound is considered part of the basic or the enhanced sounds for the sim' - } ); -} - -tambo.register( 'SoundScope', SoundScope ); -export default SoundScope; \ No newline at end of file diff --git a/js/soundManager.ts b/js/soundManager.ts index bfd0f535..65765934 100644 --- a/js/soundManager.ts +++ b/js/soundManager.ts @@ -33,8 +33,8 @@ import { PropertyLinkListener } from '../../axon/js/IReadOnlyProperty.js'; export type SoundGeneratorAddOptions = { // The 'sonification level' is used to determine whether a given sound should be enabled given the setting of the - // sonification level parameter for the sim. Valid values are 'BASIC' or 'ENHANCED'. - sonificationLevel?: string; + // sonification level parameter for the sim. + sonificationLevel?: SoundLevelEnum; // The associated view node is a Scenery node that, if provided, must be visible in the display for the sound // generator to be enabled. This is generally used only for sounds that can play for long durations, such as a @@ -54,7 +54,7 @@ type SoundGeneratorAwaitingAdd = { // sound generator with its sonification level type SoundGeneratorInfo = { soundGenerator: SoundGenerator; - sonificationLevel: string; + sonificationLevel: SoundLevelEnum; }; type SoundGeneratorInitializationOptions = { @@ -79,7 +79,7 @@ class SoundManager extends PhetioObject { public readonly enhancedSoundEnabledProperty: BooleanProperty; // an array where the sound generators are stored along with information about how to manage them - private soundGeneratorInfoArray: SoundGeneratorInfo[]; + private readonly soundGeneratorInfoArray: SoundGeneratorInfo[]; // output level for the master gain node when sonification is enabled private _masterOutputLevel: number; @@ -591,18 +591,14 @@ class SoundManager extends PhetioObject { return this.enabledProperty.value; } - public set sonificationLevel( sonificationLevel: string ) { - assert && assert( - _.includes( _.values( SoundLevelEnum ), sonificationLevel ), - `invalid sonification level: ${sonificationLevel}` - ); + public set sonificationLevel( sonificationLevel: SoundLevelEnum ) { this.enhancedSoundEnabledProperty.value = sonificationLevel === SoundLevelEnum.ENHANCED; } /** * ES5 getter for sonification level */ - public get sonificationLevel(): string { + public get sonificationLevel(): SoundLevelEnum { return this.enhancedSoundEnabledProperty.value ? SoundLevelEnum.ENHANCED : SoundLevelEnum.BASIC; } @@ -652,7 +648,7 @@ class SoundManager extends PhetioObject { /** * Log the value of the reverb gain as it changes, used primarily for debug. - * @param {number} duration - duration for logging, in seconds + * @param duration - duration for logging, in seconds */ public logReverbGain( duration: number ) { if ( this.reverbGainNode ) {