Skip to content

Commit

Permalink
fixed an issue where the lid could move by itself after and explosion…
Browse files Browse the repository at this point in the history
… followed by a return of the lid
  • Loading branch information
jbphet committed Jun 12, 2020
1 parent b0459fb commit cfb714d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
13 changes: 10 additions & 3 deletions js/common/view/ParticleContainerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,22 @@ function ParticleContainerNode( multipleParticleModel, modelViewTransform, optio
end: () => {

// Set the target size to the current size, which will stop any change in size that is currently underway.
multipleParticleModel.setTargetContainerHeight(
multipleParticleModel.containerHeightProperty.get()
);
if ( !multipleParticleModel.isExplodedProperty.value ) {
multipleParticleModel.setTargetContainerHeight( multipleParticleModel.containerHeightProperty.get() );
}
},

tandem: lidTandem.createTandem( 'lidDragListener' )
} ) );
}

// The particle container can explode while the lid is being dragged and, if that happens, cancel the interaction.
multipleParticleModel.isExplodedProperty.lazyLink( isExploded => {
if ( isExploded ) {
this.interruptSubtreeInput();
}
} );

let pressureGaugeNode;
if ( options.pressureGaugeEnabled ) {

Expand Down
24 changes: 15 additions & 9 deletions js/common/view/PointingHandNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ import MultipleParticleModel from '../model/MultipleParticleModel.js';
const WIDTH = 150; // in screen coords

/**
*
* @param {MultipleParticleModel} multipleParticleModel - model of the simulation
* @param {PhaseChangesModel} phaseChangesModel - model of the simulation
* @param {ModelViewTransform2} modelViewTransform to convert between model and view co-ordinate frames
* @param {Object} [options]
* @constructor
*/
function PointingHandNode( multipleParticleModel, modelViewTransform, options ) {
function PointingHandNode( phaseChangesModel, modelViewTransform, options ) {

options = merge( {
tandem: Tandem.REQUIRED
Expand Down Expand Up @@ -94,15 +93,15 @@ function PointingHandNode( multipleParticleModel, modelViewTransform, options )
start: event => {
startY = self.globalToParentPoint( event.pointer.point ).y;
beingDragged = true;
containerSizeAtDragStart = multipleParticleModel.containerHeightProperty.get();
containerSizeAtDragStart = phaseChangesModel.containerHeightProperty.get();
updateHintVisibility();
},

drag: event => {
endY = self.globalToParentPoint( event.pointer.point ).y;

// Resize the container based on the amount that the node has moved.
multipleParticleModel.setTargetContainerHeight(
phaseChangesModel.setTargetContainerHeight(
containerSizeAtDragStart + modelViewTransform.viewToModelDeltaY( endY - startY )
);
updateHintVisibility();
Expand All @@ -111,16 +110,23 @@ function PointingHandNode( multipleParticleModel, modelViewTransform, options )
end: event => {

// Set the target size to the current size, which will stop any change in size that is currently underway.
multipleParticleModel.setTargetContainerHeight(
multipleParticleModel.containerHeightProperty.get()
);
if ( !phaseChangesModel.isExplodedProperty.value ) {
phaseChangesModel.setTargetContainerHeight( phaseChangesModel.containerHeightProperty.get() );
}
beingDragged = false;
updateHintVisibility();
},

tandem: options.tandem.createTandem( 'dragListener' )
} ) );

// The particle container can explode while this is being dragged and, if that happens, cancel the interaction.
phaseChangesModel.isExplodedProperty.lazyLink( isExploded => {
if ( isExploded ) {
this.interruptSubtreeInput();
}
} );

// add the listener that will show and hide the hint
this.addInputListener( {
enter: function() {
Expand All @@ -141,7 +147,7 @@ function PointingHandNode( multipleParticleModel, modelViewTransform, options )
this.touchArea = this.localBounds.dilatedXY( 10, 10 );

// Add a listener to update the individual arrow visibility.
multipleParticleModel.containerHeightProperty.link( function( particleContainerHeight ) {
phaseChangesModel.containerHeightProperty.link( function( particleContainerHeight ) {
if ( particleContainerHeight === MultipleParticleModel.PARTICLE_CONTAINER_INITIAL_HEIGHT ) {

// At the height limit, so only show the down arrow.
Expand Down

0 comments on commit cfb714d

Please sign in to comment.