Skip to content

Commit

Permalink
Remove particleViewMap from being passed in to ParticleAtomNode and i…
Browse files Browse the repository at this point in the history
…nstead pass it in to function that uses it. See #112.
  • Loading branch information
Luisav1 committed Aug 18, 2023
1 parent a17c5f3 commit d31a7c1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion js/chart-intro/view/ChartIntroScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class ChartIntroScreenView extends BANScreenView<ChartIntroModel> {
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 ];

Expand Down
2 changes: 1 addition & 1 deletion js/common/view/BANScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ abstract class BANScreenView<M extends BANModel<ParticleAtom | ParticleNucleus>>
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;
Expand Down
10 changes: 4 additions & 6 deletions js/common/view/ParticleAtomNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

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';
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;
Expand All @@ -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[] = [];
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion js/decay/view/DecayScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class DecayScreenView extends BANScreenView<DecayModel> {
* 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 {
Expand Down

0 comments on commit d31a7c1

Please sign in to comment.