From 738368cf54dd7ecfc0fec74e4896802dec3577be Mon Sep 17 00:00:00 2001 From: samreid Date: Sat, 29 Dec 2018 08:11:17 -0700 Subject: [PATCH] Pass scenes where appropriate and remove unused parameter, see https://github.com/phetsims/wave-interference/issues/286 --- js/common/view/LightWaveGeneratorNode.js | 11 ++++++----- js/common/view/SoundWaveGeneratorNode.js | 14 ++++++++------ js/common/view/WaterWaveGeneratorNode.js | 10 ++++++---- js/common/view/WaveGeneratorNode.js | 3 +-- js/waves/view/WavesScreenView.js | 15 ++++++++++----- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/js/common/view/LightWaveGeneratorNode.js b/js/common/view/LightWaveGeneratorNode.js index fe024732..865c43ec 100644 --- a/js/common/view/LightWaveGeneratorNode.js +++ b/js/common/view/LightWaveGeneratorNode.js @@ -11,6 +11,7 @@ define( require => { // modules const Dimension2 = require( 'DOT/Dimension2' ); const LaserPointerNode = require( 'SCENERY_PHET/LaserPointerNode' ); + const LightScene = require( 'WAVE_INTERFERENCE/common/model/LightScene' ); const WaveGeneratorNode = require( 'WAVE_INTERFERENCE/common/view/WaveGeneratorNode' ); const waveInterference = require( 'WAVE_INTERFERENCE/waveInterference' ); @@ -25,16 +26,16 @@ define( require => { class LightWaveGeneratorNode extends WaveGeneratorNode { /** - * @param {WavesModel} model + * @param {LightScene} lightScene * @param {Node} waveAreaNode - for bounds * @param {boolean} isPrimarySource */ - constructor( model, waveAreaNode, isPrimarySource ) { - const scene = model.lightScene; - const laserPointerNode = new LaserPointerNode( scene.button1PressedProperty, _.extend( { + constructor( lightScene, waveAreaNode, isPrimarySource ) { + assert && assert( lightScene instanceof LightScene, 'lightScene should be an instance of SoundScene' ); + const laserPointerNode = new LaserPointerNode( lightScene.button1PressedProperty, _.extend( { rightCenter: waveAreaNode.leftCenter.plusXY( 20, 0 ) }, DEFAULT_OPTIONS ) ); - super( model, scene, waveAreaNode, 70, isPrimarySource, laserPointerNode ); + super( lightScene, waveAreaNode, 70, isPrimarySource, laserPointerNode ); } } diff --git a/js/common/view/SoundWaveGeneratorNode.js b/js/common/view/SoundWaveGeneratorNode.js index 5c09194a..c0f36512 100644 --- a/js/common/view/SoundWaveGeneratorNode.js +++ b/js/common/view/SoundWaveGeneratorNode.js @@ -10,6 +10,7 @@ define( require => { // modules const Image = require( 'SCENERY/nodes/Image' ); + const SoundScene = require( 'WAVE_INTERFERENCE/common/model/SoundScene' ); const Util = require( 'DOT/Util' ); const WaveGeneratorNode = require( 'WAVE_INTERFERENCE/common/view/WaveGeneratorNode' ); const waveInterference = require( 'WAVE_INTERFERENCE/waveInterference' ); @@ -65,21 +66,22 @@ define( require => { class SoundWaveGeneratorNode extends WaveGeneratorNode { /** - * @param {WavesModel} model + * @param {SoundScene} soundScene * @param {Node} waveAreaNode - for bounds * @param {boolean} isPrimarySource */ - constructor( model, waveAreaNode, isPrimarySource ) { + constructor( soundScene, waveAreaNode, isPrimarySource ) { + assert && assert( soundScene instanceof SoundScene, 'soundScene should be an instance of SoundScene' ); const image = new Image( speakerImageMID, { rightCenter: waveAreaNode.leftCenter.plusXY( 20, 0 ), scale: 0.75 } ); - super( model, model.soundScene, waveAreaNode, 42, isPrimarySource, image ); - const modelProperty = isPrimarySource ? model.soundScene.oscillator1Property : - model.soundScene.oscillator2Property; + super( soundScene, waveAreaNode, 42, isPrimarySource, image ); + const modelProperty = isPrimarySource ? soundScene.oscillator1Property : + soundScene.oscillator2Property; modelProperty.link( oscillator1 => { - const max = model.soundScene.amplitudeProperty.range.max; + const max = soundScene.amplitudeProperty.range.max; // Sign is chosen so that the membrane forward corresponds to a high pressure outside the speaker, // see https://github.com/phetsims/wave-interference/issues/178 diff --git a/js/common/view/WaterWaveGeneratorNode.js b/js/common/view/WaterWaveGeneratorNode.js index 672a8c2c..d5430f18 100644 --- a/js/common/view/WaterWaveGeneratorNode.js +++ b/js/common/view/WaterWaveGeneratorNode.js @@ -14,6 +14,7 @@ define( require => { const BooleanProperty = require( 'AXON/BooleanProperty' ); const FaucetNode = require( 'SCENERY_PHET/FaucetNode' ); const NumberProperty = require( 'AXON/NumberProperty' ); + const WaterScene = require( 'WAVE_INTERFERENCE/common/model/WaterScene' ); const WaveGeneratorNode = require( 'WAVE_INTERFERENCE/common/view/WaveGeneratorNode' ); const waveInterference = require( 'WAVE_INTERFERENCE/waveInterference' ); const WaveInterferenceUtils = require( 'WAVE_INTERFERENCE/common/WaveInterferenceUtils' ); @@ -26,11 +27,12 @@ define( require => { class WaterWaveGeneratorNode extends WaveGeneratorNode { /** - * @param {WavesModel} model + * @param {WaterScene} waterScene * @param {Node} waveAreaNode - for bounds * @param {boolean} isPrimarySource */ - constructor( model, waveAreaNode, isPrimarySource ) { + constructor( waterScene, waveAreaNode, isPrimarySource ) { + assert && assert( waterScene instanceof WaterScene, 'waterScene should be an instance of WaterScene' ); const faucetNode = new FaucetNode( // This value for maxFlowRate is irrelevant because we use our own faucet water emitting model, @@ -46,7 +48,7 @@ define( require => { // Adjusted based on the dimension of the faucet image to align with the horizontal water drop location. // The vertical offset is adjusted with FAUCET_VERTICAL_OFFSET - x: WaveInterferenceUtils.getWaterDropX( model.waterScene.lattice.visibleBounds, waveAreaNode.bounds ), + x: WaveInterferenceUtils.getWaterDropX( waterScene.lattice.visibleBounds, waveAreaNode.bounds ), scale: 0.25, horizontalPipeLength: 1600, // Long enough that it still shows even for extreme aspect ratios @@ -54,7 +56,7 @@ define( require => { rasterizeHorizontalPipeNode: true } ); - super( model, model.waterScene, waveAreaNode, 62, isPrimarySource, faucetNode, FAUCET_VERTICAL_OFFSET, -7, true ); + super( waterScene, waveAreaNode, 62, isPrimarySource, faucetNode, FAUCET_VERTICAL_OFFSET, -7, true ); } } diff --git a/js/common/view/WaveGeneratorNode.js b/js/common/view/WaveGeneratorNode.js index 7b8c5123..3ecd0bea 100644 --- a/js/common/view/WaveGeneratorNode.js +++ b/js/common/view/WaveGeneratorNode.js @@ -21,7 +21,6 @@ define( require => { class WaveGeneratorNode extends Node { /** - * @param {WavesModel} model * @param {Scene} scene * @param {Node} waveAreaNode - for bounds * @param {number} buttonPosition - x offset @@ -31,7 +30,7 @@ define( require => { * @param {number} [buttonOffset] - offset for the button, so it can be positioned on the pipe * @param {boolean} [showButtonBackground] - true if a new background for the button should be added */ - constructor( model, scene, waveAreaNode, buttonPosition, isPrimarySource, sourceNode, + constructor( scene, waveAreaNode, buttonPosition, isPrimarySource, sourceNode, verticalOffset = 0, buttonOffset = 0, showButtonBackground = false ) { diff --git a/js/waves/view/WavesScreenView.js b/js/waves/view/WavesScreenView.js index 6dc02416..cc6c645f 100644 --- a/js/waves/view/WavesScreenView.js +++ b/js/waves/view/WavesScreenView.js @@ -450,11 +450,16 @@ define( require => { * Creates a ToggleNode that shows the primary or secondary source * @param {boolean} isPrimarySource - true if it should show the primary source */ - const createWaveGeneratorToggleNode = isPrimarySource => new ToggleNode( model.sceneProperty, [ - { value: model.waterScene, node: new WaterWaveGeneratorNode( model, this.waveAreaNode, isPrimarySource ) }, - { value: model.soundScene, node: new SoundWaveGeneratorNode( model, this.waveAreaNode, isPrimarySource ) }, - { value: model.lightScene, node: new LightWaveGeneratorNode( model, this.waveAreaNode, isPrimarySource ) } - ], { + const createWaveGeneratorToggleNode = isPrimarySource => new ToggleNode( model.sceneProperty, [ { + value: model.waterScene, + node: new WaterWaveGeneratorNode( model.waterScene, this.waveAreaNode, isPrimarySource ) + }, { + value: model.soundScene, + node: new SoundWaveGeneratorNode( model.soundScene, this.waveAreaNode, isPrimarySource ) + }, { + value: model.lightScene, + node: new LightWaveGeneratorNode( model.lightScene, this.waveAreaNode, isPrimarySource ) + } ], { alignChildren: ToggleNode.NONE } );