Skip to content

Commit

Permalink
improve inheritance for string manager type, new string content, add …
Browse files Browse the repository at this point in the history
…string processing methods to ISLCStringManager, see phetsims/gravity-force-lab#109
  • Loading branch information
mbarlow12 committed Oct 21, 2018
1 parent 30a67f8 commit 40e06f1
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 0 deletions.
9 changes: 9 additions & 0 deletions inverse-square-law-common-strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@
"mass2": {
"value": "Mass 2"
},
"mass": {
"value": "mass"
},
"pattern_0value_1units": {
"value": "{{value}} {{units}}"
},
"scientificNotation": {
"value": "Scientific Notation"
},
"units.meters": {
"value": "meters"
},
"units.newtons": {
"value": "newtons"
},
"units.picometers": {
"value": "pm"
},
Expand Down
88 changes: 88 additions & 0 deletions js/ISLCA11yStrings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright 2017-2018, University of Colorado Boulder

define( require => {
'use strict';

// modules
const inverseSquareLawCommon = require( 'INVERSE_SQUARE_LAW_COMMON/inverseSquareLawCommon' );

const ISLCA11yStrings = {

/////////////////////
// Pattern Strings //
/////////////////////

vectorSizePattern: {
value: 'Force vectors are {{size}}.'
},
vectorSizeValueUnitsPattern: {
value: 'Force vectors are {{size}} at {{objectValue}} {{units}}.'
},
robotPullSummaryPattern: {
value: 'Robots {{pullAmount}} keeping spheres in place.'
},
summaryInteractionHintPattern: {
value: 'Move spheres or change their {{massOrCharge}} to begin observations.'
},
distanceSpaceAndValueSummaryPattern: {
value: '{{object1Label}} and {{object2Label}} are {{distance}} each other, exactly {{distanceValue}} {{units}} apart.'
},

////////////////////////
// Qualitative Values //
////////////////////////

// force vector and mass object size
tiny: {
value: 'tiny'
},
verySmall: {
value: 'very small'
},
small: {
value: 'small'
},
mediumSize: {
value: 'medium size'
},
large: {
value: 'large'
},
veryLarge: {
value: 'very large'
},
huge: {
value: 'huge'
},

// distance between objects/spheres
extremelyFarFrom: {
value: 'extremely far from'
},
veryFarFrom: {
value: 'very far from'
},
notSoFarFrom: {
value: 'not so far from'
},
somewhatCloseTo: {
value: 'somewhat close to'
},
closeTo: {
value: 'close to'
},
veryCloseTo: {
value: 'very close to'
},
nextTo: {
value: 'next to'
},
rightNextTo: {
value: 'right next to'
}
};

if ( assert ) { Object.freeze( ISLCA11yStrings ); }

return inverseSquareLawCommon.register( 'ISLCA11yStrings', ISLCA11yStrings );
} );
94 changes: 94 additions & 0 deletions js/view/ISLCStringManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2017-2018, University of Colorado Boulder

define( require => {
'use strict';

// modules
const inverseSquareLawCommon = require( 'INVERSE_SQUARE_LAW_COMMON/inverseSquareLawCommon' );
const ISLCA11yStrings = require( 'INVERSE_SQUARE_LAW_COMMON/ISLCA11yStrings' );
// const LinearFunction = require( 'DOT/LinearFunction' );
const StringUtils = require( 'PHETCOMMON/util/StringUtils' );
const Util = require( 'DOT/Util' );

// strings
const massString = require( 'string!INVERSE_SQUARE_LAW_COMMON/mass' );
const unitsMetersString = require( 'string!INVERSE_SQUARE_LAW_COMMON/units.meters' );
const unitsNewtonsString = require( 'string!INVERSE_SQUARE_LAW_COMMON/units.newtons' );

const vectorSizePatternString = ISLCA11yStrings.vectorSizePattern.value;
const vectorSizeValueUnitsPatternString = ISLCA11yStrings.vectorSizeValueUnitsPattern.value;
const summaryInteractionHintPatternString = ISLCA11yStrings.summaryInteractionHintPattern.value;

const tinyString = ISLCA11yStrings.tiny.value;
const verySmallString = ISLCA11yStrings.verySmall.value;
const smallString = ISLCA11yStrings.small.value;
const mediumSizeString = ISLCA11yStrings.mediumSize.value;
const largeString = ISLCA11yStrings.large.value;
const veryLargeString = ISLCA11yStrings.veryLarge.value;
const hugeString = ISLCA11yStrings.huge.value;
const sizeStrings = [ tinyString, verySmallString, smallString, mediumSizeString,
largeString, veryLargeString, hugeString ];

class ISLCStringManager {
constructor( model, options ) {

options = _.extend( {
modelValue: massString,
valueUnits: unitsNewtonsString,
distanceUnits: unitsMetersString,
valueUnitConversion: 1
}, options );

// @private
this._modelValue = options.modelValue;
this._distanceUnits = options.distanceUnits;
this._valueUnits = options.valueUnits;
this._valueUnitConversion = options.valueUnitConversion;
this._vectorSizeIndex = 0;

// @protected
this.model = model;

model.forceProperty.link( force => {
this._vectorSizeIndex = this.getForceVectorIndex( force );
} );
}

/////////////////////
// Summary Strings //
/////////////////////

getSummaryInteractionHint() {
return StringUtils.fillIn(
summaryInteractionHintPatternString,
{ massOrCharge: this._modelValue }
);
}

getForceVectorsSummaryText() {
const fillObject = {};
const pattern = this.model.forceValuesProperty.get() ?
vectorSizeValueUnitsPatternString :
vectorSizePatternString;

fillObject.size = sizeStrings[ this._vectorSizeIndex ];

if ( this.model.forceValuesProperty.get() ) {
fillObject.units = this._valueUnits;
fillObject.objectValue = Util.toFixedNumber( this.model.forceProperty.get() * this._valueUnitConversion, 7 );
}

return StringUtils.fillIn( pattern, fillObject );
}

// getObjectDistanceSummary() {
// return distanceSpaceAndValueSummaryPatternString;
// }

getForceVectorIndex( force ) {
throw new Error( 'getForceVectorIndex must be implemented in subtypes' );
}
}

return inverseSquareLawCommon.register( 'ISLCStringManager', ISLCStringManager );
} );

0 comments on commit 40e06f1

Please sign in to comment.