Skip to content

Commit

Permalink
converted JS to TS, see #160
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Apr 14, 2022
1 parent 82bab3d commit c755036
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 46 deletions.
24 changes: 13 additions & 11 deletions js/SoundLevelEnum.ts
Original file line number Diff line number Diff line change
@@ -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;
tambo.register( 'SoundScope', SoundScope );
export default SoundScope;
24 changes: 0 additions & 24 deletions js/SoundScope.ts

This file was deleted.

18 changes: 7 additions & 11 deletions js/soundManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,7 +54,7 @@ type SoundGeneratorAwaitingAdd = {
// sound generator with its sonification level
type SoundGeneratorInfo = {
soundGenerator: SoundGenerator;
sonificationLevel: string;
sonificationLevel: SoundLevelEnum;
};

type SoundGeneratorInitializationOptions = {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 ) {
Expand Down

0 comments on commit c755036

Please sign in to comment.