Skip to content

Commit

Permalink
fix pushed alerts on mass increase, and remove unused code, phetsims/…
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Feb 20, 2019
1 parent e81c4fb commit c6fdb4f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 105 deletions.
86 changes: 17 additions & 69 deletions js/gravity-force-lab/view/GravityForceLabAlertManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ define( require => {
// modules
const gravityForceLab = require( 'GRAVITY_FORCE_LAB/gravityForceLab' );
const GravityForceLabA11yStrings = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/GravityForceLabA11yStrings' );
const GravityForceLabPositionDescriber = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/view/describers/GravityForceLabPositionDescriber' );
const ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' );
const ISLCAlertManager = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCAlertManager' );
const MassDescriber = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/view/describers/MassDescriber' );
Expand All @@ -21,7 +20,6 @@ define( require => {
// a11y strings
const constantRadiusThinkDensityPatternString = GravityForceLabA11yStrings.constantRadiusThinkDensityPattern.value;
const massAndForceClausesPatternString = GravityForceLabA11yStrings.massAndForceClausesPattern.value;
const massSizeRelativeSizePatternString = GravityForceLabA11yStrings.massSizeRelativeSizePattern.value;

// constants
const { OBJECT_ONE, OBJECT_TWO } = ISLCObjectEnum;
Expand Down Expand Up @@ -59,18 +57,18 @@ define( require => {
}
} );

model.object1.valueProperty.lazyLink( ( value, oldValue ) => {
model.object1.valueProperty.lazyLink( () => {
utteranceQueue.clear();
this.alertMassValueChanged( OBJECT_ONE, value, oldValue );
this.alertMassValueChanged( OBJECT_ONE );
} );

model.object2.valueProperty.lazyLink( ( value, oldValue ) => {
model.object2.valueProperty.lazyLink( () => {
utteranceQueue.clear();
this.alertMassValueChanged( OBJECT_TWO, value, oldValue );
this.alertMassValueChanged( OBJECT_TWO );
} );
}

alertScientificNotation( displayInScientificNotation ) {
alertScientificNotation() {
const alert = this.forceDescriber.getScientificNotationAlertText();
const utterance = new Utterance( { alert: alert, uniqueGroupId: 'scientificNotation' } );
utteranceQueue.addToBack( utterance );
Expand All @@ -82,13 +80,8 @@ define( require => {
utteranceQueue.addToBack( utterance );
}

alertMassControlFocus( objectEnum ) {
const alert = this.massDescriber.getMassControlFocusAlertText( objectEnum );
utteranceQueue.addToBack( alert );
}

alertMassValueChanged( objectEnum, value, oldValue ) {
const alert = this.getMassValueChangedAlertText( objectEnum, value, oldValue );
alertMassValueChanged( objectEnum ) {
const alert = this.getMassValueChangedAlertText( objectEnum );
const utterance = new Utterance( { alert: alert, uniqueGroupId: 'massChanged' } );
utteranceQueue.addToBack( utterance );
}
Expand All @@ -106,48 +99,19 @@ define( require => {
this.alertPositionSliderFocused();
}

// alertPositionChanged( endAtEdge ) {
// const alert = this.getPositionChangedAlertText( endAtEdge );
// const utterance = new Utterance( { alert, uniqueGroupId: 'position' } );
// utteranceQueue.addToBack( utterance );
// }
//
// alertPositionUnchanged() {
// const alert = this.getPositionUnchangedAlertText();
// const utterance = new Utterance( { alert, uniqueGroupId: 'position' } );
// utteranceQueue.addToBack( utterance );
// }

/**
* Returns the filled-in string, '{{massValue}} kilograms, {{size}}, {{relativeSize}} {{otherObjectLabel}}'
*
* @param {ISLCObjectEnum} objectEnum
* Get the value text for when the mass changes for a given object
* @param {ISLCObjectEnum} objectEnum
* @returns {string}
*/
getMassControlFocusAlertText( objectEnum ) {
const massAndUnit = this.massDescriber.getMassAndUnit( objectEnum );
const thisObjectMass = this.massDescriber.getObjectFromEnum( objectEnum ).valueProperty.get();
const size = this.massDescriber.getMassSize( thisObjectMass );
const relativeSize = this.massDescriber.getMassRelativeSize( objectEnum );
const otherObjectLabel = this.massDescriber.getOtherObjectLabelFromEnum( objectEnum );
return StringUtils.fillIn( massSizeRelativeSizePatternString, {
massAndUnit: massAndUnit,
size: size,
relativeSize: relativeSize,
otherObjectLabel: otherObjectLabel
} );
}

getMassValueChangedAlertText( objectEnum, newMass, oldMass ) {
// TODO: this function is called before the position property is updated and sets pushedMassEnum, we'll need to compare
// the two mass values against the current positions to see if one will be pushed.
const positionDescriber = GravityForceLabPositionDescriber.getDescriber();
getMassValueChangedAlertText( objectEnum ) {

let massClause = this.massDescriber.getMassChangeClause( objectEnum );

if ( positionDescriber.massPushed ) {
// if changing the mass of an object caused one of the masses to move position
if ( this.model.massWasPushed() ) {
massClause = this.massDescriber.getMassChangesAndMovesClause( objectEnum );
if ( positionDescriber.pushedMassEnum !== objectEnum ) {
if ( this.model.pushedObjectEnumProperty.value !== objectEnum ) {
massClause = this.massDescriber.getMassChangesAndMovesOtherClause( objectEnum );
}
}
Expand All @@ -158,28 +122,12 @@ define( require => {
forceClause = this.forceDescriber.getVectorChangeForcesNowClause();
}

return StringUtils.fillIn( massAndForceClausesPatternString, { massClause: massClause, forceClause: forceClause } );
return StringUtils.fillIn( massAndForceClausesPatternString, {
massClause: massClause,
forceClause: forceClause
} );
}

// getPositionChangedAlertText( endAtEdge ) {
// let alertText = this.forceDescriber.getVectorChangeText();
// let edgeAlertText = this.forceDescriber.getVectorSizeText();
//
// if ( this.model.forceValuesProperty.get() ) {
// alertText = this.forceDescriber.getVectorChangeForcesNowText();
// edgeAlertText = this.forceDescriber.getVectorSizeForceValueText();
// }
//
// return endAtEdge ? edgeAlertText : alertText;
// }
//
// getPositionUnchangedAlertText() {
// const positionDescriber = GravityForceLabPositionDescriber.getDescriber();
// const forceClause = this.forceDescriber.getVectorsAndForcesClause();
// const region = positionDescriber.qualitativeDistance;
// return StringUtils.fillIn( regionForceClausePatternString, { region, forceClause } );
// }

static getManager() {
return ISLCAlertManager.getManager();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,9 @@ define( require => {

// modules
const gravityForceLab = require( 'GRAVITY_FORCE_LAB/gravityForceLab' );
const ISLCA11yStrings = require( 'INVERSE_SQUARE_LAW_COMMON/ISLCA11yStrings' );
const ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' );
const PositionDescriber = require( 'INVERSE_SQUARE_LAW_COMMON/view/describers/PositionDescriber' );
// const StringUtils = require( 'PHETCOMMON/util/StringUtils' );
const Util = require( 'DOT/Util' );

// strings
const leftString = ISLCA11yStrings.left.value;
const rightString = ISLCA11yStrings.right.value;

// constants
const { OBJECT_ONE, OBJECT_TWO } = ISLCObjectEnum;

// let describer = null;

class GravityForceLabPositionDescriber extends PositionDescriber {

constructor( model, object1Label, object2Label, options ) {
Expand All @@ -30,26 +18,6 @@ define( require => {
}, options );

super( model, object1Label, object2Label, options );

// @public
this.pushedMassEnum = null;

this.object1.positionProperty.lazyLink( position => {
this.pushedMassEnum = this.object1.isDragging ? null : OBJECT_ONE;
} );

this.object2.positionProperty.lazyLink( position => {
this.pushedMassEnum = this.object2.isDragging ? null : OBJECT_TWO;
} );
}

get massPushed() {
return this.pushedMassEnum !== null;
}

get pushedMassDirection() {
assert && assert( this.pushedMassEnum !== null, 'cannot get pushedMassDirection when pushedMassEnum is null' );
return this.pushedMassEnum === OBJECT_ONE ? leftString : rightString;
}

// @override
Expand Down Expand Up @@ -93,7 +61,6 @@ define( require => {
static getDescriber() {
// assert && assert( describer, 'describer has not yet been initialized' );
return PositionDescriber.getDescriber();
// return describer;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions js/gravity-force-lab/view/describers/MassDescriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ define( require => {
/**
* Each object can only be pushed in one direction. Returns 'left' or 'right' based on the object passed in.
*
* @param {ISLCObjectEnum} pushedMassEnum
* @param {ISLCObjectEnum} objectEnum
* @returns {string}
*/
getPushDirection( pushedMassEnum ) {
return pushedMassEnum === OBJECT_ONE ? leftString : rightString;
getPushDirection( objectEnum ) {
return objectEnum === OBJECT_ONE ? leftString : rightString;
}

getSizeFromIndex( index ) {
Expand Down

0 comments on commit c6fdb4f

Please sign in to comment.