Skip to content

Commit

Permalink
Addressed REVIEW: Refactor usage of ForcesModeChoice enumeration. phe…
Browse files Browse the repository at this point in the history
  • Loading branch information
Denz1994 committed Jan 30, 2019
1 parent bc54651 commit 55b1b6f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
9 changes: 6 additions & 3 deletions js/common/model/MassesAndSpringsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ define( function( require ) {
var Body = require( 'MASSES_AND_SPRINGS/common/model/Body' );
var BodyIO = require( 'MASSES_AND_SPRINGS/common/model/BodyIO' );
var BooleanProperty = require( 'AXON/BooleanProperty' );
var ForcesModeChoice = require( 'MASSES_AND_SPRINGS/common/enum/ForcesModeChoice' );
var Enumeration = require( 'PHET_CORE/Enumeration' );
var inherit = require( 'PHET_CORE/inherit' );
var LinearFunction = require( 'DOT/LinearFunction' );
var Mass = require( 'MASSES_AND_SPRINGS/common/model/Mass' );
Expand Down Expand Up @@ -45,6 +45,9 @@ define( function( require ) {
// Flag used to differentiate basics and non-basics version
this.basicsVersion = false;

// @public {Enumeration}
this.forcesModeChoice = new Enumeration( [ 'FORCES', 'NET_FORCES' ] );

// @public {Property.<boolean>} determines whether the sim is in a play/pause state
this.playingProperty = new BooleanProperty( true, {
tandem: tandem.createTandem( 'playingProperty' )
Expand Down Expand Up @@ -137,10 +140,10 @@ define( function( require ) {
} );

// @public {Property.<string>} determines mode of the vectors to be viewed
this.forcesModeProperty = new Property( ForcesModeChoice.FORCES, {
this.forcesModeProperty = new Property( this.forcesModeChoice.FORCES, {
tandem: tandem.createTandem( 'forcesModeProperty' ),
phetioType: PropertyIO( StringIO ),
validValues: [ ForcesModeChoice.FORCES, ForcesModeChoice.NET_FORCES ]
validValues: [ this.forcesModeChoice.FORCES, this.forcesModeChoice.NET_FORCES ]
} );

// @public {Spring[]} Array that will contain all of the springs.
Expand Down
7 changes: 3 additions & 4 deletions js/common/view/MassNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ define( function( require ) {
var Bounds2 = require( 'DOT/Bounds2' );
var Color = require( 'SCENERY/util/Color' );
var DerivedProperty = require( 'AXON/DerivedProperty' );
var ForcesModeChoice = require( 'MASSES_AND_SPRINGS/common/enum/ForcesModeChoice' );
var ForceVectorArrow = require( 'MASSES_AND_SPRINGS/common/view/ForceVectorArrow' );
var inherit = require( 'PHET_CORE/inherit' );
var Line = require( 'SCENERY/nodes/Line' );
Expand Down Expand Up @@ -260,7 +259,7 @@ define( function( require ) {
var updateForceVisibility = function( arrowVisibilityProperty, arrowNode ) {
Property.multilink( [ mass.springProperty, arrowVisibilityProperty, model.forcesModeProperty ],
function( spring, springVectorVisibility, forcesMode ) {
arrowNode.visible = !!spring && springVectorVisibility && forcesMode === ForcesModeChoice.FORCES;
arrowNode.visible = !!spring && springVectorVisibility && forcesMode === model.forcesModeChoice.FORCES;
} );
};

Expand All @@ -279,7 +278,7 @@ define( function( require ) {
// Show/hide the net force arrow
Property.multilink( [ mass.springProperty, model.forcesModeProperty ],
function( spring, forcesMode ) {
netForceArrow.visible = !!spring && forcesMode === ForcesModeChoice.NET_FORCES;
netForceArrow.visible = !!spring && forcesMode === model.forcesModeChoice.NET_FORCES;
} );

// Show/hide line at base of vectors
Expand All @@ -290,7 +289,7 @@ define( function( require ) {
model.forcesModeProperty
],
function( spring, gravityForceVisible, springForceVisible, forcesMode ) {
forceNullLine.visible = !!spring && ( gravityForceVisible || springForceVisible || forcesMode === ForcesModeChoice.NET_FORCES );
forceNullLine.visible = !!spring && ( gravityForceVisible || springForceVisible || forcesMode === model.forcesModeChoice.NET_FORCES );
} );

/**
Expand Down
9 changes: 4 additions & 5 deletions js/vectors/view/VectorVisibilityControlNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ define( function( require ) {
var AlignBox = require( 'SCENERY/nodes/AlignBox' );
var AlignGroup = require( 'SCENERY/nodes/AlignGroup' );
var AquaRadioButton = require( 'SUN/AquaRadioButton' );
var ForcesModeChoice = require( 'MASSES_AND_SPRINGS/common/enum/ForcesModeChoice' );
var ForceVectorArrow = require( 'MASSES_AND_SPRINGS/common/view/ForceVectorArrow' );
var HBox = require( 'SCENERY/nodes/HBox' );
var inherit = require( 'PHET_CORE/inherit' );
Expand Down Expand Up @@ -152,7 +151,7 @@ define( function( require ) {
// responsible for forces aquaRadioButton
var forcesVisibilityRadioButton = new AquaRadioButton(
model.forcesModeProperty,
ForcesModeChoice.FORCES,
model.forcesModeChoice.FORCES,
new Text( forcesString, {
font: MassesAndSpringsConstants.TITLE_FONT,
maxWidth: MAX_WIDTH,
Expand All @@ -169,18 +168,18 @@ define( function( require ) {
} ), { group: alignGroup, xAlign: 'left' } );
var netForceVisibilityRadioButton = new AquaRadioButton(
model.forcesModeProperty,
ForcesModeChoice.NET_FORCES,
model.forcesModeChoice.NET_FORCES,
new HBox( { children: [ netForceAlignBox, netForceArrow ], spacing: CONTENT_SPACING } ),
{ radius: 7, spacing: 7 }
);

// manages the mutability of the forces checkboxes dependent on the forces and net force aquaRadioButton
model.forcesModeProperty.link( function( mode ) {
if ( mode === ForcesModeChoice.FORCES ) {
if ( mode === model.forcesModeChoice.FORCES ) {
forcesVisibilityCheckboxGroup.pickable = true;
forcesVisibilityCheckboxGroup.opacity = 1;
}
else if ( mode === ForcesModeChoice.NET_FORCES ) {
else if ( mode === model.forcesModeChoice.NET_FORCES ) {
forcesVisibilityCheckboxGroup.pickable = false;
forcesVisibilityCheckboxGroup.opacity = 0.3;
}
Expand Down

0 comments on commit 55b1b6f

Please sign in to comment.