Skip to content

Commit

Permalink
make the dropper have a fixed position, #323
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Feb 1, 2023
1 parent 1dfc0ae commit f18b794
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
3 changes: 1 addition & 2 deletions js/concentration/model/ConcentrationModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ export default class ConcentrationModel implements TModel {
} );

this.dropper = new Dropper( this.soluteProperty, this.soluteFormProperty, {
position: new Vector2( this.beaker.position.x, 225 ),
dragBounds: new Bounds2( 260, 225, 580, 225 ),
position: new Vector2( 410, 225 ),
maxFlowRate: DROPPER_FLOW_RATE,
tandem: tandem.createTandem( 'dropper' )
} );
Expand Down
21 changes: 12 additions & 9 deletions js/concentration/model/Dropper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@ import NumberProperty from '../../../../axon/js/NumberProperty.js';
import Property from '../../../../axon/js/Property.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import Range from '../../../../dot/js/Range.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import optionize from '../../../../phet-core/js/optionize.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import PhetioObject, { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import BooleanIO from '../../../../tandem/js/types/BooleanIO.js';
import beersLawLab from '../../beersLawLab.js';
import BLLMovable, { BLLMovableOptions } from '../../common/model/BLLMovable.js';
import Solute from '../../common/model/Solute.js';
import SoluteForm from './SoluteForm.js';

type SelfOptions = {
position?: Vector2;
maxFlowRate?: number; // L/s
visible?: boolean;
};

type DropperOptions = SelfOptions & BLLMovableOptions;
type DropperOptions = SelfOptions & PickRequired<PhetioObjectOptions, 'tandem'>;

export default class Dropper extends BLLMovable {
export default class Dropper extends PhetioObject {

public readonly position: Vector2;
public readonly soluteProperty: Property<Solute>;
public readonly visibleProperty: TReadOnlyProperty<boolean>;
public readonly enabledProperty: Property<boolean>;
Expand All @@ -39,18 +42,19 @@ export default class Dropper extends BLLMovable {
public constructor( soluteProperty: Property<Solute>, soluteFormProperty: EnumerationProperty<SoluteForm>,
providedOptions: DropperOptions ) {

const options = optionize<DropperOptions, SelfOptions, BLLMovableOptions>()( {
const options = optionize<DropperOptions, SelfOptions, PhetioObjectOptions>()( {

// SelfOptions
position: Vector2.ZERO,
maxFlowRate: 1,
visible: true,

// BLLMovableOptions
// PhetioObjectpOptions
phetioState: false
}, providedOptions );

super( options );

this.position = options.position;
this.soluteProperty = soluteProperty;

this.visibleProperty = new DerivedProperty( [ soluteFormProperty ],
Expand Down Expand Up @@ -117,8 +121,7 @@ export default class Dropper extends BLLMovable {
super.dispose();
}

public override reset(): void {
super.reset();
public reset(): void {
this.isDispensingProperty.reset();
this.enabledProperty.reset();
this.isEmptyProperty.reset();
Expand Down
17 changes: 3 additions & 14 deletions js/concentration/view/BLLDropperNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import ModelViewTransform2 from '../../../../phetcommon/js/view/ModelViewTransform2.js';
import EyeDropperNode, { EyeDropperNodeOptions } from '../../../../scenery-phet/js/EyeDropperNode.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import { DragListener, Path, RichText } from '../../../../scenery/js/imports.js';
import { Path, RichText } from '../../../../scenery/js/imports.js';
import beersLawLab from '../../beersLawLab.js';
import Solute from '../../common/model/Solute.js';
import Solvent from '../../common/model/Solvent.js';
Expand Down Expand Up @@ -64,9 +64,7 @@ export default class BLLDropperNode extends EyeDropperNode {
this.addChild( labelText );

// position
dropper.positionProperty.link( position => {
this.translation = modelViewTransform.modelToViewPosition( position );
} );
this.translation = modelViewTransform.modelToViewPosition( dropper.position );

// Position the label on the dropper, and resize it's translucent background to fit.
labelText.boundsProperty.link( () => {
Expand All @@ -92,17 +90,8 @@ export default class BLLDropperNode extends EyeDropperNode {
// dilate touch area
this.touchArea = this.localBounds.dilatedX( 0.25 * this.width );

// move the dropper
const dragListener = new DragListener( {
positionProperty: dropper.positionProperty,
dragBoundsProperty: new Property( dropper.dragBounds ),
transform: modelViewTransform,
tandem: options.tandem.createTandem( 'dragListener' )
} );
this.addInputListener( dragListener );

this.addLinkedElement( dropper, {
tandem: options.tandem.createTandem( 'dropper' )
tandem: options.tandem.createTandem( dropper.tandem.name )
} );
}

Expand Down
5 changes: 2 additions & 3 deletions js/concentration/view/StockSolutionNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ export default class StockSolutionNode extends Rectangle {

// path
if ( dropper.isDispensingProperty.value && !dropper.isEmptyProperty.value ) {
this.setRect( -tipWidth / 2, 0, tipWidth, beaker.position.y - dropper.positionProperty.value.y );
this.setRect( -tipWidth / 2, 0, tipWidth, beaker.position.y - dropper.position.y );
}
else {
this.setRect( 0, 0, 0, 0 );
}

// move this node to the dropper's position
this.translation = modelViewTransform.modelToViewPosition( dropper.positionProperty.value );
this.translation = modelViewTransform.modelToViewPosition( dropper.position );
};
dropper.positionProperty.link( updateShapeAndPosition );
dropper.isDispensingProperty.link( updateShapeAndPosition );
dropper.isEmptyProperty.link( updateShapeAndPosition );

Expand Down

0 comments on commit f18b794

Please sign in to comment.