Skip to content

Commit

Permalink
add temporary sound for faucet, #90, phetsims/scenery-phet#840
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Mar 5, 2024
1 parent edfc28e commit 1e5aaa4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion js/generator/view/WaterFaucetNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2024, University of Colorado Boulder

//TODO https://github.com/phetsims/scenery-phet/issues/840 When FaucetNode sound is completed, delete code identified by "TEMPORARY SOUND".
/**
* WaterFaucetNode is the water faucet used to power the generator.
*
Expand All @@ -10,9 +11,10 @@ import faradaysElectromagneticLab from '../../faradaysElectromagneticLab.js';
import FaucetNode, { FaucetNodeOptions } from '../../../../scenery-phet/js/FaucetNode.js';
import Property from '../../../../axon/js/Property.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import { NodeTranslationOptions } from '../../../../scenery/js/imports.js';
import { DragListener, NodeTranslationOptions } from '../../../../scenery/js/imports.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import WaterFaucet from '../model/WaterFaucet.js';
import ValueChangeSoundPlayer from '../../../../tambo/js/sound-generators/ValueChangeSoundPlayer.js';

type SelfOptions = EmptySelfOptions;

Expand All @@ -36,7 +38,28 @@ export default class WaterFaucetNode extends FaucetNode {
phetioVisiblePropertyInstrumented: false
}, providedOptions );

// TEMPORARY SOUND
const soundGenerator = new ValueChangeSoundPlayer( waterFaucet.flowRateProperty.range );

// TEMPORARY SOUND for keyboard drag. It's unclear why options.drag does not also apply to mouse/touch drag.
let previousValue = waterFaucet.flowRateProperty.value;
options.drag = event => {
if ( event.isFromPDOM() ) {
soundGenerator.playSoundForValueChange( waterFaucet.flowRateProperty.value, previousValue );
}
else {
soundGenerator.playSoundIfThresholdReached( waterFaucet.flowRateProperty.value, previousValue );
}
previousValue = waterFaucet.flowRateProperty.value;
};

super( waterFaucet.flowRateProperty.range.max, waterFaucet.flowRateProperty, new Property( true ), options );

// TEMPORARY SOUND mouse/touch drag. It's unclear why options.drag does not also handle this.
this.addInputListener( new DragListener( {
attach: false,
drag: ( event, listener ) => options.drag( event )
} ) );
}
}

Expand Down

0 comments on commit 1e5aaa4

Please sign in to comment.