Skip to content

Commit

Permalink
Link alerts to mass changes, map radius difference to qualitative val…
Browse files Browse the repository at this point in the history
…ue, alert content getter added to string manager, see #109
  • Loading branch information
mbarlow12 committed Nov 29, 2018
1 parent 2c2fc85 commit db7b550
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
16 changes: 16 additions & 0 deletions js/gravity-force-lab/view/GravityForceLabAlertManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ define( require => {
this.alertScientificNotation( scientificNotation );
}
} );

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

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

alertScientificNotation( displayInScientificNotation ) {
Expand All @@ -62,6 +72,12 @@ define( require => {
const alert = this.stringManager.getMassControlFocusAlertText( objectEnum );
utteranceQueue.addToBack( alert );
}

alertMassValueChanged( value, oldValue ) {
const alert = this.stringManager.getMassValueChangedAlertText( value, oldValue );
const utterance = new Utterance( { alert, uniqueGroupId: 'massChanged' } );
utteranceQueue.addToBack( utterance );
}
}

return gravityForceLab.register( 'GravityForceLabAlertManager', GravityForceLabAlertManager );
Expand Down
1 change: 0 additions & 1 deletion js/gravity-force-lab/view/GravityForceLabScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ define( function( require ) {
GravityForceLabConstants.MASS_BLUE_COLOR,
{
onFocus: function( event ) {
console.log( 'from screenview', self);
self.alertManager.alertMassControlFocus( OBJECT_ONE );
}
},
Expand Down
41 changes: 32 additions & 9 deletions js/gravity-force-lab/view/GravityForceLabStringManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ define( require => {
let value;
if ( model.scientificNotationProperty.get() ) {
units = 'newtons';
value = ISLCStringManager.getForceInScientificNotation( forceValue, 4 );
value = ISLCStringManager.getForceInScientificNotation( forceValue, 2 );
}
else {
units = 'micronewtons';
Expand All @@ -85,9 +85,10 @@ define( require => {
super( model, object1Label, object2Label, options );

// @private
this._object1ToObject2Ratio = 0;
this._object2ToObject1Ratio = 0;

this._radiusDifference = 0;
this._object1MassGrowing = false;
this._object2MassGrowing = false;
this.formatMassValue = options.formatMassValue;
this.centerOffset = options.centerOffset;
this.formatPositionUnitMark = options.formatPositionUnitMark;
Expand All @@ -109,14 +110,21 @@ define( require => {
* TS noted in the design doc about using 'steps' instead of ratios
* this implies that I should take the actual difference between the two
* values
* One advantage is that I can simply use the sign of the value
*/
// this._object1ToObject2Ratio = r1 / r2;
// this._object2ToObject1Ratio = 1 / this._object1ToObject2Ratio;
// if r2 is larger than r1 then the value will be negative
this._objectDifference = m1 - m2;
this._objectMassDifference = m1 - m2;
}
);

model.object1.valueProperty.link( ( newMass, oldMass ) => {
this._object1MassGrowing = ( newMass - oldMass ) > 0;
} );

model.object2.valueProperty.link( ( newMass, oldMass ) => {
this._object2MassGrowing = ( newMass - oldMass ) > 0;
} );
}

/////////////////////
Expand Down Expand Up @@ -162,13 +170,28 @@ define( require => {
}

getMassControlFocusAlertText( objectEnum ) {
const pattern = '{{value}} kilograms, {{size}}, {{relativeSize}} {{otherObject}}';
const pattern = '{{massValue}}, {{size}}, {{relativeSize}} {{otherObject}}';
const thisObject = objectEnum === OBJECT_ONE ? this.object1 : this.object2;
const value = thisObject.valueProperty.get();
const size = this.getSizeOfMass( value );
const massValue = this.formatMassValue( thisObject.valueProperty.get() );
const size = this.getSizeOfMass( massValue );
const relativeSize = this.getObjectRelativeSize( objectEnum );
const otherObject = objectEnum === OBJECT_ONE ? this.object2Label : this.object1Label;
return StringUtils.fillIn( pattern, { value, size, relativeSize, otherObject } );
return StringUtils.fillIn( pattern, { massValue, size, relativeSize, otherObject } );
}

getMassValueChangedAlertText( newMass, oldMass ) {
let pattern = 'As mass {{massChange}}, vectors {{vectorChange}}.';
const objectIsGrowing = ( newMass - oldMass ) > 0;
const massChange = objectIsGrowing ? 'gets bigger' : 'gets smaller';
const vectorChange = objectIsGrowing ? 'get bigger' : 'get smaller';

const fillObject = { massChange, vectorChange };

if ( this.model.forceValuesProperty.get() ) {
pattern = 'As mass {{massChange}}, vectors {{vectorChange}}, forces now {{forceValue}}';
fillObject.forceValue = this.getForceValueText();
}
return StringUtils.fillIn( pattern, fillObject );
}

getSizeOfMass( massValue ) {
Expand Down

0 comments on commit db7b550

Please sign in to comment.