Skip to content

Commit

Permalink
Remove support for TWIXT animation. After using collection layout bou…
Browse files Browse the repository at this point in the history
…nds. This is no longer needed. #120
  • Loading branch information
phet-dev authored and Denz1994 committed Jan 22, 2020
1 parent d6ac04e commit 0886159
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 94 deletions.
59 changes: 0 additions & 59 deletions js/common/model/Atom2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ define( require => {
const Atom = require( 'NITROGLYCERIN/Atom' );
const BooleanProperty = require( 'AXON/BooleanProperty' );
const buildAMolecule = require( 'BUILD_A_MOLECULE/buildAMolecule' );
const Easing = require( 'TWIXT/Easing' );
const Emitter = require( 'AXON/Emitter' );
const Rectangle = require( 'DOT/Rectangle' );
const Strings = require( 'BUILD_A_MOLECULE/Strings' );
Expand Down Expand Up @@ -44,13 +43,6 @@ define( require => {
this.isAnimatingProperty = new BooleanProperty( false );
this.isSeparatingProperty = new BooleanProperty( false );

// @private {Vector2|null} Used for animating the molecules to a position constrained in play area bounds
this.animationStartPosition = null;
this.animationEndPosition = null;

// @private {number} Valid values 0 <= x <= 1. Used to adjust rate of animation completion.
this.animationProgress = 0;

// @public {Emitter}
this.grabbedByUserEmitter = new Emitter( { parameters: [ { valueType: Atom2 } ] } );
this.droppedByUserEmitter = new Emitter( { parameters: [ { valueType: Atom2 } ] } );
Expand Down Expand Up @@ -79,9 +71,6 @@ define( require => {
this.userControlledProperty.lazyLink( controlled => {
if ( controlled ) {
this.grabbedByUserEmitter.emit( this );

// Interrupt animation process
this.interruptAnimation( controlled );
}
else {
this.droppedByUserEmitter.emit( this );
Expand All @@ -106,41 +95,6 @@ define( require => {
if ( this.isSeparatingProperty.value ) {
this.stepAtomTowardsDestination( dt );
}

// Handle animation process
if ( this.isAnimatingProperty.value ) {
this.animate( dt );
}
}

/**
* Handle animating returning atoms to a position constrained within play area.
*
* @param {number} dt
* @private
*/
animate( dt ) {
const distance = this.animationStartPosition.distance( this.animationEndPosition );
if ( distance > 0 ) {

// Responsible for the tempo of the animation.
this.animationProgress = Math.min( 1, this.animationProgress + dt * 2 );
const ratio = Easing.CUBIC_IN_OUT.value( this.animationProgress );

// Update the position of the atom
this.positionProperty.set( this.animationStartPosition.blend( this.animationEndPosition, ratio ) );
}

// At this point the animation has completed
else {
this.animationProgress = 1;
this.destinationProperty.value = this.positionProperty.value;
}
if ( this.animationProgress === 1 ) {
this.isAnimatingProperty.set( false );
this.animationProgress = 0;
this.separateMoleculeEmitter.emit();
}
}

/**
Expand Down Expand Up @@ -178,16 +132,6 @@ define( require => {
}
}

/**
* Interrupt and reset the animation progress if a user controls an atom.
*
* @param {boolean} userControlled - User is controlling the atom
*/
interruptAnimation( userControlled ) {
this.isAnimatingProperty.set( !userControlled );
this.animationProgress = 0;
}

setPosition( x, y ) {
this.positionProperty.value = new Vector2( x, y );
}
Expand All @@ -213,9 +157,6 @@ define( require => {
this.visibleProperty.reset();
this.addedToModelProperty.reset();
this.destinationProperty.value = this.positionProperty.value;

// Treat animation interruption as if it is userControlled.
this.interruptAnimation( true );
}
}

Expand Down
34 changes: 0 additions & 34 deletions js/common/view/BAMScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ define( require => {
this.atomDragBounds = new Bounds2( -1575, -850, 1575, 950 );
this.mappedKitCollectionBounds = this.kitCollectionMap[ this.kitCollectionList.currentCollectionProperty.value.id ].bounds.dilatedX( 60 );


// @public Dialog used for representing 3D molecules.
// Only create a dialog if webgl is enabled. See https://github.com/phetsims/build-a-molecule/issues/105
this.dialog = ThreeUtils.isWebGLEnabled() ? new Molecule3DDialog( new Property( null ) ) : new WarningDialog();
Expand Down Expand Up @@ -374,7 +373,6 @@ define( require => {
if ( molecule ) {
molecule.atoms.forEach( moleculeAtom => {
if ( moleculeAtom ) {
moleculeAtom.interruptAnimation( atom.userControlledProperty.value );
moleculeAtom.destinationProperty.value = moleculeAtom.positionProperty.value;
}
} );
Expand Down Expand Up @@ -421,29 +419,10 @@ define( require => {

// Keep track of view elements used later in the callback
const mappedAtomNode = this.kitPlayAreaNode.atomNodeMap[ atom.id ];
const molecule = currentKit.getMolecule( atom );

// Responsible for dropping molecules in play area or kit area
const droppedInKitArea = mappedAtomNode && mappedAtomNode.bounds.intersectsBounds( this.mappedKitCollectionBounds );

// Set the atom position to the closest position within the play area bounds, unless it's dropped in kit area.
if ( !this.playAreaDragBounds.containsPoint( atom.positionProperty.value ) && !droppedInKitArea ) {
this.setAnimationParameters( atom, this.playAreaDragBounds.closestPointTo( atom.positionProperty.value ) );

// Track changed position of atom after returning to constrained bounds.
// All atoms bonded to the dragged atom need to be offset by this delta.
const delta = atom.animationEndPosition.minus( atom.animationStartPosition );

// Every other atom in the molecule should update its position with the same delta.
if ( molecule ) {
molecule.atoms.forEach( moleculeAtom => {
if ( moleculeAtom !== atom ) {
this.setAnimationParameters( moleculeAtom, moleculeAtom.positionProperty.value.plus( delta ) );
}
} );
}
}

// Responsible for bonding molecules in play area or breaking molecule bonds and returning to kit.
// We don't want to do this while the molecule is animating.
if ( !atom.isAnimatingProperty.value ) {
Expand All @@ -458,19 +437,6 @@ define( require => {
atomNode.addInputListener( atomListener );
}

/**
* Sets animation end and start positions.
*
* @param atom {Atom2}
* @param animationEndPosition {Vector2}
* @private
*/
setAnimationParameters( atom, animationEndPosition ) {
atom.animationStartPosition = atom.positionProperty.value;
atom.animationEndPosition = animationEndPosition;
atom.isAnimatingProperty.set( true );
}

/**
* Removes atom elements from view.
*
Expand Down
3 changes: 2 additions & 1 deletion js/common/view/MoleculeCollectingScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ define( require => {
this.regenerateCallback = regenerateCallback;

// Adjust play area and carousel bounds to compensate for CollectionPanel
this.playAreaDragBounds = kitCollectionList.currentCollectionProperty.value.currentKitProperty.value.collectionLayout.availablePlayAreaBounds;
const collectionLayout = kitCollectionList.currentCollectionProperty.value.currentKitProperty.value.collectionLayout;
this.playAreaDragBounds = collectionLayout.availablePlayAreaBounds.withMaxX( collectionLayout.availableKitBounds.width );
this.mappedKitCollectionBounds = this.kitCollectionMap[ this.kitCollectionList.currentCollectionProperty.value.id ].bounds.dilatedX( 15 );
const collectionAttachmentCallbacks = [];
const collectionPanel = new CollectionPanel(
Expand Down

0 comments on commit 0886159

Please sign in to comment.