Skip to content

Commit

Permalink
minor code review changes, phetsims/build-a-nucleus#85
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Aug 2, 2023
1 parent d81f379 commit 8885e07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
23 changes: 10 additions & 13 deletions js/model/ParticleAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,17 +625,15 @@ class ParticleAtom extends PhetioObject {
/**
* Change the nucleon type of the provided particle to the other nucleon type.
*/
public changeNucleonType( particle: Particle, animateAndRemoveParticle: VoidFunction ): Animation {
public changeNucleonType( particle: Particle, onChangeComplete: VoidFunction ): Animation {
assert && assert( this.containsParticle( particle ), 'ParticleAtom does not contain this particle ' + particle.id );
assert && assert( particle.type === 'proton' || particle.type === 'neutron', 'Particle type must be a proton or a neutron.' );

const isParticleTypeProton = particle.type === 'proton';
const particleTypes = {
newParticleType: ( isParticleTypeProton ? 'neutron' : 'proton' ) as ParticleTypeString,
oldParticleArray: isParticleTypeProton ? this.protons : this.neutrons,
newParticleArray: isParticleTypeProton ? this.neutrons : this.protons
};
particle.typeProperty.value = particleTypes.newParticleType;
const oldParticleArray = isParticleTypeProton ? this.protons : this.neutrons;
const newParticleArray = isParticleTypeProton ? this.neutrons : this.protons;

particle.typeProperty.value = ( isParticleTypeProton ? 'neutron' : 'proton' ) as ParticleTypeString;

const particleType = particle.typeProperty.value;

Expand Down Expand Up @@ -673,15 +671,14 @@ class ParticleAtom extends PhetioObject {
initialColorChangeAnimation.then( finalColorChangeAnimation );
initialColorChangeAnimation.start();

initialColorChangeAnimation.finishEmitter.addListener( () => {
animateAndRemoveParticle();
} );
initialColorChangeAnimation.finishEmitter.addListener( () => onChangeComplete() );

// Defer the massNumberProperty links until the particle arrays are correct so the nucleus does not reconfigure.
const wasDeferred = this.massNumberProperty.isDeferred;
this.massNumberProperty.setDeferred( true );
arrayRemove( particleTypes.oldParticleArray, particle );
particleTypes.newParticleArray.push( particle );
this.massNumberProperty.setDeferred( false );
arrayRemove( oldParticleArray, particle );
newParticleArray.push( particle );
!wasDeferred && this.massNumberProperty.setDeferred( false );

return initialColorChangeAnimation;
}
Expand Down
8 changes: 4 additions & 4 deletions js/view/ParticleNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ class ParticleNode extends Circle {

// Set the options for the default look.
const nonHighContrastStroke = newColor.colorUtilsDarker( 0.33 );
const newOptions: CircleOptions = {};
newOptions.fill = gradientFill;
newOptions.stroke = nonHighContrastStroke;

this.mutate( newOptions );
this.mutate( {
fill: gradientFill,
stroke: nonHighContrastStroke
} );
};

// change the color of the particle
Expand Down

0 comments on commit 8885e07

Please sign in to comment.