-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve inheritance for string manager type, new string content, add …
…string processing methods to ISLCStringManager, see phetsims/gravity-force-lab#109
- Loading branch information
Showing
3 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} ); |