Skip to content

Commit

Permalink
Convert options to typescript, #404
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Mar 28, 2022
1 parent 093efa5 commit a541301
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 27 deletions.
10 changes: 7 additions & 3 deletions js/common/view/BothHandsPDOMNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import CueArrowsState from './CueArrowsState.js';
import RatioDescriber from './describers/RatioDescriber.js';
import TickMarkView from './TickMarkView.js';
import EnumerationProperty from '../../../../axon/js/EnumerationProperty.js';
import IReadOnlyProperty from '../../../../axon/js/IReadOnlyProperty.js';

// constants
const OBJECT_RESPONSE_DELAY = 500;
Expand Down Expand Up @@ -70,8 +71,10 @@ class BothHandsPDOMNode extends Node {
private readonly contextResponseUtterance: Utterance;
private readonly ratioUnlockedFromBothHandsUtterance: Utterance;

// TODO: wish I know how to mark it as a @public (read-only) (but set internal to this file).https://github.com/phetsims/ratio-and-proportion/issues/404
isBeingInteractedWithProperty: Property<boolean>;
// Two references to the same Property allows for a public, readonly interface, while still editable in this file.
readonly isBeingInteractedWithProperty: IReadOnlyProperty<boolean>;
private readonly _isBeingInteractedWithProperty: Property<boolean>;

private readonly bothHandsInteractionListener: BothHandsInteractionListener;

constructor( providedOptions: BothHandsPDOMNodeOptions ) {
Expand Down Expand Up @@ -216,7 +219,8 @@ class BothHandsPDOMNode extends Node {
alertStableDelay: OBJECT_RESPONSE_DELAY + 10
} );

this.isBeingInteractedWithProperty = this.bothHandsInteractionListener.isBeingInteractedWithProperty;
this._isBeingInteractedWithProperty = this.bothHandsInteractionListener.isBeingInteractedWithProperty;
this.isBeingInteractedWithProperty = this._isBeingInteractedWithProperty;

// Though most cases are covered by just listening to fitness, there are certain cases when Property values can change,
// but the fitness doesn't. See https://github.com/phetsims/ratio-and-proportion/issues/222 as an example.
Expand Down
13 changes: 6 additions & 7 deletions js/common/view/sound/InProportionSoundGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import BooleanProperty from '../../../../../axon/js/BooleanProperty.js';
import DerivedProperty from '../../../../../axon/js/DerivedProperty.js';
import NumberProperty from '../../../../../axon/js/NumberProperty.js';
import merge from '../../../../../phet-core/js/merge.js';
import SoundClip from '../../../../../tambo/js/sound-generators/SoundClip.js';
import SoundClip, { SoundClipOptions } from '../../../../../tambo/js/sound-generators/SoundClip.js';
import inProportion_mp3 from '../../../../sounds/in-proportion/inProportion_mp3.js';
import ratioAndProportion from '../../../ratioAndProportion.js';
import RAPModel from '../../model/RAPModel.js';
import Property from '../../../../../axon/js/Property.js';
import IReadOnlyProperty from '../../../../../axon/js/IReadOnlyProperty.js';
import optionize from '../../../../../phet-core/js/optionize.js';

const SUCCESS_OUTPUT_LEVEL = 0.8;
const SILENT_LEVEL = 0;
Expand Down Expand Up @@ -60,14 +60,13 @@ class InProportionSoundGenerator extends SoundClip {
* @param model
* @param enabledControlProperty - not supposed to be settable, just listened to. NOTE: this is not simply
* an on/off Property for the SoundGenerator, see below.
* @param options
* @param providedOptions
*/
constructor( model: RAPModel, enabledControlProperty: Property<boolean>, options?: any ) {
constructor( model: RAPModel, enabledControlProperty: Property<boolean>, providedOptions?: SoundClipOptions ) {

// TODO: convert to optionize once SoundClip is typescript https://github.com/phetsims/ratio-and-proportion/issues/404
options = merge( {
const options = optionize<SoundClipOptions, {}>( {
initialOutputLevel: 0.5
}, options );
}, providedOptions );

assert && assert( !options.enableControlProperties, 'use the parameter instead, and note doc for difference in implementation' );

Expand Down
11 changes: 5 additions & 6 deletions js/common/view/sound/MovingInProportionSoundGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/

import Property from '../../../../../axon/js/Property.js';
import merge from '../../../../../phet-core/js/merge.js';
import optionize from '../../../../../phet-core/js/optionize.js';
import CompositeSoundClip from '../../../../../tambo/js/sound-generators/CompositeSoundClip.js';
import SoundGenerator from '../../../../../tambo/js/sound-generators/SoundGenerator.js';
import SoundGenerator, { SoundGeneratorOptions } from '../../../../../tambo/js/sound-generators/SoundGenerator.js';
import movingInProportionChoirLoop_mp3 from '../../../../sounds/moving-in-proportion/movingInProportionChoirLoop_mp3.js';
import movingInProportionOrganLoop_mp3 from '../../../../sounds/moving-in-proportion/movingInProportionOrganLoop_mp3.js';
import ratioAndProportion from '../../../ratioAndProportion.js';
Expand All @@ -20,12 +20,11 @@ class MovingInProportionSoundGenerator extends SoundGenerator {

private movingInProportionSoundClip: CompositeSoundClip;

constructor( model: RAPModel, options?: any ) {
constructor( model: RAPModel, providedOptions?: SoundGeneratorOptions ) {

// TODO: convert to optionize once SoundGenerator is typescript https://github.com/phetsims/ratio-and-proportion/issues/404
options = merge( {
const options = optionize<SoundGeneratorOptions, {}>( {
initialOutputLevel: 0.13
}, options );
}, providedOptions );

super( options );

Expand Down
11 changes: 5 additions & 6 deletions js/common/view/sound/StaccatoFrequencySoundGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import dotRandom from '../../../../../dot/js/dotRandom.js';
import Range from '../../../../../dot/js/Range.js';
import LinearFunction from '../../../../../dot/js/LinearFunction.js';
import merge from '../../../../../phet-core/js/merge.js';
import SoundClip from '../../../../../tambo/js/sound-generators/SoundClip.js';
import SoundGenerator from '../../../../../tambo/js/sound-generators/SoundGenerator.js';
import SoundGenerator, { SoundGeneratorOptions } from '../../../../../tambo/js/sound-generators/SoundGenerator.js';
import staccatoC_mp3 from '../../../../sounds/staccato/staccatoC_mp3.js';
import staccatoC001_mp3 from '../../../../sounds/staccato/staccatoC001_mp3.js';
import staccatoC002_mp3 from '../../../../sounds/staccato/staccatoC002_mp3.js';
Expand All @@ -39,6 +38,7 @@ import staccatoG001_mp3 from '../../../../sounds/staccato/staccatoG001_mp3.js';
import staccatoG002_mp3 from '../../../../sounds/staccato/staccatoG002_mp3.js';
import ratioAndProportion from '../../../ratioAndProportion.js';
import IReadOnlyProperty from '../../../../../axon/js/IReadOnlyProperty.js';
import optionize from '../../../../../phet-core/js/optionize.js';

// organize the sounds by variation and note
const staccatoSounds = [
Expand All @@ -65,12 +65,11 @@ class StaccatoFrequencySoundGenerator extends SoundGenerator {
// in ms, keep track of the amount of time that has passed since the last staccato sound played
private timeSinceLastPlay: number;

constructor( fitnessProperty: IReadOnlyProperty<number>, fitnessRange: Range, inProportionProperty: IReadOnlyProperty<boolean>, options: object ) {
constructor( fitnessProperty: IReadOnlyProperty<number>, fitnessRange: Range, inProportionProperty: IReadOnlyProperty<boolean>, providedOptions: SoundGeneratorOptions ) {

// TODO: convert to optionize once SoundGenerator is typescript https://github.com/phetsims/ratio-and-proportion/issues/404
options = merge( {
const options = optionize<SoundGeneratorOptions, {}>( {
initialOutputLevel: 0.25
}, options );
}, providedOptions );

super( options );

Expand Down
19 changes: 14 additions & 5 deletions js/common/view/sound/ViewSounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import DerivedProperty from '../../../../../axon/js/DerivedProperty.js';
import merge from '../../../../../phet-core/js/merge.js';
import SoundClip from '../../../../../tambo/js/sound-generators/SoundClip.js';
import SoundClip, { SoundClipOptions } from '../../../../../tambo/js/sound-generators/SoundClip.js';
import SoundLevelEnum from '../../../../../tambo/js/SoundLevelEnum.js';
import soundManager from '../../../../../tambo/js/soundManager.js';
import grab_mp3 from '../../../../../tambo/sounds/grab_mp3.js';
Expand All @@ -21,9 +21,19 @@ import BoundarySoundClip from './BoundarySoundClip.js';
import TickMarkBumpSoundClip from './TickMarkBumpSoundClip.js';
import Property from '../../../../../axon/js/Property.js';
import EnumerationProperty from '../../../../../axon/js/EnumerationProperty.js';
import optionize from '../../../../../phet-core/js/optionize.js';

const TOTAL_RANGE = rapConstants.TOTAL_RATIO_TERM_VALUE_RANGE;

type SelfOptions = {

// TODO: convert to optionize once SoundManager.addSoundGenerator is typescript https://github.com/phetsims/ratio-and-proportion/issues/404
addSoundOptions?: any;
soundClipOptions?: SoundClipOptions;
}

type ViewSoundsOptions = SelfOptions & {};

class ViewSounds {

readonly grabSoundClip: SoundClip;
Expand All @@ -32,17 +42,16 @@ class ViewSounds {
readonly tickMarkBumpSoundClip: TickMarkBumpSoundClip;

constructor( tickMarkRangeProperty: Property<number>, tickMarkViewProperty: EnumerationProperty<TickMarkView>,
playTickMarkBumpSoundProperty: Property<boolean>, options?: any ) {
playTickMarkBumpSoundProperty: Property<boolean>, providedOptions?: ViewSoundsOptions ) {

// TODO: convert to optionize once SoundClip is typescript https://github.com/phetsims/ratio-and-proportion/issues/404
options = merge( {
const options = optionize<ViewSoundsOptions>( {
addSoundOptions: {
categoryName: 'user-interface'
},
soundClipOptions: {
initialOutputLevel: 0.15
}
}, options );
}, providedOptions );

this.grabSoundClip = new SoundClip( grab_mp3, options.soundClipOptions );
this.releaseSoundClip = new SoundClip( release_mp3, options.soundClipOptions );
Expand Down

0 comments on commit a541301

Please sign in to comment.