Skip to content

Commit

Permalink
delete model.dropper.positionProperty and view.dropperNode.dragListen…
Browse files Browse the repository at this point in the history
…er, #270

(cherry picked from commit 2729be5)
  • Loading branch information
pixelzoom authored and zepumph committed Jan 27, 2023
1 parent 24bb774 commit ecde0f2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 51 deletions.
25 changes: 10 additions & 15 deletions js/common/model/Dropper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';
import Property from '../../../../axon/js/Property.js';
import Bounds2 from '../../../../dot/js/Bounds2.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 { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import phScale from '../../phScale.js';
import PHMovable, { PHMovableOptions } from './PHMovable.js';
import Solute from './Solute.js';

type SelfOptions = {
Expand All @@ -25,10 +25,11 @@ type SelfOptions = {
visible?: boolean; // is the dropper visible?
};

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

export default class Dropper extends PHMovable {
export default class Dropper {

public readonly position: Vector2;
public readonly soluteProperty: Property<Solute>;
public readonly flowRateProperty: Property<number>;
public readonly isDispensingProperty: Property<boolean>;
Expand All @@ -38,25 +39,20 @@ export default class Dropper extends PHMovable {
// See https://github.com/phetsims/ph-scale/issues/178
public readonly visibleProperty: Property<boolean>;

public constructor( solute: Solute, solutes: Solute[], position: Vector2, dragBounds: Bounds2, providedOptions: DropperOptions ) {
public constructor( solute: Solute, solutes: Solute[], position: Vector2, providedOptions: DropperOptions ) {

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

// SelfOptions
flowRate: 0,
maxFlowRate: 0.05,
dispensing: false,
empty: false,
enabled: true,
visible: true,

// PHMovableOptions
positionPropertyOptions: {
phetioHighFrequency: true
}
visible: true
}, providedOptions );

super( position, dragBounds, options );
this.position = position;

this.soluteProperty = new Property( solute, {
validValues: solutes,
Expand Down Expand Up @@ -105,8 +101,7 @@ export default class Dropper extends PHMovable {
} );
}

public override reset(): void {
super.reset();
public reset(): void {
this.soluteProperty.reset();
this.isDispensingProperty.reset();
this.enabledProperty.reset();
Expand Down
9 changes: 3 additions & 6 deletions js/common/model/PHModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import Property from '../../../../axon/js/Property.js';
import Bounds2 from '../../../../dot/js/Bounds2.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';
Expand Down Expand Up @@ -100,11 +99,9 @@ export default class PHModel<T extends Solution> implements TModel {
this.beaker = new Beaker( PHScaleConstants.BEAKER_POSITION );

const yDropper = this.beaker.position.y - this.beaker.size.height - 15;
this.dropper = new Dropper( Solute.WATER, this.solutes,
new Vector2( this.beaker.position.x - 50, yDropper ),
new Bounds2( this.beaker.left + 40, yDropper, this.beaker.right - 200, yDropper ), {
tandem: options.tandem.createTandem( 'dropper' )
} );
this.dropper = new Dropper( Solute.WATER, this.solutes, new Vector2( this.beaker.position.x - 50, yDropper ), {
tandem: options.tandem.createTandem( 'dropper' )
} );

this.solution = options.createSolution( this.dropper.soluteProperty, this.beaker.volume,
options.tandem.createTandem( 'solution' ) );
Expand Down
5 changes: 2 additions & 3 deletions js/common/view/DropperFluidNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ export default class DropperFluidNode extends Rectangle {

// shape
if ( dropper.flowRateProperty.value > 0 ) {
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.flowRateProperty.link( updateShapeAndPosition );

// set color to match solute
Expand Down
24 changes: 2 additions & 22 deletions js/common/view/PHDropperNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Property from '../../../../axon/js/Property.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
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 { DragListener, InteractiveHighlighting } from '../../../../scenery/js/imports.js';
import phScale from '../../phScale.js';
import Dropper from '../model/Dropper.js';

type SelfOptions = EmptySelfOptions;

type PHDropperNodeOptions = SelfOptions & PickRequired<EyeDropperNodeOptions, 'tandem' | 'visibleProperty'>;

export default class PHDropperNode extends InteractiveHighlighting( EyeDropperNode ) {
export default class PHDropperNode extends EyeDropperNode {

public constructor( dropper: Dropper, modelViewTransform: ModelViewTransform2, providedOptions: PHDropperNodeOptions ) {

Expand All @@ -39,30 +37,12 @@ export default class PHDropperNode extends InteractiveHighlighting( EyeDropperNo
super( options );

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

// change fluid color when the solute changes
dropper.soluteProperty.link( solute => {
this.setFluidColor( solute.stockColor );
} );

// dilate touch area
this.touchArea = this.localBounds.dilatedX( 0.25 * this.width );

// move the dropper
this.addInputListener( new DragListener( {
useInputListenerCursor: true,
positionProperty: dropper.positionProperty,
dragBoundsProperty: new Property( dropper.dragBounds ),
transform: modelViewTransform,
tandem: options.tandem.createTandem( 'dragListener' ),
phetioEnabledPropertyInstrumented: true // see https://github.com/phetsims/ph-scale/issues/263
} ) );

// NOTE: Moving the dropper via the keyboard is not necessary.
// See https://github.com/phetsims/ph-scale/issues/252
}
}

Expand Down
5 changes: 0 additions & 5 deletions js/micro/model/MicroModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Bounds2 from '../../../../dot/js/Bounds2.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import PHModel, { PHModelOptions } from '../../common/model/PHModel.js';
Expand All @@ -32,10 +31,6 @@ export default class MicroModel extends PHModel<MicroSolution> {
}, providedOptions );

super( options );

// adjust the drag bounds of the dropper to account for different user-interface constraints
const yDropper = this.dropper.positionProperty.value.y;
this.dropper.dragBounds = new Bounds2( this.beaker.left + 120, yDropper, this.beaker.right - 170, yDropper );
}
}

Expand Down

0 comments on commit ecde0f2

Please sign in to comment.