From 0348f33c047c528afd86df2d53342f8ee365eabe Mon Sep 17 00:00:00 2001 From: Michael Kauzmann Date: Fri, 12 Jul 2024 14:48:12 -0600 Subject: [PATCH] listen to density please, https://github.com/phetsims/density-buoyancy-common/issues/256 Signed-off-by: Michael Kauzmann --- .../view/MaterialMassVolumeControlNode.ts | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/js/common/view/MaterialMassVolumeControlNode.ts b/js/common/view/MaterialMassVolumeControlNode.ts index ca03a9d3..de4bb0af 100644 --- a/js/common/view/MaterialMassVolumeControlNode.ts +++ b/js/common/view/MaterialMassVolumeControlNode.ts @@ -35,6 +35,7 @@ import densityBuoyancyCommon from '../../densityBuoyancyCommon.js'; import BooleanToggleNode from '../../../../sun/js/BooleanToggleNode.js'; import Tandem from '../../../../tandem/js/Tandem.js'; import BooleanProperty from '../../../../axon/js/BooleanProperty.js'; +import MaterialProperty from '../model/MaterialProperty.js'; // constants const LITERS_IN_CUBIC_METER = DensityBuoyancyCommonConstants.LITERS_IN_CUBIC_METER; @@ -73,7 +74,7 @@ export default class MaterialMassVolumeControlNode extends MaterialControlNode { // the density slider can be added to this layer to show up in the right position (above the volume slider). protected readonly densityControlPlaceholderLayer: Node = new Node(); - public constructor( materialProperty: Property, + public constructor( materialProperty: MaterialProperty, massProperty: ReadOnlyProperty, volumeProperty: Property, materials: Material[], @@ -125,26 +126,25 @@ export default class MaterialMassVolumeControlNode extends MaterialControlNode { let userVolumeChanging = false; // DerivedProperty doesn't need disposal, since everything here lives for the lifetime of the simulation - const enabledMassRangeProperty = new DerivedProperty( [ materialProperty ], material => { - if ( material.custom ) { - return new Range( options.minCustomMass, options.maxCustomMass ); - } - else { - const density = material.density; - - const maxMassRange = supportTwoMassNumberControls && density > options.highDensityThreshold ? options.highDensityMaxMass! : options.maxMass; + const enabledMassRangeProperty = new DerivedProperty( [ materialProperty, materialProperty.densityProperty ], + ( material, density ) => { + if ( material.custom ) { + return new Range( options.minCustomMass, options.maxCustomMass ); + } + else { + const maxMassRange = supportTwoMassNumberControls && density > options.highDensityThreshold ? options.highDensityMaxMass! : options.maxMass; - const minMass = Utils.clamp( density * options.minVolumeLiters / LITERS_IN_CUBIC_METER, options.minMass, maxMassRange ); - const maxMass = Utils.clamp( density * options.maxVolumeLiters / LITERS_IN_CUBIC_METER, options.minMass, maxMassRange ); + const minMass = Utils.clamp( density * options.minVolumeLiters / LITERS_IN_CUBIC_METER, options.minMass, maxMassRange ); + const maxMass = Utils.clamp( density * options.maxVolumeLiters / LITERS_IN_CUBIC_METER, options.minMass, maxMassRange ); - return new WorkaroundRange( minMass, maxMass ); - } - }, { - reentrant: true, - phetioState: false, - phetioValueType: Range.RangeIO, - valueComparisonStrategy: 'equalsFunction' - } ); + return new WorkaroundRange( minMass, maxMass ); + } + }, { + reentrant: true, + phetioState: false, + phetioValueType: Range.RangeIO, + valueComparisonStrategy: 'equalsFunction' + } ); const enabledVolumeRangeProperty = new DerivedProperty( [ materialProperty ], material => { return new WorkaroundRange(