Skip to content

Commit

Permalink
use scenery-phet's cue node, phetsims/density-buoyancy-common#364
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Kauzmann <[email protected]>
  • Loading branch information
zepumph committed Aug 29, 2024
1 parent 41984c1 commit 85e0980
Showing 1 changed file with 7 additions and 39 deletions.
46 changes: 7 additions & 39 deletions js/accessibility/nodes/BalloonInteractionCueNode.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
// Copyright 2017-2023, University of Colorado Boulder

/**
* A node that provides an interaction cue for dragging the balloon in Balloons and Static Electricity. Includes arrow
* and letter keys to indicate that the user can use WASD or arrow keys to move it around the play area.
* A node that provides an interaction cue for dragging (originally for the balloon in Balloons and Static Electricity).
* Includes arrow and letter keys to indicate that the user can use WASD or arrow keys to move the object around the
* play area. Provide the boundsProperty for the object for automatic resizing around the object.
*
* @author Jesse Greenberg
* @author Michael Kauzmann (PhET Interactive Simulations)
*/

import Multilink from '../../../../axon/js/Multilink.js';
import { Shape } from '../../../../kite/js/imports.js';
import LetterKeyNode, { LetterKeyNodeOptions } from '../../keyboard/LetterKeyNode.js';
import PhetFont from '../../PhetFont.js';
import { HBox, Node, Path, VBox } from '../../../../scenery/js/imports.js';
import balloonsAndStaticElectricity from '../../balloonsAndStaticElectricity.js';
import PlayAreaMap from '../model/PlayAreaMap.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import BalloonModel from '../model/BalloonModel.js';
import TextKeyNode from '../../keyboard/TextKeyNode.js';
import Bounds2 from '../../../../dot/js/Bounds2.js';
import Property from '../../../../axon/js/Property.js';
import sceneryPhet from '../../sceneryPhet.js';

// constants
const ARROW_HEIGHT = 15; // dimensions for the arrow icons
Expand All @@ -42,7 +40,7 @@ const DIRECTION_ANGLES = {
right: Math.PI / 2
};

class WASDCueNode extends Node {
export default class WASDCueNode extends Node {
protected wNode: Node;
protected aNode: Node;
protected sNode: Node;
Expand Down Expand Up @@ -122,34 +120,4 @@ class WASDCueNode extends Node {
}
}

class BalloonInteractionCueNode extends WASDCueNode {

public constructor( wallIsVisibleProperty: TReadOnlyProperty<boolean>, balloonModel: BalloonModel ) {

super( new Property( balloonModel.bounds ) );

// add listeners to update visibility of nodes when position changes and when the wall is made
// visible/invisible
Multilink.multilink( [ balloonModel.positionProperty, wallIsVisibleProperty ], ( position, visible ) => {

// get the max x positions depending on if the wall is visible
let centerXRightBoundary;
if ( visible ) {
centerXRightBoundary = PlayAreaMap.X_POSITIONS.AT_WALL;
}
else {
centerXRightBoundary = PlayAreaMap.X_BOUNDARY_POSITIONS.AT_RIGHT_EDGE;
}

const balloonCenter = balloonModel.getCenter();
this.aNode.visible = balloonCenter.x !== PlayAreaMap.X_BOUNDARY_POSITIONS.AT_LEFT_EDGE;
this.sNode.visible = balloonCenter.y !== PlayAreaMap.Y_BOUNDARY_POSITIONS.AT_BOTTOM;
this.dNode.visible = balloonCenter.x !== centerXRightBoundary;
this.wNode.visible = balloonCenter.y !== PlayAreaMap.Y_BOUNDARY_POSITIONS.AT_TOP;
} );
}
}

balloonsAndStaticElectricity.register( 'BalloonInteractionCueNode', BalloonInteractionCueNode );

export default BalloonInteractionCueNode;
sceneryPhet.register( 'WASDCueNode', WASDCueNode );

0 comments on commit 85e0980

Please sign in to comment.