diff --git a/js/model/ISLCModel.js b/js/model/ISLCModel.js index d1f31cd..d6579d5 100644 --- a/js/model/ISLCModel.js +++ b/js/model/ISLCModel.js @@ -55,6 +55,10 @@ define( require => { this.object1 = object1; this.object2 = object2; + // set the appropriate enum reference to each object. + object1.enum = ISLCObjectEnum.OBJECT_ONE; + object2.enum = ISLCObjectEnum.OBJECT_TWO; + // @public // {Property.} - needed for adjusting alerts when an object moves as a result of a radius increase this.pushedObjectEnumProperty = new Property( null ); diff --git a/js/model/ISLCObject.js b/js/model/ISLCObject.js index 3f95787..eb8dfa5 100644 --- a/js/model/ISLCObject.js +++ b/js/model/ISLCObject.js @@ -15,6 +15,7 @@ define( require => { const inherit = require( 'PHET_CORE/inherit' ); const inverseSquareLawCommon = require( 'INVERSE_SQUARE_LAW_COMMON/inverseSquareLawCommon' ); const ISLCConstants = require( 'INVERSE_SQUARE_LAW_COMMON/ISLCConstants' ); + const ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' ); const NumberIO = require( 'TANDEM/types/NumberIO' ); const NumberProperty = require( 'AXON/NumberProperty' ); const Property = require( 'AXON/Property' ); @@ -77,7 +78,7 @@ define( require => { // @publiv (read-only) - Emitter that fires whenever the position changes as a result of an object's value changing. // Emits with the objectEnum that caused the position change. - this.valueChangedPositionEmitter = new Emitter( { validators: [ { valueType: 'string' } ] } ); + this.valueChangedPositionEmitter = new Emitter( { validators: [ { valueType: ISLCObjectEnum } ] } ); // @public - flag to check if the object is being dragged by the user // set in the drag handler @@ -88,6 +89,9 @@ define( require => { // @public this.valueRange = valueRange; + + // @public {ISLCObjectEnum} - filled in by the model + this.enum = null; } inverseSquareLawCommon.register( 'ISLCObject', ISLCObject ); diff --git a/js/view/ISLCObjectEnum.js b/js/view/ISLCObjectEnum.js index e367556..98734cb 100644 --- a/js/view/ISLCObjectEnum.js +++ b/js/view/ISLCObjectEnum.js @@ -9,14 +9,38 @@ define( require => { 'use strict'; // modules + const Enumeration = require( 'PHET_CORE/Enumeration' ); const inverseSquareLawCommon = require( 'INVERSE_SQUARE_LAW_COMMON/inverseSquareLawCommon' ); - const ISLCObjectEnum = { - OBJECT_ONE: 'object1', - OBJECT_TWO: 'object2' - }; + return inverseSquareLawCommon.register( 'ISLCObjectEnum', new Enumeration( [ + 'OBJECT_ONE', + 'OBJECT_TWO' + ], ISLCObjectEnum => { - if ( assert ) { Object.freeze( ISLCObjectEnum ); } + /** + * @param {ISLCObjectEnum} objectEnum + * @returns {ISLCObjectEnum} + */ + ISLCObjectEnum.getOtherObjectEnum = objectEnum => { + assert && assert( ISLCObjectEnum.includes( objectEnum ) ); + return objectEnum === ISLCObjectEnum.OBJECT_ONE ? ISLCObjectEnum.OBJECT_TWO : ISLCObjectEnum.OBJECT_ONE; + }; - return inverseSquareLawCommon.register( 'ISLCObjectEnum', ISLCObjectEnum ); + /** + * @public + * @param {ISLCObjectEnum} objectEnum + * @returns {boolean} + */ + ISLCObjectEnum.isObject1 = objectEnum => { + return objectEnum === ISLCObjectEnum.OBJECT_ONE; + }; + + /** + * @param {ISLCObjectEnum} objectEnum + * @returns {boolean} + */ + ISLCObjectEnum.isObject2 = objectEnum => { + return objectEnum === ISLCObjectEnum.OBJECT_TWO; + }; + } ) ); } ); \ No newline at end of file diff --git a/js/view/describers/ISLCDescriber.js b/js/view/describers/ISLCDescriber.js index 1ca3d7f..bd77a4e 100644 --- a/js/view/describers/ISLCDescriber.js +++ b/js/view/describers/ISLCDescriber.js @@ -12,15 +12,10 @@ define( require => { // modules const inverseSquareLawCommon = require( 'INVERSE_SQUARE_LAW_COMMON/inverseSquareLawCommon' ); - const ISLCA11yStrings = require( 'INVERSE_SQUARE_LAW_COMMON/ISLCA11yStrings' ); const ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' ); - const StringUtils = require( 'PHETCOMMON/util/StringUtils' ); - - // strings - const summaryInteractionHintPatternString = ISLCA11yStrings.summaryInteractionHintPattern.value; // constants - const { OBJECT_ONE, OBJECT_TWO } = ISLCObjectEnum; + const { OBJECT_ONE } = ISLCObjectEnum; class ISLCDescriber { @@ -39,29 +34,12 @@ define( require => { this.object2Label = object2Label; } - /** - * @public - * @param {ISLCObjectEnum} objectEnum - * @returns {boolean} - */ - isObject1( objectEnum ) { - return objectEnum === OBJECT_ONE; - } - - /** - * @public - * @param {ISLCObjectEnum} objectEnum - * @returns {boolean} - */ - isObject2( objectEnum ) { - return objectEnum === OBJECT_TWO; - } - /** * @param {ISLCObjectEnum} objectEnum * @returns {Mass} */ getObjectFromEnum( objectEnum ) { + assert && assert( ISLCObjectEnum.includes( objectEnum ) ); return objectEnum === OBJECT_ONE ? this.object1 : this.object2; } @@ -70,6 +48,7 @@ define( require => { * @returns {Mass} */ getOtherObjectFromEnum( objectEnum ) { + assert && assert( ISLCObjectEnum.includes( objectEnum ) ); return objectEnum === OBJECT_ONE ? this.object2 : this.object1; } @@ -78,6 +57,7 @@ define( require => { * @returns {string} */ getObjectLabelFromEnum( objectEnum ) { + assert && assert( ISLCObjectEnum.includes( objectEnum ) ); return objectEnum === OBJECT_ONE ? this.object1Label : this.object2Label; } @@ -86,40 +66,9 @@ define( require => { * @returns {string} */ getOtherObjectLabelFromEnum( objectEnum ) { + assert && assert( ISLCObjectEnum.includes( objectEnum ) ); return objectEnum === OBJECT_ONE ? this.object2Label : this.object1Label; } - - /** - * @param {ISLCObjectEnum} objectEnum - * @returns {ISLCObjectEnum} - */ - getOtherObjectEnum( objectEnum ) { - return objectEnum === OBJECT_ONE ? OBJECT_TWO : OBJECT_ONE; - } - - /** - * @public - * @param {ISLCObject} object - * @returns {boolean} - */ - getEnumFromObject( object ) { - return object === this.object1 ? OBJECT_ONE : - object === this.object2 ? OBJECT_TWO : - assert && assert( false, 'unrecognized ISLCObject' ); - } - - /** - * TODO: as of writing this is only used by GFL, should it be moved out of here? - * Static function to get interaction hint - * @param massOrCharge - * @returns {*|string} - */ - static getSummaryInteractionHint( massOrCharge ) { - return StringUtils.fillIn( - summaryInteractionHintPatternString, - { massOrCharge: massOrCharge } - ); - } } return inverseSquareLawCommon.register( 'ISLCDescriber', ISLCDescriber ); diff --git a/js/view/describers/PositionDescriber.js b/js/view/describers/PositionDescriber.js index 817f4ec..ce017c7 100644 --- a/js/view/describers/PositionDescriber.js +++ b/js/view/describers/PositionDescriber.js @@ -14,6 +14,7 @@ define( require => { const inverseSquareLawCommon = require( 'INVERSE_SQUARE_LAW_COMMON/inverseSquareLawCommon' ); const ISLCA11yStrings = require( 'INVERSE_SQUARE_LAW_COMMON/ISLCA11yStrings' ); const ISLCDescriber = require( 'INVERSE_SQUARE_LAW_COMMON/view/describers/ISLCDescriber' ); + const ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' ); const Property = require( 'AXON/Property' ); const StringProperty = require( 'AXON/StringProperty' ); const StringUtils = require( 'PHETCOMMON/util/StringUtils' ); @@ -277,10 +278,11 @@ define( require => { /** * Get the position change clause, like closer/farther strings. + * @param {ISLCObject} object * @returns {string|null} - null if there isn't a position progress or landmark clause */ getPositionProgressOrLandmarkClause( object ) { - const objectEnum = this.getEnumFromObject( object ); + const objectEnum = object.enum; let positionString = this.movedCloser ? closerString : fartherAwayString; @@ -297,7 +299,7 @@ define( require => { // objects touching each other else if ( this.objectTouchingBoundary( objectEnum ) ) { - positionString = this.isObject1( objectEnum ) ? lastStopRightString : lastStopLeftString; + positionString = ISLCObjectEnum.isObject1( objectEnum ) ? lastStopRightString : lastStopLeftString; } // No change, so if not covered by above edge cases, there shouldn't be a progress clause @@ -362,7 +364,7 @@ define( require => { * @returns {boolean} */ object1AtMin( objectEnum ) { - return this.isObject1( objectEnum ) && this.objectAtTouchingMin( objectEnum ); + return ISLCObjectEnum.isObject1( objectEnum ) && this.objectAtTouchingMin( objectEnum ); } /** @@ -370,7 +372,7 @@ define( require => { * @returns {boolean} */ object2AtMax( objectEnum ) { - return this.isObject2( objectEnum ) && this.objectAtTouchingMax( objectEnum ); + return ISLCObjectEnum.isObject2( objectEnum ) && this.objectAtTouchingMax( objectEnum ); } @@ -438,10 +440,10 @@ define( require => { * @returns {string} */ getEdgeFromObjectEnum( objectEnum ) { - if ( this.objectAtTouchingMin( objectEnum ) && this.isObject1( objectEnum ) ) { + if ( this.objectAtTouchingMin( objectEnum ) && ISLCObjectEnum.isObject1( objectEnum ) ) { return leftString; } - else if ( this.objectAtTouchingMax( objectEnum ) && this.isObject2( objectEnum ) ) { + else if ( this.objectAtTouchingMax( objectEnum ) && ISLCObjectEnum.isObject2( objectEnum ) ) { return rightString; } else {