Skip to content

Commit

Permalink
fix TParticles hierarchy with SR, #213
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Nov 15, 2017
1 parent 430519d commit f59540a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 141 deletions.
11 changes: 1 addition & 10 deletions js/concentration/model/Particles.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,12 @@ define( function( require ) {
/**
* Adds a particle.
* @param {SoluteParticle} particle
* @public called by TParticles and subclasses
* @protected
*/
addParticle: function( particle ) {
this.particles.push( particle );
},

/**
* Removes all particles.
* @public
* @abstract
*/
removeAllParticles: function() {
throw new Error( 'must be implemented by subtype' );
},

/**
* Registers a listener that will be called when the collection of particles has changed in some way
* (eg, number of particles, particles move, ...)
Expand Down
8 changes: 3 additions & 5 deletions js/concentration/model/Precipitate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ define( function( require ) {
var PrecipitateParticle = require( 'BEERS_LAW_LAB/concentration/model/PrecipitateParticle' );
var Vector2 = require( 'DOT/Vector2' );

// phet-io modules
var TPrecipitate = require( 'BEERS_LAW_LAB/concentration/model/TPrecipitate' );

/**
* @param {ConcentrationSolution} solution
* @param {Beaker} beaker
Expand Down Expand Up @@ -49,8 +46,9 @@ define( function( require ) {
self.updateParticles();
} );

// Persists for the life of the sim, no need to be disposed
tandem.addInstance( this, { phetioType: TPrecipitate } );
// We're not calling tandem.addInstance for Precipitate because it doesn't add any new attributes or methods.
// And individual particles are derived from the model, so restoring individual particles (as part of saved
// state) is problematic. See https://github.com/phetsims/beers-law-lab/issues/213
}

beersLawLab.register( 'Precipitate', Precipitate );
Expand Down
1 change: 0 additions & 1 deletion js/concentration/model/ShakerParticles.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ define( function( require ) {

/**
* @public
* @override
*/
removeAllParticles: function() {
var particles = this.particles.slice( 0 );
Expand Down
58 changes: 0 additions & 58 deletions js/concentration/model/TParticles.js

This file was deleted.

57 changes: 0 additions & 57 deletions js/concentration/model/TPrecipitate.js

This file was deleted.

28 changes: 18 additions & 10 deletions js/concentration/model/TShakerParticles.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,52 @@ define( function( require ) {
var phetioInherit = require( 'ifphetio!PHET_IO/phetioInherit' );
var TObject = require( 'ifphetio!PHET_IO/types/TObject' );
var TShakerParticle = require( 'BEERS_LAW_LAB/concentration/model/TShakerParticle' );
var TParticles = require( 'BEERS_LAW_LAB/concentration/model/TParticles' );

/**
*
* @param instance
* @param {ShakerParticles} shakerParticles
* @param phetioID
* @constructor
*/
function TShakerParticles( instance, phetioID ) {
assert && assertInstanceOf( instance, phet.beersLawLab.ShakerParticles );
TParticles.call( this, instance, phetioID );
function TShakerParticles( shakerParticles, phetioID ) {
assert && assertInstanceOf( shakerParticles, phet.beersLawLab.ShakerParticles );
TObject.call( this, shakerParticles, phetioID );
}

phetioInherit( TObject, 'TShakerParticles', TShakerParticles, {}, {

documentation: 'Base type for a group of particles.',

clearChildInstances: function( instance ) {
TParticles.clearChildInstances( instance );
clearChildInstances: function( shakerParticles ) {
shakerParticles.removeAllParticles();

// Particles.step is not called in playback mode, so this needs to be called explicitly to update the view.
shakerParticles.fireChanged();
},

/**
* Create a dynamic particle as specified by the phetioID and state.
* @param {Object} instance
* @param {ShakerParticles} shakerParticles
* @param {Tandem} tandem
* @param {Object} stateObject
* @returns {ChargedParticle}
*/
addChildInstance: function( instance, tandem, stateObject ) {
addChildInstance: function( shakerParticles, tandem, stateObject ) {

var value = TShakerParticle.fromStateObject( stateObject );
assert && assert( value.acceleration instanceof phet.dot.Vector2, 'acceleration should be a Vector2' );
TParticles.addParticle( instance, new phet.beersLawLab.ShakerParticle(

shakerParticles.addParticle( new phet.beersLawLab.ShakerParticle(
value.solute,
value.location,
value.orientation,
value.velocity,
value.acceleration,
tandem
) );

// Particles.step is not called in playback mode, so this needs to be called explicitly to update the view.
shakerParticles.fireChanged();
}
} );

Expand Down

0 comments on commit f59540a

Please sign in to comment.