From e9212c0c11b40de0ddf31b3e84ff000f825895b4 Mon Sep 17 00:00:00 2001 From: zepumph Date: Mon, 11 Nov 2019 12:39:34 -0900 Subject: [PATCH] GravityForceLabRulerDescriber to extend ISLCDescriber, add hotkey alerts, https://github.com/phetsims/gravity-force-lab/issues/138 --- .../GravityForceLabA11yStrings.js | 3 ++ .../view/GravityForceLabScreenView.js | 4 +-- .../GravityForceLabRulerDescriber.js | 36 ++++++++++++++++--- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/js/gravity-force-lab/GravityForceLabA11yStrings.js b/js/gravity-force-lab/GravityForceLabA11yStrings.js index 4650648c..ac5a6a2c 100644 --- a/js/gravity-force-lab/GravityForceLabA11yStrings.js +++ b/js/gravity-force-lab/GravityForceLabA11yStrings.js @@ -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: { diff --git a/js/gravity-force-lab/view/GravityForceLabScreenView.js b/js/gravity-force-lab/view/GravityForceLabScreenView.js index a14ed193..60e84bb6 100644 --- a/js/gravity-force-lab/view/GravityForceLabScreenView.js +++ b/js/gravity-force-lab/view/GravityForceLabScreenView.js @@ -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( diff --git a/js/gravity-force-lab/view/describers/GravityForceLabRulerDescriber.js b/js/gravity-force-lab/view/describers/GravityForceLabRulerDescriber.js index 4de65578..6a134d3c 100644 --- a/js/gravity-force-lab/view/describers/GravityForceLabRulerDescriber.js +++ b/js/gravity-force-lab/view/describers/GravityForceLabRulerDescriber.js @@ -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' ); @@ -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; @@ -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.} rulerPositionProperty + * @param {GravityForceLabModel} model + * @param {string} object1Label + * @param {string} object2Label * @param {ModelViewTransform2} modelViewTransform * @param {Array.} 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; @@ -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 */