From cc70d208a1374473807440e720b32f5bb4a1002c Mon Sep 17 00:00:00 2001 From: Luisav1 Date: Wed, 14 Sep 2022 19:29:11 -0600 Subject: [PATCH] Add check for creator node visibility when emitting an alpha particle. See https://github.com/phetsims/build-a-nucleus/issues/51. --- js/common/view/BANScreenView.ts | 8 ++------ js/decay/view/DecayScreenView.ts | 8 ++++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/js/common/view/BANScreenView.ts b/js/common/view/BANScreenView.ts index ac77f95..5088753 100644 --- a/js/common/view/BANScreenView.ts +++ b/js/common/view/BANScreenView.ts @@ -588,16 +588,12 @@ abstract class BANScreenView extends ScreenView { } } - protected removeParticleFromModel( particle: Particle ): void { - this.model.outgoingParticles.includes( particle ) && this.model.outgoingParticles.remove( particle ); - this.model.removeParticle( particle ); - } - /** * Remove the given particle from the model and check the particle type's creator node visibility. */ protected removeParticleAndSetCreatorNodeVisibility( particle: Particle ): void { - this.removeParticleFromModel( particle ); + this.model.outgoingParticles.includes( particle ) && this.model.outgoingParticles.remove( particle ); + this.model.removeParticle( particle ); // make the creator node visible when removing the last nucleon from the particle atom this.setCreatorNodeVisibility( particle.type === ParticleType.PROTON.name.toLowerCase() ? diff --git a/js/decay/view/DecayScreenView.ts b/js/decay/view/DecayScreenView.ts index 8e99f1e..60bade0 100644 --- a/js/decay/view/DecayScreenView.ts +++ b/js/decay/view/DecayScreenView.ts @@ -415,11 +415,11 @@ class DecayScreenView extends BANScreenView { this.model.particleAnimations.push( alphaParticleEmissionAnimation ); alphaParticleEmissionAnimation.finishEmitter.addListener( () => { - alphaParticle.protons.forEach( proton => { - this.removeParticleFromModel( proton ); - } ); alphaParticle.neutrons.forEach( neutron => { - this.removeParticleFromModel( neutron ); + this.removeParticleAndSetCreatorNodeVisibility( neutron ); + } ); + alphaParticle.protons.forEach( proton => { + this.removeParticleAndSetCreatorNodeVisibility( proton ); } ); alphaParticleNode.dispose(); alphaParticle.dispose();