Skip to content

Commit

Permalink
GravityForceLabRulerDescriber to extend ISLCDescriber, add hotkey ale…
Browse files Browse the repository at this point in the history
…rts, #138
  • Loading branch information
zepumph committed Nov 11, 2019
1 parent 608ffe8 commit e9212c0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
3 changes: 3 additions & 0 deletions js/gravity-force-lab/GravityForceLabA11yStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ define( require => {
centersApartPattern: {
value: 'Centers of spheres {{distanceAndUnits}} apart.'
},
jumpCenterMassAlert: {
value: 'Ruler zero mark at center of {{object1}}. {{centersApart}}'
},

// vertical ruler positions
coveringM2: {
Expand Down
4 changes: 2 additions & 2 deletions js/gravity-force-lab/view/GravityForceLabScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ define( require => {
this.layoutBounds.bottom
];

const rulerDescriber = new GravityForceLabRulerDescriber( model.rulerPositionProperty, modelViewTransform,
rulerRegionPositions, positionDescriber );
const rulerDescriber = new GravityForceLabRulerDescriber( model, mass1AbbreviatedString, mass2AbbreviatedString,
modelViewTransform, rulerRegionPositions, positionDescriber );

// @private - added to object for animation stepping
const gravityForceLabRuler = new ISLCRulerNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ define( require => {
// modules
const gravityForceLab = require( 'GRAVITY_FORCE_LAB/gravityForceLab' );
const GravityForceLabA11yStrings = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/GravityForceLabA11yStrings' );
const ISLCDescriber = require( 'INVERSE_SQUARE_LAW_COMMON/view/describers/ISLCDescriber' );
const ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' );
const ISLCQueryParameters = require( 'INVERSE_SQUARE_LAW_COMMON/ISLCQueryParameters' );
const Range = require( 'DOT/Range' );
const StringUtils = require( 'PHETCOMMON/util/StringUtils' );
Expand All @@ -23,6 +25,7 @@ define( require => {
const moveKeyboardHintString = GravityForceLabA11yStrings.moveKeyboardHint.value;
const gestureHintString = GravityForceLabA11yStrings.gestureHint.value;
const keyboardReleaseHintString = GravityForceLabA11yStrings.keyboardReleaseHint.value;
const jumpCenterMassAlertString = GravityForceLabA11yStrings.jumpCenterMassAlert.value;

const coveringM2String = GravityForceLabA11yStrings.coveringM2.value;
const coveringM1String = GravityForceLabA11yStrings.coveringM1.value;
Expand All @@ -47,20 +50,24 @@ define( require => {
RULER_VERTICAL_REGIONS.indexOf( justBelowCentersString ) );
const SHOW_RULER_REGIONS = ISLCQueryParameters.showRulerRegions;

class GravityForceLabRulerDescriber {
class GravityForceLabRulerDescriber extends ISLCDescriber {

/**
* @param {Property.<number>} rulerPositionProperty
* @param {GravityForceLabModel} model
* @param {string} object1Label
* @param {string} object2Label
* @param {ModelViewTransform2} modelViewTransform
* @param {Array.<number>} viewYPositions - a list of Y positions, least (top) to greatest (bottom)
* @param {PositionDescriber} positionDescriber
*/
constructor( rulerPositionProperty, modelViewTransform, viewYPositions, positionDescriber ) {
constructor( model, object1Label, object2Label, modelViewTransform, viewYPositions, positionDescriber ) {

assert && assert( RULER_VERTICAL_REGIONS.length === viewYPositions.length, 'Unexpected number of y positions' );

super( model, object1Label, object2Label );

// @private
this.rulerPositionProperty = rulerPositionProperty;
this.rulerPositionProperty = model.rulerPositionProperty;
this.modelViewTransform = modelViewTransform;
this.positionDescriber = positionDescriber;
this.viewYPositions = viewYPositions;
Expand Down Expand Up @@ -143,6 +150,27 @@ define( require => {
return RULER_VERTICAL_REGIONS[ this.getVerticalRegionIndex() ];
}

/**
* Get current vertical position when in home position. Should only be called when the ruler is currently in home
* position.
*/
getHomePositionString() {
const currentRegion = this.getCurrentVerticalRegion();
assert && assert( currentRegion === inHomePositionString, 'getHomePositionString called when ruler not in home position' );
return currentRegion;
}

/**
* @public
* @returns {string}
*/
getJumpCenterMassAlert() {
return StringUtils.fillIn( jumpCenterMassAlertString, {
centersApart: this.getCentersApartDistance(),
object1: this.getObjectLabelFromEnum( ISLCObjectEnum.OBJECT_ONE )
} );
}

/**
* @public
*/
Expand Down

0 comments on commit e9212c0

Please sign in to comment.