From be21b34edbc5f23af1fd36cffbc576657e431969 Mon Sep 17 00:00:00 2001 From: Luisav1 Date: Thu, 17 Aug 2023 11:48:59 -0600 Subject: [PATCH] Address REVIEW comment by creating a new variable to keep track of the xPosition index. See https://github.com/phetsims/build-a-nucleus/issues/112. --- js/chart-intro/view/NucleonShellView.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/js/chart-intro/view/NucleonShellView.ts b/js/chart-intro/view/NucleonShellView.ts index ca2b152..ebb47d0 100644 --- a/js/chart-intro/view/NucleonShellView.ts +++ b/js/chart-intro/view/NucleonShellView.ts @@ -16,6 +16,7 @@ import ParticleType from '../../common/model/ParticleType.js'; import Vector2 from '../../../../dot/js/Vector2.js'; import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js'; import { FIRST_LEVEL_CAPACITY, ParticleShellPosition, SECOND_LEVEL_CAPACITY } from '../model/ParticleNucleus.js'; +import EnergyLevelType from '../model/EnergyLevelType.js'; type EnergyLevelNodeOptions = EmptySelfOptions & NodeOptions; @@ -64,24 +65,27 @@ class NucleonShellView extends Node { // update the stroke color and width of the respective energy levels as the nucleon number changes const boldEnergyLevelWidth = 4; const defaultEnergyLevelWidth = 1; + let xPositionIndex; // the xPosition from 1 to 5 for the second and third energy levels nucleonCountProperty.link( nucleonNumber => { if ( nucleonNumber <= FIRST_LEVEL_CAPACITY ) { - energyLevels[ 0 ].stroke = Color.interpolateRGBA( emptyLayerColor, fullLayerColor, nucleonNumber / FIRST_LEVEL_CAPACITY ); + const firstEnergyLevel = EnergyLevelType.NONE.yPosition; // set to first energy level where yPosition = 0 + energyLevels[ firstEnergyLevel ].stroke = Color.interpolateRGBA( emptyLayerColor, fullLayerColor, nucleonNumber / FIRST_LEVEL_CAPACITY ); // if the energy level is full (2 particles on the lower energy level), double the lineWidth - energyLevels[ 0 ].lineWidth = nucleonNumber === FIRST_LEVEL_CAPACITY ? boldEnergyLevelWidth : defaultEnergyLevelWidth; + energyLevels[ firstEnergyLevel ].lineWidth = nucleonNumber === FIRST_LEVEL_CAPACITY ? boldEnergyLevelWidth : defaultEnergyLevelWidth; } else { - let energyLevelNumber = 1; - if ( nucleonNumber > SECOND_LEVEL_CAPACITY + FIRST_LEVEL_CAPACITY ) { - nucleonNumber -= SECOND_LEVEL_CAPACITY; - energyLevelNumber = FIRST_LEVEL_CAPACITY; + let energyLevelNumber = EnergyLevelType.FIRST.yPosition; // initialize to second energy level where yPosition = 1 + xPositionIndex = nucleonNumber; // initialize to the current nucleonNumber + if ( nucleonNumber > ( SECOND_LEVEL_CAPACITY + FIRST_LEVEL_CAPACITY ) ) { + xPositionIndex = nucleonNumber - SECOND_LEVEL_CAPACITY; + energyLevelNumber = EnergyLevelType.SECOND.yPosition; } - nucleonNumber -= FIRST_LEVEL_CAPACITY; // REVIEW: instead of mutating the listener variable, it is better to name a new one (less confusing that way) - energyLevels[ energyLevelNumber ].stroke = Color.interpolateRGBA( emptyLayerColor, fullLayerColor, nucleonNumber / SECOND_LEVEL_CAPACITY ); + xPositionIndex = xPositionIndex - FIRST_LEVEL_CAPACITY; + energyLevels[ energyLevelNumber ].stroke = Color.interpolateRGBA( emptyLayerColor, fullLayerColor, xPositionIndex / SECOND_LEVEL_CAPACITY ); // if the energy level is full (6 particles on the upper and middle energy levels), double the lineWidth - energyLevels[ energyLevelNumber ].lineWidth = nucleonNumber === SECOND_LEVEL_CAPACITY ? boldEnergyLevelWidth : defaultEnergyLevelWidth; + energyLevels[ energyLevelNumber ].lineWidth = xPositionIndex === SECOND_LEVEL_CAPACITY ? boldEnergyLevelWidth : defaultEnergyLevelWidth; } } ); }