Skip to content

Commit

Permalink
add force alert when constant radius is turned off, add support for c…
Browse files Browse the repository at this point in the history
…apilization in ForceDescriber.getVectorChangeClause, phetsims/gravity-force-lab-basics#168
  • Loading branch information
zepumph committed Aug 20, 2019
1 parent d632fb1 commit e959191
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions js/gravity-force-lab/GravityForceLabA11yStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ define( require => {
value: 'As {{changeDirectionPhrase}} and moves {{otherObjectLabel}} {{leftOrRight}}'
},

sentencePattern: {
value: '{{sentence}}.'
},

// relative mass sizes
muchMuchSmallerThan: {
value: 'much much smaller than'
Expand Down
27 changes: 24 additions & 3 deletions js/gravity-force-lab/view/GravityForceLabAlertManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ define( require => {
// a11y strings
const constantRadiusThinkDensityPatternString = GravityForceLabA11yStrings.constantRadiusThinkDensityPattern.value;
const massAndForceClausesPatternString = GravityForceLabA11yStrings.massAndForceClausesPattern.value;
const sentencePatternString = GravityForceLabA11yStrings.sentencePattern.value;

class GravityForceLabAlertManager extends ISLCAlertManager {

Expand Down Expand Up @@ -90,8 +91,18 @@ define( require => {
// When the value changes position, the position will change after the valueProperty has, so link a listener to
// alert one the positions are correct, this is important to get the alerts like
// "mass 1 get's bigger and moves mass 2 right"
model.object1.valueChangedPositionEmitter.addListener( objectEnum => this.alertMassValueChanged( objectEnum, true ) );
model.object2.valueChangedPositionEmitter.addListener( objectEnum => this.alertMassValueChanged( objectEnum, true ) );
const secondaryPositionChangedListener = objectEnum => {

// handle the case where the position changed from the constant radius being toggled
if ( model.object1.constantRadiusChangedSinceLastStep || model.object2.constantRadiusChangedSinceLastStep ) {
this.alertConstantSizeChangedPosition();
}
else { // value specific assumption
this.alertMassValueChanged( objectEnum, true );
}
};
model.object1.positionChangedFromSecondarySourceEmitter.addListener( secondaryPositionChangedListener );
model.object2.positionChangedFromSecondarySourceEmitter.addListener( secondaryPositionChangedListener );
}

/**
Expand Down Expand Up @@ -123,7 +134,17 @@ define( require => {

this.massChangedUtterance.alert = StringUtils.fillIn( massAndForceClausesPatternString, {
massClause: massClause,
forceClause: this.forceDescriber.getVectorChangeClause( forceBiggerOverride )
forceClause: this.forceDescriber.getVectorChangeClause( forceBiggerOverride, false )
} );
utteranceQueue.addToBack( this.massChangedUtterance );
}

/**
* @private
*/
alertConstantSizeChangedPosition() {
this.massChangedUtterance.alert = StringUtils.fillIn( sentencePatternString, {
sentence: this.forceDescriber.getVectorChangeClause( false, true )
} );
utteranceQueue.addToBack( this.massChangedUtterance );
}
Expand Down

0 comments on commit e959191

Please sign in to comment.