Skip to content

Commit

Permalink
Tandem grouping for block sets, see phetsims/density#96
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Sep 7, 2021
1 parent c73517d commit bdf684e
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 56 deletions.
2 changes: 1 addition & 1 deletion js/common/model/BlockSetModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const BlockSetModel = ( type, BlockSet, initialMode ) => {

// @public {Property.<BlockSet>}
this.blockSetProperty = new EnumerationProperty( BlockSet, initialMode, {
tandem: tandem.createTandem( 'blockSetProperty' )
tandem: tandem.createTandem( 'blockSets' ).createTandem( 'blockSetProperty' )
} );

// @private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DensityBuoyancyCommonColors.labelBProperty.link( labelColor => {
bMaterial.color = ThreeUtils.colorToThree( labelColor );
} );

class SecondMassVisibleControl extends RectangularRadioButtonGroup {
class BlocksRadioButtonGroup extends RectangularRadioButtonGroup {
/**
* @param {Property.<boolean>} secondaryMassVisibleProperty
* @param {Object} [options]
Expand All @@ -39,12 +39,12 @@ class SecondMassVisibleControl extends RectangularRadioButtonGroup {
super( secondaryMassVisibleProperty, [
{
value: false,
node: SecondMassVisibleControl.getSingleCuboidIcon(),
node: BlocksRadioButtonGroup.getSingleCuboidIcon(),
tandemName: 'oneBlockRadioButton'
},
{
value: true,
node: SecondMassVisibleControl.getDoubleCuboidIcon(),
node: BlocksRadioButtonGroup.getDoubleCuboidIcon(),
tandemName: 'twoBlocksRadioButton'
}
], merge( {
Expand Down Expand Up @@ -165,8 +165,8 @@ class SecondMassVisibleControl extends RectangularRadioButtonGroup {
*/
static getSingleCuboidIcon() {
if ( DensityBuoyancyCommonQueryParameters.generateIconImages ) {
return SecondMassVisibleControl.getIcon( 5.5, scene => {
scene.add( SecondMassVisibleControl.createBox( aMaterial, new Vector3( 0, 0, 0 ) ) );
return BlocksRadioButtonGroup.getIcon( 5.5, scene => {
scene.add( BlocksRadioButtonGroup.createBox( aMaterial, new Vector3( 0, 0, 0 ) ) );
} );
}
else {
Expand All @@ -182,9 +182,9 @@ class SecondMassVisibleControl extends RectangularRadioButtonGroup {
*/
static getDoubleCuboidIcon() {
if ( DensityBuoyancyCommonQueryParameters.generateIconImages ) {
return SecondMassVisibleControl.getIcon( 4, scene => {
scene.add( SecondMassVisibleControl.createBox( aMaterial, new Vector3( -0.039, 0.015, -0.07 ) ) );
scene.add( SecondMassVisibleControl.createBox( bMaterial, new Vector3( 0.03, -0.005, 0.07 ) ) );
return BlocksRadioButtonGroup.getIcon( 4, scene => {
scene.add( BlocksRadioButtonGroup.createBox( aMaterial, new Vector3( -0.039, 0.015, -0.07 ) ) );
scene.add( BlocksRadioButtonGroup.createBox( bMaterial, new Vector3( 0.03, -0.005, 0.07 ) ) );
} );
}
else {
Expand All @@ -193,5 +193,5 @@ class SecondMassVisibleControl extends RectangularRadioButtonGroup {
}
}

densityBuoyancyCommon.register( 'SecondMassVisibleControl', SecondMassVisibleControl );
export default SecondMassVisibleControl;
densityBuoyancyCommon.register( 'BlocksRadioButtonGroup', BlocksRadioButtonGroup );
export default BlocksRadioButtonGroup;
4 changes: 2 additions & 2 deletions js/common/view/PrimarySecondaryControlsNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class PrimarySecondaryControlsNode extends PrimarySecondaryPanelsNode {
labelNode: PrimarySecondaryPanelsNode.getPrimaryLabelNode(),
color: DensityBuoyancyCommonColors.labelAProperty,
visibleProperty: primaryMass.visibleProperty,
tandem: tandem.createTandem( 'primaryBlockControlNode' )
tandem: tandem.createTandem( 'blockAControlPanel' )
}, omittedOptions ) ),
new BlockControlNode( secondaryMass, popupLayer, merge( {
labelNode: PrimarySecondaryPanelsNode.getSecondaryLabelNode(),
color: DensityBuoyancyCommonColors.labelBProperty,
visibleProperty: secondaryMass.visibleProperty,
tandem: tandem.createTandem( 'secondaryBlockControlNode' )
tandem: tandem.createTandem( 'blockBControlPanel' )
}, omittedOptions ) )
);
}
Expand Down
12 changes: 6 additions & 6 deletions js/common/view/SecondaryMassScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import Vector3 from '../../../../dot/js/Vector3.js';
import densityBuoyancyCommon from '../../densityBuoyancyCommon.js';
import BlocksRadioButtonGroup from './BlocksRadioButtonGroup.js';
import DensityBuoyancyScreenView from './DensityBuoyancyScreenView.js';
import SecondMassVisibleControl from './SecondMassVisibleControl.js';

class SecondaryMassScreenView extends DensityBuoyancyScreenView {
/**
Expand All @@ -22,11 +22,11 @@ class SecondaryMassScreenView extends DensityBuoyancyScreenView {
assert && assert( this.rightBox, 'SecondaryMassScreenView requires a this.rightBox be defined to add this control' );

// @private {Node}
this.secondMassVisibleControl = new SecondMassVisibleControl( secondaryMassVisibleProperty, {
tandem: this.tandem.createTandem( 'secondMassVisibleControl' )
this.blocksRadioButtonGroup = new BlocksRadioButtonGroup( secondaryMassVisibleProperty, {
tandem: this.tandem.createTandem( 'blocksRadioButtonGroup' )
} );

this.addChild( this.secondMassVisibleControl );
this.addChild( this.blocksRadioButtonGroup );

// This instance lives for the lifetime of the simulation, so we don't need to remove this listener
this.rightBox.transformEmitter.addListener( () => this.positionSecondMassControl() );
Expand All @@ -38,12 +38,12 @@ class SecondaryMassScreenView extends DensityBuoyancyScreenView {
* @private
*/
positionSecondMassControl() {
this.secondMassVisibleControl.bottom = this.modelToViewPoint( new Vector3(
this.blocksRadioButtonGroup.bottom = this.modelToViewPoint( new Vector3(
0,
this.model.poolBounds.minY,
this.model.poolBounds.maxZ
) ).y;
this.secondMassVisibleControl.left = this.rightBox.left;
this.blocksRadioButtonGroup.left = this.rightBox.left;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions js/density/model/DensityExploreModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ class DensityExploreModel extends DensityBuoyancyModel {
canShowForces: false
}, options ) );

const blocksTandem = tandem.createTandem( 'blocks' );

// @public (read-only) {Mass}
this.primaryMass = Cuboid.createWithMass( this.engine, Material.WOOD, new Vector2( -0.2, 0.2 ), 2, {
tag: Mass.MassTag.PRIMARY,
tandem: tandem.createTandem( 'primaryMass' )
tandem: blocksTandem.createTandem( 'blockA' )
} );
this.availableMasses.push( this.primaryMass );
this.secondaryMass = Cuboid.createWithMass( this.engine, Material.ALUMINUM, new Vector2( -0.2, 0.35 ), 13.5, {
tag: Mass.MassTag.SECONDARY,
tandem: tandem.createTandem( 'secondaryMass' ),
tandem: blocksTandem.createTandem( 'blockB' ),
visible: false
} );
this.availableMasses.push( this.secondaryMass );
Expand Down
31 changes: 16 additions & 15 deletions js/density/model/DensityIntroModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ class DensityIntroModel extends BlockSetModel( DensityBuoyancyModel, BlockSet, B

const tandem = options.tandem;

const sameMassTandem = tandem.createTandem( 'sameMass' );
const sameVolumeTandem = tandem.createTandem( 'sameVolume' );
const sameDensityTandem = tandem.createTandem( 'sameDensity' );
const blockSetsTandem = tandem.createTandem( 'blockSets' );
const sameMassTandem = blockSetsTandem.createTandem( 'sameMass' );
const sameVolumeTandem = blockSetsTandem.createTandem( 'sameVolume' );
const sameDensityTandem = blockSetsTandem.createTandem( 'sameDensity' );

const massProperty = new NumberProperty( 5, {
range: new Range( 1, 10 ),
Expand Down Expand Up @@ -64,22 +65,22 @@ class DensityIntroModel extends BlockSetModel( DensityBuoyancyModel, BlockSet, B
Cuboid.createWithMass( model.engine, Material.createCustomMaterial( {
density: 500,
customColor: DensityBuoyancyCommonColors.comparingYellowColorProperty
} ), Vector2.ZERO, 5, { tandem: sameMassTandem.createTandem( 'yellowMass' ) } ),
} ), Vector2.ZERO, 5, { tandem: sameMassTandem.createTandem( 'yellowBlock' ) } ),

Cuboid.createWithMass( model.engine, Material.createCustomMaterial( {
density: 1000,
customColor: DensityBuoyancyCommonColors.comparingBlueColorProperty
} ), Vector2.ZERO, 5, { tandem: sameMassTandem.createTandem( 'blueMass' ) } ),
} ), Vector2.ZERO, 5, { tandem: sameMassTandem.createTandem( 'blueBlock' ) } ),

Cuboid.createWithMass( model.engine, Material.createCustomMaterial( {
density: 2000,
customColor: DensityBuoyancyCommonColors.comparingGreenColorProperty
} ), Vector2.ZERO, 5, { tandem: sameMassTandem.createTandem( 'greenMass' ) } ),
} ), Vector2.ZERO, 5, { tandem: sameMassTandem.createTandem( 'greenBlock' ) } ),

Cuboid.createWithMass( model.engine, Material.createCustomMaterial( {
density: 4000,
customColor: DensityBuoyancyCommonColors.comparingRedColorProperty
} ), Vector2.ZERO, 5, { tandem: sameMassTandem.createTandem( 'redMass' ) } )
} ), Vector2.ZERO, 5, { tandem: sameMassTandem.createTandem( 'redBlock' ) } )
];

// This instance lives for the lifetime of the simulation, so we don't need to remove this listener
Expand All @@ -97,22 +98,22 @@ class DensityIntroModel extends BlockSetModel( DensityBuoyancyModel, BlockSet, B
Cuboid.createWithMass( model.engine, Material.createCustomMaterial( {
density: 1600,
customColor: DensityBuoyancyCommonColors.comparingYellowColorProperty
} ), Vector2.ZERO, 8, { tandem: sameVolumeTandem.createTandem( 'yellowMass' ) } ),
} ), Vector2.ZERO, 8, { tandem: sameVolumeTandem.createTandem( 'yellowBlock' ) } ),

Cuboid.createWithMass( model.engine, Material.createCustomMaterial( {
density: 1200,
customColor: DensityBuoyancyCommonColors.comparingBlueColorProperty
} ), Vector2.ZERO, 6, { tandem: sameVolumeTandem.createTandem( 'blueMass' ) } ),
} ), Vector2.ZERO, 6, { tandem: sameVolumeTandem.createTandem( 'blueBlock' ) } ),

Cuboid.createWithMass( model.engine, Material.createCustomMaterial( {
density: 800,
customColor: DensityBuoyancyCommonColors.comparingGreenColorProperty
} ), Vector2.ZERO, 4, { tandem: sameVolumeTandem.createTandem( 'greenMass' ) } ),
} ), Vector2.ZERO, 4, { tandem: sameVolumeTandem.createTandem( 'greenBlock' ) } ),

Cuboid.createWithMass( model.engine, Material.createCustomMaterial( {
density: 400,
customColor: DensityBuoyancyCommonColors.comparingRedColorProperty
} ), Vector2.ZERO, 2, { tandem: sameVolumeTandem.createTandem( 'redMass' ) } )
} ), Vector2.ZERO, 2, { tandem: sameVolumeTandem.createTandem( 'redBlock' ) } )
];

// This instance lives for the lifetime of the simulation, so we don't need to remove this listener
Expand All @@ -133,22 +134,22 @@ class DensityIntroModel extends BlockSetModel( DensityBuoyancyModel, BlockSet, B
Cuboid.createWithMass( model.engine, Material.createCustomMaterial( {
density: 500,
customColor: DensityBuoyancyCommonColors.comparingYellowColorProperty
} ), Vector2.ZERO, 3, { tandem: sameDensityTandem.createTandem( 'yellowMass' ) } ),
} ), Vector2.ZERO, 3, { tandem: sameDensityTandem.createTandem( 'yellowBlock' ) } ),

Cuboid.createWithMass( model.engine, Material.createCustomMaterial( {
density: 500,
customColor: DensityBuoyancyCommonColors.comparingBlueColorProperty
} ), Vector2.ZERO, 2, { tandem: sameDensityTandem.createTandem( 'blueMass' ) } ),
} ), Vector2.ZERO, 2, { tandem: sameDensityTandem.createTandem( 'blueBlock' ) } ),

Cuboid.createWithMass( model.engine, Material.createCustomMaterial( {
density: 500,
customColor: DensityBuoyancyCommonColors.comparingGreenColorProperty
} ), Vector2.ZERO, 1, { tandem: sameDensityTandem.createTandem( 'greenMass' ) } ),
} ), Vector2.ZERO, 1, { tandem: sameDensityTandem.createTandem( 'greenBlock' ) } ),

Cuboid.createWithMass( model.engine, Material.createCustomMaterial( {
density: 500,
customColor: DensityBuoyancyCommonColors.comparingRedColorProperty
} ), Vector2.ZERO, 0.5, { tandem: sameDensityTandem.createTandem( 'redMass' ) } )
} ), Vector2.ZERO, 0.5, { tandem: sameDensityTandem.createTandem( 'redBlock' ) } )
];

// This instance lives for the lifetime of the simulation, so we don't need to remove this listener
Expand Down
Loading

0 comments on commit bdf684e

Please sign in to comment.