diff --git a/js/common/model/BallState.js b/js/common/model/BallState.js index 57f8b800..ec5edc60 100644 --- a/js/common/model/BallState.js +++ b/js/common/model/BallState.js @@ -18,9 +18,8 @@ * - Pauses the sim. * - Sets the elapsed time to 0. * - Sets the Balls' position, mass, and velocity to their most recent saved BallState. Their restart BallState - * is saved when the user finishes controlling one of the Balls. - * - Only balls currently in the BallSystem are restarted. Only balls in the BallSystem that are fully inside - * the PlayArea's bounds have their states saved. + * is saved when the user finishes controlling one of the Balls. However, if any of the balls are outside + * the PlayArea's bounds, the states are not saved. See https://github.com/phetsims/collision-lab/issues/163. * * @author Brandon Li */ diff --git a/js/common/model/BallSystem.js b/js/common/model/BallSystem.js index 3318502a..963b7fa4 100644 --- a/js/common/model/BallSystem.js +++ b/js/common/model/BallSystem.js @@ -167,20 +167,20 @@ class BallSystem { // Observe when Balls are added to the system and save the states of all balls in the system. Listener lasts for the // life-time of the simulation since BallSystems are never disposed. this.balls.elementAddedEmitter.addListener( ball => { - this.balls.forEach( ball => ball.insidePlayAreaProperty.value && ball.saveState() ); + this.balls.every( ball => ball.insidePlayAreaProperty.value ) && this.balls.forEach( ball => ball.saveState() ); } ); // Observe when the user is done controlling any of the Balls to: - // 1. Save the states of all Balls that are both in the system and fully inside the PlayArea's bounds. + // 1. Save the states of all Balls if every ball is inside the PlayArea's bounds. // 2. Clear the trailing Paths of all Balls and the Path of the CenterOfMass. // 3. Reset the rotation of Balls relative to their centers. // // Link lasts for the life-time of the sim as BallSystems are never disposed. this.ballSystemUserControlledProperty.lazyLink( ballSystemUserControlled => { - if ( !ballSystemUserControlled ) { + if ( !ballSystemUserControlled && this.balls.every( ball => ball.insidePlayAreaProperty.value ) ) { this.balls.forEach( ball => { - // Save the state of each Ball in the BallSystem that is fully inside the PlayArea. + // Save the state of each Ball. ball.insidePlayAreaProperty.value && ball.saveState(); ball.path.clear(); ball.rotationProperty.reset();