From d31a7c100c31d7bdba4a845adc237b996e7a55ff Mon Sep 17 00:00:00 2001 From: Luisav1 Date: Fri, 18 Aug 2023 08:49:22 -0600 Subject: [PATCH] Remove particleViewMap from being passed in to ParticleAtomNode and instead pass it in to function that uses it. See https://github.com/phetsims/build-a-nucleus/issues/112. --- js/chart-intro/view/ChartIntroScreenView.ts | 2 +- js/common/view/BANScreenView.ts | 2 +- js/common/view/ParticleAtomNode.ts | 10 ++++------ js/decay/view/DecayScreenView.ts | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/js/chart-intro/view/ChartIntroScreenView.ts b/js/chart-intro/view/ChartIntroScreenView.ts index ed2bc3f..84f25a4 100644 --- a/js/chart-intro/view/ChartIntroScreenView.ts +++ b/js/chart-intro/view/ChartIntroScreenView.ts @@ -382,7 +382,7 @@ class ChartIntroScreenView extends BANScreenView { private createMiniParticleView( particle: Particle ): void { const particleView = new ParticleView( particle, this.miniAtomMVT, { inputEnabled: false } ); this.particleViewMap[ particle.id ] = particleView; - this.particleAtomNode.addParticleView( particle ); + this.particleAtomNode.addParticleView( particle, this.particleViewMap ); particle.disposeEmitter.addListener( () => { delete this.particleViewMap[ particle.id ]; diff --git a/js/common/view/BANScreenView.ts b/js/common/view/BANScreenView.ts index b527d73..6ff5793 100644 --- a/js/common/view/BANScreenView.ts +++ b/js/common/view/BANScreenView.ts @@ -514,7 +514,7 @@ abstract class BANScreenView> particle.dispose(); } ); - this.particleAtomNode = new ParticleAtomNode( this.particleViewMap, atomCenter, this.model.protonNumberRange ); + this.particleAtomNode = new ParticleAtomNode( atomCenter, this.model.protonNumberRange ); // for use in positioning this.doubleArrowButtons = doubleArrowButtons; diff --git a/js/common/view/ParticleAtomNode.ts b/js/common/view/ParticleAtomNode.ts index b481b11..5874348 100644 --- a/js/common/view/ParticleAtomNode.ts +++ b/js/common/view/ParticleAtomNode.ts @@ -10,7 +10,6 @@ import buildANucleus from '../../buildANucleus.js'; import { Circle, Color, Node } from '../../../../scenery/js/imports.js'; -import { ParticleViewMap } from './BANScreenView.js'; import BANConstants from '../BANConstants.js'; import LinearFunction from '../../../../dot/js/LinearFunction.js'; import Vector2 from '../../../../dot/js/Vector2.js'; @@ -18,6 +17,7 @@ import AtomIdentifier from '../../../../shred/js/AtomIdentifier.js'; import Particle from '../../../../shred/js/model/Particle.js'; import ParticleView from '../../../../shred/js/view/ParticleView.js'; import Range from '../../../../dot/js/Range.js'; +import { ParticleViewMap } from './BANScreenView.js'; // empirically determined, from the ElectronCloudView radius const MIN_ELECTRON_CLOUD_RADIUS = 42.5; @@ -33,9 +33,8 @@ class ParticleAtomNode extends Node { private readonly nucleonLayers: Node[]; private readonly atomCenter: Vector2; private readonly protonNumberRange: Range; - private readonly particleViewMap: ParticleViewMap; - public constructor( particleViewMap: ParticleViewMap, atomCenter: Vector2, protonNumberRange: Range ) { + public constructor( atomCenter: Vector2, protonNumberRange: Range ) { // Add the nucleonLayers const nucleonLayers: Node[] = []; @@ -66,7 +65,6 @@ class ParticleAtomNode extends Node { this.nucleonLayers = nucleonLayers; this.nucleonLayers.reverse(); // Set up the nucleon layers so that layer 0 is in front. - this.particleViewMap = particleViewMap; this.atomCenter = atomCenter; this.protonNumberRange = protonNumberRange; this.electronCloud = electronCloud; @@ -77,8 +75,8 @@ class ParticleAtomNode extends Node { /** * Add ParticleView for a given particle to the correct nucleonLayer. */ - public addParticleView( particle: Particle ): void { - const particleView = this.particleViewMap[ particle.id ]; + public addParticleView( particle: Particle, particleViewMap: ParticleViewMap ): void { + const particleView = particleViewMap[ particle.id ]; this.nucleonLayers[ particle.zLayerProperty.get() ].addChild( particleView ); // Add a listener that adjusts a nucleon's z-order layering. diff --git a/js/decay/view/DecayScreenView.ts b/js/decay/view/DecayScreenView.ts index c74dba5..f557531 100644 --- a/js/decay/view/DecayScreenView.ts +++ b/js/decay/view/DecayScreenView.ts @@ -269,7 +269,7 @@ class DecayScreenView extends BANScreenView { * Add particleView to correct layer in particleAtomNode. */ protected override addParticleView( particle: Particle ): void { - this.particleAtomNode.addParticleView( particle ); + this.particleAtomNode.addParticleView( particle, this.particleViewMap ); } protected override getRandomExternalModelPosition(): Vector2 {