Skip to content

Commit

Permalink
remove todo/method in ISLCDescriber, ISLCObjectEnum to be Enumeration…
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jun 11, 2019
1 parent ab27ae5 commit 8a99f01
Showing 5 changed files with 52 additions and 69 deletions.
4 changes: 4 additions & 0 deletions js/model/ISLCModel.js
Original file line number Diff line number Diff line change
@@ -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.<ISLCObjectEnum|null>} - needed for adjusting alerts when an object moves as a result of a radius increase
this.pushedObjectEnumProperty = new Property( null );
6 changes: 5 additions & 1 deletion js/model/ISLCObject.js
Original file line number Diff line number Diff line change
@@ -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 );
36 changes: 30 additions & 6 deletions js/view/ISLCObjectEnum.js
Original file line number Diff line number Diff line change
@@ -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;
};
} ) );
} );
61 changes: 5 additions & 56 deletions js/view/describers/ISLCDescriber.js
Original file line number Diff line number Diff line change
@@ -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 );
14 changes: 8 additions & 6 deletions js/view/describers/PositionDescriber.js
Original file line number Diff line number Diff line change
@@ -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,15 +364,15 @@ define( require => {
* @returns {boolean}
*/
object1AtMin( objectEnum ) {
return this.isObject1( objectEnum ) && this.objectAtTouchingMin( objectEnum );
return ISLCObjectEnum.isObject1( objectEnum ) && this.objectAtTouchingMin( objectEnum );
}

/**
* @param {ISLCObjectEnum} objectEnum
* @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 {

1 comment on commit 8a99f01

@zepumph
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.