Skip to content

Commit 0886159

Browse files
phet-devDenz1994
authored andcommitted
Remove support for TWIXT animation. After using collection layout bounds. This is no longer needed. #120
1 parent d6ac04e commit 0886159

File tree

3 files changed

+2
-94
lines changed

3 files changed

+2
-94
lines changed

js/common/model/Atom2.js

-59
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ define( require => {
1313
const Atom = require( 'NITROGLYCERIN/Atom' );
1414
const BooleanProperty = require( 'AXON/BooleanProperty' );
1515
const buildAMolecule = require( 'BUILD_A_MOLECULE/buildAMolecule' );
16-
const Easing = require( 'TWIXT/Easing' );
1716
const Emitter = require( 'AXON/Emitter' );
1817
const Rectangle = require( 'DOT/Rectangle' );
1918
const Strings = require( 'BUILD_A_MOLECULE/Strings' );
@@ -44,13 +43,6 @@ define( require => {
4443
this.isAnimatingProperty = new BooleanProperty( false );
4544
this.isSeparatingProperty = new BooleanProperty( false );
4645

47-
// @private {Vector2|null} Used for animating the molecules to a position constrained in play area bounds
48-
this.animationStartPosition = null;
49-
this.animationEndPosition = null;
50-
51-
// @private {number} Valid values 0 <= x <= 1. Used to adjust rate of animation completion.
52-
this.animationProgress = 0;
53-
5446
// @public {Emitter}
5547
this.grabbedByUserEmitter = new Emitter( { parameters: [ { valueType: Atom2 } ] } );
5648
this.droppedByUserEmitter = new Emitter( { parameters: [ { valueType: Atom2 } ] } );
@@ -79,9 +71,6 @@ define( require => {
7971
this.userControlledProperty.lazyLink( controlled => {
8072
if ( controlled ) {
8173
this.grabbedByUserEmitter.emit( this );
82-
83-
// Interrupt animation process
84-
this.interruptAnimation( controlled );
8574
}
8675
else {
8776
this.droppedByUserEmitter.emit( this );
@@ -106,41 +95,6 @@ define( require => {
10695
if ( this.isSeparatingProperty.value ) {
10796
this.stepAtomTowardsDestination( dt );
10897
}
109-
110-
// Handle animation process
111-
if ( this.isAnimatingProperty.value ) {
112-
this.animate( dt );
113-
}
114-
}
115-
116-
/**
117-
* Handle animating returning atoms to a position constrained within play area.
118-
*
119-
* @param {number} dt
120-
* @private
121-
*/
122-
animate( dt ) {
123-
const distance = this.animationStartPosition.distance( this.animationEndPosition );
124-
if ( distance > 0 ) {
125-
126-
// Responsible for the tempo of the animation.
127-
this.animationProgress = Math.min( 1, this.animationProgress + dt * 2 );
128-
const ratio = Easing.CUBIC_IN_OUT.value( this.animationProgress );
129-
130-
// Update the position of the atom
131-
this.positionProperty.set( this.animationStartPosition.blend( this.animationEndPosition, ratio ) );
132-
}
133-
134-
// At this point the animation has completed
135-
else {
136-
this.animationProgress = 1;
137-
this.destinationProperty.value = this.positionProperty.value;
138-
}
139-
if ( this.animationProgress === 1 ) {
140-
this.isAnimatingProperty.set( false );
141-
this.animationProgress = 0;
142-
this.separateMoleculeEmitter.emit();
143-
}
14498
}
14599

146100
/**
@@ -178,16 +132,6 @@ define( require => {
178132
}
179133
}
180134

181-
/**
182-
* Interrupt and reset the animation progress if a user controls an atom.
183-
*
184-
* @param {boolean} userControlled - User is controlling the atom
185-
*/
186-
interruptAnimation( userControlled ) {
187-
this.isAnimatingProperty.set( !userControlled );
188-
this.animationProgress = 0;
189-
}
190-
191135
setPosition( x, y ) {
192136
this.positionProperty.value = new Vector2( x, y );
193137
}
@@ -213,9 +157,6 @@ define( require => {
213157
this.visibleProperty.reset();
214158
this.addedToModelProperty.reset();
215159
this.destinationProperty.value = this.positionProperty.value;
216-
217-
// Treat animation interruption as if it is userControlled.
218-
this.interruptAnimation( true );
219160
}
220161
}
221162

js/common/view/BAMScreenView.js

-34
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ define( require => {
5858
this.atomDragBounds = new Bounds2( -1575, -850, 1575, 950 );
5959
this.mappedKitCollectionBounds = this.kitCollectionMap[ this.kitCollectionList.currentCollectionProperty.value.id ].bounds.dilatedX( 60 );
6060

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

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

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

429-
// Set the atom position to the closest position within the play area bounds, unless it's dropped in kit area.
430-
if ( !this.playAreaDragBounds.containsPoint( atom.positionProperty.value ) && !droppedInKitArea ) {
431-
this.setAnimationParameters( atom, this.playAreaDragBounds.closestPointTo( atom.positionProperty.value ) );
432-
433-
// Track changed position of atom after returning to constrained bounds.
434-
// All atoms bonded to the dragged atom need to be offset by this delta.
435-
const delta = atom.animationEndPosition.minus( atom.animationStartPosition );
436-
437-
// Every other atom in the molecule should update its position with the same delta.
438-
if ( molecule ) {
439-
molecule.atoms.forEach( moleculeAtom => {
440-
if ( moleculeAtom !== atom ) {
441-
this.setAnimationParameters( moleculeAtom, moleculeAtom.positionProperty.value.plus( delta ) );
442-
}
443-
} );
444-
}
445-
}
446-
447426
// Responsible for bonding molecules in play area or breaking molecule bonds and returning to kit.
448427
// We don't want to do this while the molecule is animating.
449428
if ( !atom.isAnimatingProperty.value ) {
@@ -458,19 +437,6 @@ define( require => {
458437
atomNode.addInputListener( atomListener );
459438
}
460439

461-
/**
462-
* Sets animation end and start positions.
463-
*
464-
* @param atom {Atom2}
465-
* @param animationEndPosition {Vector2}
466-
* @private
467-
*/
468-
setAnimationParameters( atom, animationEndPosition ) {
469-
atom.animationStartPosition = atom.positionProperty.value;
470-
atom.animationEndPosition = animationEndPosition;
471-
atom.isAnimatingProperty.set( true );
472-
}
473-
474440
/**
475441
* Removes atom elements from view.
476442
*

js/common/view/MoleculeCollectingScreenView.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ define( require => {
8181
this.regenerateCallback = regenerateCallback;
8282

8383
// Adjust play area and carousel bounds to compensate for CollectionPanel
84-
this.playAreaDragBounds = kitCollectionList.currentCollectionProperty.value.currentKitProperty.value.collectionLayout.availablePlayAreaBounds;
84+
const collectionLayout = kitCollectionList.currentCollectionProperty.value.currentKitProperty.value.collectionLayout;
85+
this.playAreaDragBounds = collectionLayout.availablePlayAreaBounds.withMaxX( collectionLayout.availableKitBounds.width );
8586
this.mappedKitCollectionBounds = this.kitCollectionMap[ this.kitCollectionList.currentCollectionProperty.value.id ].bounds.dilatedX( 15 );
8687
const collectionAttachmentCallbacks = [];
8788
const collectionPanel = new CollectionPanel(

0 commit comments

Comments
 (0)