Skip to content

Commit

Permalink
Pass scenes where appropriate and remove unused parameter, see #286
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Dec 29, 2018
1 parent 1e2e676 commit 738368c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
11 changes: 6 additions & 5 deletions js/common/view/LightWaveGeneratorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

Expand All @@ -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 );
}
}

Expand Down
14 changes: 8 additions & 6 deletions js/common/view/SoundWaveGeneratorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions js/common/view/WaterWaveGeneratorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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,
Expand All @@ -46,15 +48,15 @@ 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

// Overcome a flickering problems, see https://github.com/phetsims/wave-interference/issues/187
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 );
}
}

Expand Down
3 changes: 1 addition & 2 deletions js/common/view/WaveGeneratorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ) {
Expand Down
15 changes: 10 additions & 5 deletions js/waves/view/WavesScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
} );

Expand Down

0 comments on commit 738368c

Please sign in to comment.