Skip to content

Commit

Permalink
Replace SimpleDragHandler with SoundDragListener, see: #320
Browse files Browse the repository at this point in the history
  • Loading branch information
marlitas committed Nov 26, 2024
1 parent 1e9b34f commit fcbd1e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
11 changes: 4 additions & 7 deletions js/motion/view/ItemNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Multilink from '../../../../axon/js/Multilink.js';
import PatternStringProperty from '../../../../axon/js/PatternStringProperty.js';
import Matrix3 from '../../../../dot/js/Matrix3.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import { Image, Node, Rectangle, SimpleDragHandler, Text, ImageableImage } from '../../../../scenery/js/imports.js';
import { Image, ImageableImage, Node, Rectangle, Text } from '../../../../scenery/js/imports.js';
import phetioStateSetEmitter from '../../../../tandem/js/phetioStateSetEmitter.js';
import forcesAndMotionBasics from '../../forcesAndMotionBasics.js';
import ForcesAndMotionBasicsStrings from '../../ForcesAndMotionBasicsStrings.js';
Expand All @@ -19,6 +19,7 @@ import MotionScreenView from './MotionScreenView.js';
import Item from '../model/Item.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import SoundDragListener from '../../../../scenery-phet/js/SoundDragListener.js';

//Workaround for https://github.com/phetsims/scenery/issues/108
const IDENTITY = Matrix3.scaling( 1, 1 );
Expand Down Expand Up @@ -144,13 +145,9 @@ export default class ItemNode extends Node {
person.directionProperty.set( direction );
};

const dragListener = new SimpleDragHandler( {
const dragListener = new SoundDragListener( {
tandem: tandem.createTandem( 'dragListener' ),

// @ts-expect-error
translate: options => {
item.positionProperty.set( options.position );
},
positionProperty: item.positionProperty,

//When picking up an object, remove it from the stack.
start: () => {
Expand Down
9 changes: 5 additions & 4 deletions js/motion/view/PusherNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Utils from '../../../../dot/js/Utils.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import { Image, Node, SimpleDragHandler } from '../../../../scenery/js/imports.js';
import { DragListener, Image, Node, SceneryEvent } from '../../../../scenery/js/imports.js';
import pusher_0_png from '../../../images/pushPullFigures/pusher_0_png.js';
import pusher_10_png from '../../../images/pushPullFigures/pusher_10_png.js';
import pusher_11_png from '../../../images/pushPullFigures/pusher_11_png.js';
Expand Down Expand Up @@ -46,6 +46,7 @@ import forcesAndMotionBasics from '../../forcesAndMotionBasics.js';
import MotionModel from '../model/MotionModel.js';
import MotionConstants from '../MotionConstants.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import SoundDragListener from '../../../../scenery-phet/js/SoundDragListener.js';

export default class PusherNode extends Node {

Expand Down Expand Up @@ -304,12 +305,12 @@ export default class PusherNode extends Node {
}
} );

const dragListener = new SimpleDragHandler( {
const dragListener = new SoundDragListener( {
tandem: tandem.createTandem( 'dragListener' ),
allowTouchSnag: true,
translate: ( options: { delta: Vector2 } ) => {
drag: ( event: SceneryEvent, listener: DragListener ) => {
if ( this.interactive ) {
const newAppliedForce = model.appliedForceProperty.get() + options.delta.x;
const newAppliedForce = model.appliedForceProperty.get() + listener.modelDelta.x;
const clampedAppliedForce = Math.max( -500, Math.min( 500, newAppliedForce ) );

// the new force should be rounded so that applied force is not
Expand Down
13 changes: 5 additions & 8 deletions js/netforce/view/PullerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
*/

import Vector2 from '../../../../dot/js/Vector2.js';
import { Image, SimpleDragHandler, ImageableImage } from '../../../../scenery/js/imports.js';
import { Image, ImageableImage } from '../../../../scenery/js/imports.js';
import forcesAndMotionBasics from '../../forcesAndMotionBasics.js';
import IntentionalAny from '../../../../phet-core/js/types/IntentionalAny.js';
import Puller from '../model/Puller.js';
import NetForceModel from '../model/NetForceModel.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import Knot from '../model/Knot.js';
import SoundDragListener from '../../../../scenery-phet/js/SoundDragListener.js';

export default class PullerNode extends Image {
public standImage: ImageableImage;
Expand Down Expand Up @@ -72,11 +73,11 @@ export default class PullerNode extends Image {
this.updatePosition( puller, model );
} );

const dragListener = new SimpleDragHandler( {
const dragListener = new SoundDragListener( {
tandem: tandem.createTandem( 'dragListener' ),
allowTouchSnag: true,

start: ( event: IntentionalAny ) => {
positionProperty: puller.positionProperty,
start: ( event: IntentionalAny ) => {

// check to see if a puller is knotted - if it is, store the knot
const knot = puller.knotProperty.get();
Expand All @@ -101,10 +102,6 @@ export default class PullerNode extends Image {
puller.draggingProperty.set( false );
puller.droppedEmitter.emit();
this.updateImage( puller, model );
},
translate: ( event: IntentionalAny ) => {
this.updateImage( puller, model );
this.puller.positionProperty.set( event.position );
}
}
);
Expand Down

0 comments on commit fcbd1e6

Please sign in to comment.