Skip to content

Commit

Permalink
Refactor and delete MassNodeDescriber, move code into MassPDOMNode ty…
Browse files Browse the repository at this point in the history
…pes; documentation; removed unused parameters, phetsims/gravity-force-lab-basics#134
  • Loading branch information
zepumph committed Jun 11, 2019
1 parent 05ed441 commit a0da258
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 150 deletions.
59 changes: 52 additions & 7 deletions js/gravity-force-lab/view/MassPDOMNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ define( require => {

// modules
const gravityForceLab = require( 'GRAVITY_FORCE_LAB/gravityForceLab' );
const GravityForceLabA11yStrings = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/GravityForceLabA11yStrings' );
const ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' );
const ISLCObjectPDOMNode = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectPDOMNode' );
const MassNodeDescriber = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/view/describers/MassNodeDescriber' );
const Node = require( 'SCENERY/nodes/Node' );
const StringUtils = require( 'PHETCOMMON/util/StringUtils' );

// strings
const mass1AbbreviatedString = require( 'string!GRAVITY_FORCE_LAB/mass1Abbreviated' );
const mass2AbbreviatedString = require( 'string!GRAVITY_FORCE_LAB/mass2Abbreviated' );

// a11y strings
const sizeAndPositionPatternString = GravityForceLabA11yStrings.sizeAndPositionPattern.value;
const redSpherePatternString = GravityForceLabA11yStrings.redSpherePattern.value;
const blueSpherePatternString = GravityForceLabA11yStrings.blueSpherePattern.value;

// constants
const { OBJECT_ONE } = ISLCObjectEnum;

class MassPDOMNode extends ISLCObjectPDOMNode {

/**
Expand All @@ -33,19 +43,23 @@ define( require => {
// mass/position dynamic description for this Mass. This function will be called bound to "this" before calling.
wireUpMassAndPositionUpdates: () => {
model.forceProperty.link( () => {
this.massAndPositionNode.innerContent = this.nodeDescriber.getSizeAndPositionItemText();
this.massAndPositionNode.innerContent = this.getSizeAndPositionItemText();
} );
}
}, options );

const nodeDescriber = new MassNodeDescriber( model, objectEnum, massDescriber, positionDescriber, options );
options.labelContent = nodeDescriber.getMassSphereString();

super( model, objectEnum, options );


// @protected
this.nodeDescriber = nodeDescriber;
this.objectEnum = objectEnum; // {ISLCObjectEnum}
this.mass = massDescriber.getObjectFromEnum( objectEnum ); // {ISLCObject}
this.massLabel = massDescriber.getObjectLabelFromEnum( objectEnum ); // {string}
this.positionDescriber = positionDescriber; // {PositionDescriber}
this.massDescriber = massDescriber; // {MassDescriber}

// set the accessibleName after member fields have been initialized
this.labelContent = this.getMassSphereString();

this.massAndPositionNode = new Node( { tagName: 'li' } );

this.addChild( this.massAndPositionNode );
Expand All @@ -67,6 +81,37 @@ define( require => {
} );
}
}

/**
* @returns {string}
* @protected
*/
getMassValue() {
return this.massDescriber.getFormattedMass( this.mass.valueProperty.get() );
}

/**
* @returns {string}
* @private
*/
getSizeAndPositionItemText() {
return StringUtils.fillIn( sizeAndPositionPatternString, {
thisObjectLabel: this.massLabel,
size: this.massDescriber.getMassSize( this.mass.valueProperty.get() ),
massValue: this.getMassValue(),
position: this.positionDescriber.getConvertedPositionFromEnum( this.objectEnum ),
unit: this.positionDescriber.unit
} );
}

/**
* @returns {string}
* @private
*/
getMassSphereString() {
const pattern = this.objectEnum === OBJECT_ONE ? blueSpherePatternString : redSpherePatternString;
return StringUtils.fillIn( pattern, { objectLabel: this.massLabel } );
}
}

return gravityForceLab.register( 'MassPDOMNode', MassPDOMNode );
Expand Down
9 changes: 9 additions & 0 deletions js/gravity-force-lab/view/SpherePositionsPDOMNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ define( require => {
descriptionContent: spherePositionHelpTextString
}, options ) );
}

/**
* Provide a thin layer for api similarity between REGULAR and BASICS
* @param {string} description
* @public
*/
setDescription( description ) {
this.descriptionContent = description;
}
}

return gravityForceLab.register( 'SpherePositionsPDOMNode', SpherePositionsPDOMNode );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ define( require => {
super( model, object1Label, object2Label, options );
}

// @override
/**
* @param {number} distance
* @returns {number}
* @protected
*/
getDistanceIndex( distance ) {
assert && assert( distance > 0, 'Distance between spheres should always be positive.' );

Expand Down
142 changes: 0 additions & 142 deletions js/gravity-force-lab/view/describers/MassNodeDescriber.js

This file was deleted.

0 comments on commit a0da258

Please sign in to comment.