Skip to content

Commit

Permalink
maxRayLength:500 for Generator screen, #66
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed May 7, 2024
1 parent 4f47ef1 commit cfbf116
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
42 changes: 29 additions & 13 deletions js/common/view/FELLightBulbNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import faradaysElectromagneticLab from '../../faradaysElectromagneticLab.js';
import { Image, Node } from '../../../../scenery/js/imports.js';
import { Image, Node, NodeOptions } from '../../../../scenery/js/imports.js';
import LightBulb from '../model/LightBulb.js';
import LightBulbNode from '../../../../scenery-phet/js/LightBulbNode.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
Expand All @@ -18,13 +18,35 @@ import ShadedRectangle from '../../../../scenery-phet/js/ShadedRectangle.js';
import Bounds2 from '../../../../dot/js/Bounds2.js';
import FELColors from '../FELColors.js';
import BooleanIO from '../../../../tandem/js/types/BooleanIO.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import CurrentIndicator from '../model/CurrentIndicator.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import optionize from '../../../../phet-core/js/optionize.js';

type SelfOptions = {
maxRayLength?: number; // passed to LightBulbNode
};

type FELLightBulbNodeOptions = SelfOptions & PickRequired<NodeOptions, 'tandem'>;

export default class FELLightBulbNode extends Node {

public constructor( lightBulb: LightBulb, currentIndicatorProperty: TReadOnlyProperty<CurrentIndicator>, tandem: Tandem ) {
public constructor( lightBulb: LightBulb,
currentIndicatorProperty: TReadOnlyProperty<CurrentIndicator>,
providedOptions: FELLightBulbNodeOptions ) {

const options = optionize<FELLightBulbNodeOptions, SelfOptions, NodeOptions>()( {

// SelfOptions
maxRayLength: 350,

// NodeOptions
visibleProperty: new DerivedProperty( [ currentIndicatorProperty ], indicator => ( indicator === lightBulb ), {
tandem: providedOptions.tandem.createTandem( 'visibleProperty' ),
phetioValueType: BooleanIO
} ),
phetioFeatured: true
}, providedOptions );

const baseNode = new ShadedRectangle( new Bounds2( 0, 0, 150, 20 ), {
baseColor: FELColors.lightBulbBaseColorProperty,
Expand All @@ -47,7 +69,7 @@ export default class FELLightBulbNode extends Node {
minRays: 20,
maxRays: 20,
minRayLength: 0,
maxRayLength: 350,
maxRayLength: options.maxRayLength,
longRayLineWidth: 2,
mediumRayLineWidth: 2,
shortRayLineWidth: 1,
Expand All @@ -60,15 +82,9 @@ export default class FELLightBulbNode extends Node {
bottom: socketNode.top + 18
} );

super( {
children: [ bulbNode, socketNode, baseNode ],
visibleProperty: new DerivedProperty( [ currentIndicatorProperty ], indicator => ( indicator === lightBulb ), {
tandem: tandem.createTandem( 'visibleProperty' ),
phetioValueType: BooleanIO
} ),
tandem: tandem,
phetioFeatured: true
} );
options.children = [ bulbNode, socketNode, baseNode ];

super( options );

this.addLinkedElement( lightBulb );
}
Expand Down
16 changes: 11 additions & 5 deletions js/common/view/PickupCoilNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import { Node, NodeOptions } from '../../../../scenery/js/imports.js';
import PickupCoilSamplePointsNode from './PickupCoilSamplePointsNode.js';
import FELLightBulbNode from './FELLightBulbNode.js';
import VoltmeterNode from './VoltmeterNode.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import optionize from '../../../../phet-core/js/optionize.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import PickOptional from '../../../../phet-core/js/types/PickOptional.js';
import PickupCoilAreaNode from './PickupCoilAreaNode.js';

type SelfOptions = EmptySelfOptions;
type SelfOptions = {
maxRayLength?: number; // passed to LightBulbNode
};

type PickupCoilNodeOptions = SelfOptions &
PickOptional<FELMovableNodeOptions, 'isMovable' | 'dragBoundsProperty'> &
Expand All @@ -34,7 +36,9 @@ export default class PickupCoilNode extends FELMovableNode {

public constructor( pickupCoil: PickupCoil, providedOptions: PickupCoilNodeOptions ) {

const options = optionize<PickupCoilNodeOptions, SelfOptions, NodeOptions>()( {}, providedOptions );
const options = optionize<PickupCoilNodeOptions, SelfOptions, NodeOptions>()( {
maxRayLength: 350
}, providedOptions );

const coilNode = new CoilNode( pickupCoil.coil, pickupCoil, {
dragBoundsProperty: options.dragBoundsProperty,
Expand All @@ -45,8 +49,10 @@ export default class PickupCoilNode extends FELMovableNode {
const areaNode = new PickupCoilAreaNode( pickupCoil );
const samplePointsNode = new PickupCoilSamplePointsNode( pickupCoil );

const lightBulbNode = new FELLightBulbNode( pickupCoil.lightBulb, pickupCoil.currentIndicatorProperty,
options.tandem.createTandem( 'lightBulbNode' ) );
const lightBulbNode = new FELLightBulbNode( pickupCoil.lightBulb, pickupCoil.currentIndicatorProperty, {
maxRayLength: options.maxRayLength,
tandem: options.tandem.createTandem( 'lightBulbNode' )
} );

const voltmeterNode = new VoltmeterNode( pickupCoil.voltmeter, pickupCoil.currentIndicatorProperty,
coilNode.boundsProperty, options.tandem.createTandem( 'voltmeterNode' ) );
Expand Down
1 change: 1 addition & 0 deletions js/generator/view/GeneratorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class GeneratorNode extends Node {

const pickupCoilNode = new PickupCoilNode( generator.pickupCoil, {
isMovable: false, // pickupCoilNode is not movable in this screen.
maxRayLength: 500, // see https://github.com/phetsims/faradays-electromagnetic-lab/issues/66#issuecomment-2088698150
tandem: tandem.createTandem( 'pickupCoilNode' )
} );

Expand Down

0 comments on commit cfbf116

Please sign in to comment.