Skip to content

Commit

Permalink
Interrupt drag events from other atoms when dragging and during reset…
Browse files Browse the repository at this point in the history
… callbacks. #161
  • Loading branch information
Denz1994 committed Mar 3, 2020
1 parent 91f2d99 commit fdac623
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion js/common/view/BAMScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class BAMScreenView extends ScreenView {

// Create a button to refill the kit
const refillListener = () => {
this.interruptSubtreeInput();
this.kitPlayAreaNode.resetPlayAreaKit();
this.kitPlayAreaNode.currentKit.buckets.forEach( bucket => {
bucket.setToFullState();
Expand All @@ -110,6 +111,7 @@ class BAMScreenView extends ScreenView {
// Create a reset all button. Position altered on "Larger" Screen.
this.resetAllButton = new ResetAllButton( {
listener: () => {
this.interruptSubtreeInput();

// When clicked, empty collection boxes
kitCollectionList.currentCollectionProperty.value.collectionBoxes.forEach( box => {
Expand Down Expand Up @@ -342,6 +344,14 @@ class BAMScreenView extends ScreenView {
dragBoundsProperty: new Property( this.atomDragBounds ),
positionProperty: atom.positionProperty,
start: () => {

// Interrupt drag events on other atom nodes
this.kitPlayAreaNode.atomLayer.children.forEach( otherAtomNode => {
if ( otherAtomNode && atomNode !== otherAtomNode ) {
otherAtomNode.interruptSubtreeInput();
otherAtomNode.atom.userControlledProperty.reset();
}
} );
dragLength = 0;
atom.destinationProperty.value = atom.positionProperty.value;

Expand Down Expand Up @@ -373,7 +383,7 @@ class BAMScreenView extends ScreenView {
// Set the last position to the newly dragged position.
lastPosition = atom.positionProperty.value;

// Handles atoms with multiple molecules
// Handles molecules with multiple atoms
const molecule = currentKit.getMolecule( atom );
if ( molecule ) {
molecule.atoms.forEach( moleculeAtom => {
Expand Down Expand Up @@ -408,6 +418,7 @@ class BAMScreenView extends ScreenView {
// We don't want to do this while the molecule is animating.
currentKit.atomDropped( atom, droppedInKitArea );


// Make sure to update the update button after moving atoms
this.updateRefillButton();
}
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/KitView.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class KitView extends Node {
const particleAddedListener = atom => {

// AtomNode created based on atoms in bucket
const atomNode = new AtomNode( atom, {} );
const atomNode = new AtomNode( atom );

// Keep track of the atomNode by mapping to its atom's ID then add to atom layer
this.atomNodeMap[ atom.id ] = atomNode;
Expand Down

1 comment on commit fdac623

@Denz1994
Copy link
Contributor Author

@Denz1994 Denz1994 commented on fdac623 Mar 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also related #162
#144

Please sign in to comment.