Skip to content

Commit

Permalink
got through all the easy errors (mostly that don't have to do with co…
Browse files Browse the repository at this point in the history
…mmon code) 79 left, #404
  • Loading branch information
zepumph committed Oct 21, 2021
1 parent 8999552 commit a488ed6
Show file tree
Hide file tree
Showing 20 changed files with 183 additions and 80 deletions.
32 changes: 20 additions & 12 deletions js/common/view/RAPScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,29 @@ const RATIO_HALF_SPACING = 10;
// area on the right.
const RATIO_SECTION_WIDTH = 2 / 3;

const uiScaleFunction = new LinearFunction( LAYOUT_BOUNDS.height, MAX_RATIO_HEIGHT, 1, 1.5, true );
const uiPositionFunction = new LinearFunction( 1, 1.5, LAYOUT_BOUNDS.height * 0.15, -LAYOUT_BOUNDS.height * 0.2, true );
type LinearFunctionType = ( x: number ) => number

const uiScaleFunction = new LinearFunction( LAYOUT_BOUNDS.height, MAX_RATIO_HEIGHT, 1, 1.5, true ) as LinearFunctionType;
const uiPositionFunction = new LinearFunction( 1, 1.5, LAYOUT_BOUNDS.height * 0.15, -LAYOUT_BOUNDS.height * 0.2, true ) as LinearFunctionType;

class RAPScreenView extends ScreenView {

protected tickMarkViewProperty: Property<TickMarkViewType>;
protected tickMarkViewProperty: EnumerationProperty<TickMarkViewType>;
protected tickMarkRangeProperty: NumberProperty;
protected readonly ratioDescriber: RatioDescriber;
handPositionsDescriber: HandPositionsDescriber;
private antecedentRatioHalf: RatioHalf;
private consequentRatioHalf: RatioHalf;
markerInput: RAPMarkerInput | null;
inProportionSoundGenerator: InProportionSoundGenerator;
movingInProportionSoundGenerator: MovingInProportionSoundGenerator;
staccatoFrequencySoundGenerator: StaccatoFrequencySoundGenerator;
private markerInput: RAPMarkerInput | null;
private inProportionSoundGenerator: InProportionSoundGenerator;
private movingInProportionSoundGenerator: MovingInProportionSoundGenerator;
private staccatoFrequencySoundGenerator: StaccatoFrequencySoundGenerator;

protected topScalingUILayerNode: Node;
protected bottomScalingUILayerNode: Node;
protected resetAllButton: ResetAllButton;
protected tickMarkViewRadioButtonGroup: TickMarkViewRadioButtonGroup;
private layoutRAPScreeView: ( b: Bounds2 ) => void

/**
* @param {RAPModel} model
Expand Down Expand Up @@ -130,7 +138,7 @@ class RAPScreenView extends ScreenView {
// A collection of properties that keep track of which cues should be displayed for both the antecedent and consequent hands.
const cueArrowsState = new CueArrowsState();

const tickMarksAndLabelsColorProperty = new DerivedProperty( [ model.ratioFitnessProperty ],
const tickMarksAndLabelsColorProperty: DerivedProperty<Color> = new DerivedProperty( [ model.ratioFitnessProperty ],
( fitness: number ) => Color.interpolateRGBA(
RAPColors.tickMarksAndLabelsOutOfFitnessProperty.value,
RAPColors.tickMarksAndLabelsInFitnessProperty.value, fitness
Expand Down Expand Up @@ -299,7 +307,7 @@ class RAPScreenView extends ScreenView {
Property.multilink( [
model.ratioFitnessProperty,
model.inProportionProperty
], ( fitness, inProportion ) => {
], ( fitness: number, inProportion: boolean ) => {
let color = null;
if ( inProportion ) {
color = RAPColors.backgroundInFitnessProperty.value;
Expand Down Expand Up @@ -425,7 +433,7 @@ class RAPScreenView extends ScreenView {
* @override
* @public
*/
layout( viewBounds ) {
layout( viewBounds: Bounds2 ) {
this.resetTransform();

const scale = this.getLayoutScale( viewBounds );
Expand Down Expand Up @@ -472,9 +480,9 @@ class RAPScreenView extends ScreenView {
* @public
* @param {number} dt
*/
step( dt ) {
step( dt: number ) {

this.markerInput && this.markerInput.step( dt );
this.markerInput && this.markerInput.step();
this.inProportionSoundGenerator.step( dt );
this.staccatoFrequencySoundGenerator.step( dt );
}
Expand Down
6 changes: 3 additions & 3 deletions js/common/view/RAPTickMarkLabelsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RAPTickMarkLabelsNode extends Node {
* @param {Object} [options]
*/
constructor( tickMarkViewProperty: Property<TickMarkViewType>, tickMarkRangeProperty: Property<number>, height: number,
colorProperty: Property<Color>, options?: any ) {
colorProperty: Property<Color | string>, options?: any ) {

if ( options ) {
assert && assert( !options.hasOwnProperty( 'children' ), 'RAPTickMarkLabelsNode sets its own children' );
Expand Down Expand Up @@ -64,13 +64,13 @@ class RAPTickMarkLabelsNode extends Node {
*/
get labelHeight() {
assert && assert( this.heightOfText, 'cannot get labelHeight until labels have been drawn' );
return this.heightOfText;
return this.heightOfText as number;
}

/**
* @public
*/
layout( height:number ) {
layout( height: number ) {

this.totalHeight = height;
this.update( this.tickMarkRangeProperty.value, this.tickMarkViewProperty.value );
Expand Down
19 changes: 18 additions & 1 deletion js/common/view/describers/BothHandsDescriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,26 @@
import StringUtils from '../../../../../phetcommon/js/util/StringUtils.js';
import ratioAndProportion from '../../../ratioAndProportion.js';
import ratioAndProportionStrings from '../../../ratioAndProportionStrings.js';
import Property from '../../../../../axon/js/Property.js';
import RAPRatioTuple from '../../model/RAPRatioTuple.js';
import Range from '../../../../../dot/js/Range.js';
import RatioDescriber from './RatioDescriber.js';
import HandPositionsDescriber from './HandPositionsDescriber.js';
import { TickMarkViewType } from '../TickMarkView.js';

const ratioDistancePositionContextResponsePatternString = ratioAndProportionStrings.a11y.ratio.distancePositionContextResponse;

class BothHandsDescriber {

private ratioTupleProperty: Property<RAPRatioTuple>;
private enabledRatioTermsRangeProperty: Property<Range>;
private tickMarkViewProperty: Property<TickMarkViewType>;
private ratioDescriber: RatioDescriber;
private handPositionsDescriber: HandPositionsDescriber;
private ratioLockedProperty: Property<boolean>;
private previousAntecedentAtExtremity: boolean;
private previousConsequentAtExtremity: boolean;

/**
* @param {Property.<RAPRatioTuple>} ratioTupleProperty
* @param {Property.<Range>} enabledRatioTermsRangeProperty
Expand All @@ -23,7 +38,9 @@ class BothHandsDescriber {
* @param {RatioDescriber} ratioDescriber
* @param {HandPositionsDescriber} handPositionsDescriber
*/
constructor( ratioTupleProperty, enabledRatioTermsRangeProperty, ratioLockedProperty, tickMarkViewProperty, ratioDescriber, handPositionsDescriber ) {
constructor( ratioTupleProperty: Property<RAPRatioTuple>, enabledRatioTermsRangeProperty: Property<Range>,
ratioLockedProperty: Property<boolean>, tickMarkViewProperty: Property<TickMarkViewType>,
ratioDescriber: RatioDescriber, handPositionsDescriber: HandPositionsDescriber ) {

// @private - from model
this.ratioTupleProperty = ratioTupleProperty;
Expand Down
28 changes: 19 additions & 9 deletions js/common/view/describers/HandPositionsDescriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import ratioAndProportion from '../../../ratioAndProportion.js';
import ratioAndProportionStrings from '../../../ratioAndProportionStrings.js';
import RatioTerm from '../../model/RatioTerm.js';
import rapConstants from '../../rapConstants.js';
import TickMarkView from '../TickMarkView.js';
import TickMarkView, { TickMarkViewType } from '../TickMarkView.js';
import Property from '../../../../../axon/js/Property';
import RAPRatioTuple from '../../model/RAPRatioTuple.js';
import TickMarkDescriber from './TickMarkDescriber.js';

// constants
const leftHandLowerString = ratioAndProportionStrings.a11y.leftHandLower;
Expand Down Expand Up @@ -63,11 +66,16 @@ const TOTAL_RANGE = rapConstants.TOTAL_RATIO_TERM_VALUE_RANGE;

class HandPositionsDescriber {

private ratioTupleProperty: Property<RAPRatioTuple>;
private tickMarkDescriber: TickMarkDescriber;
private previousDistanceRegion: null | string;
private previousDistance: number;

/**
* @param {Property.<RAPRatioTuple>} ratioTupleProperty
* @param {TickMarkDescriber} tickMarkDescriber
*/
constructor( ratioTupleProperty, tickMarkDescriber ) {
constructor( ratioTupleProperty: Property<RAPRatioTuple>, tickMarkDescriber: TickMarkDescriber ) {

// @private - from model
this.ratioTupleProperty = ratioTupleProperty;
Expand All @@ -87,7 +95,7 @@ class HandPositionsDescriber {
* @param {boolean} useOfPlayArea - whether the position should end with "of Play Area", like "at bottom of Play Area"
* @returns {string}
*/
getHandPositionDescription( position, tickMarkView, useOfPlayArea = true ) {
getHandPositionDescription( position: number, tickMarkView: TickMarkViewType, useOfPlayArea = true ) {
if ( TickMarkView.describeQualitative( tickMarkView ) ) {
const qualitativeHandPosition = this.getQualitativePosition( position );
return !useOfPlayArea ? qualitativeHandPosition : StringUtils.fillIn( ratioAndProportionStrings.a11y.ofPlayAreaPattern, {
Expand All @@ -105,7 +113,7 @@ class HandPositionsDescriber {
* @param {boolean} semiQuantitative=false
* @returns {string}
*/
getQuantitativeHandPosition( handPosition, semiQuantitative = false ) {
getQuantitativeHandPosition( handPosition: number, semiQuantitative = false ) {
const tickMarkData = this.tickMarkDescriber.getRelativePositionAndTickMarkNumberForPosition( handPosition );

// semi quantitative description uses ordinal numbers instead of full numbers.
Expand All @@ -127,7 +135,7 @@ class HandPositionsDescriber {
* @returns {string} - the qualitative position
* @private
*/
getQualitativePosition( position ) {
getQualitativePosition( position: number ) {
assert && assert( TOTAL_RANGE.contains( position ), 'position expected to be in position range' );

const normalizedPosition = TOTAL_RANGE.getNormalizedValue( position );
Expand Down Expand Up @@ -163,7 +171,7 @@ class HandPositionsDescriber {

assert && assert( index !== null, 'should have been in one of these regions' );

return QUALITATIVE_POSITIONS[ index ];
return QUALITATIVE_POSITIONS[ index as number ];
}

/**
Expand Down Expand Up @@ -206,6 +214,8 @@ class HandPositionsDescriber {
else if ( distance === 0 ) {
index = 9;
}
assert && assert( index !== null );
index = index as number;
assert && assert( index < DISTANCE_REGIONS_CAPITALIZED.length, 'out of range' );
return ( lowercase ? DISTANCE_REGIONS_LOWERCASE : DISTANCE_REGIONS_CAPITALIZED )[ index ];
}
Expand All @@ -215,8 +225,8 @@ class HandPositionsDescriber {
* @param {RatioTerm} ratioTerm - which ratio term is this for? Antecedent or consequent
* @returns {string}
*/
getSingleHandDistance( ratioTerm ) {
assert && assert( RatioTerm.includes( ratioTerm ), 'unsupported RatioTerm' );
getSingleHandDistance( ratioTerm: RatioTerm ) {
assert && assert( typeof RatioTerm[ ratioTerm ] === 'number', 'unsupported RatioTerm' );
const otherHand = ratioTerm === RatioTerm.ANTECEDENT ? rightHandLowerString : leftHandLowerString;

const distanceRegion = this.getDistanceRegion();
Expand Down Expand Up @@ -285,7 +295,7 @@ class HandPositionsDescriber {
* @param {Object} [options]
* @returns {string|null} - null if no change
*/
getDistanceProgressString( options ) {
getDistanceProgressString( options?: any ) {
options = merge( {
closerString: ratioAndProportionStrings.a11y.handPosition.closerTo,
fartherString: ratioAndProportionStrings.a11y.handPosition.fartherFrom
Expand Down
24 changes: 17 additions & 7 deletions js/common/view/describers/RatioDescriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import sceneryPhetStrings from '../../../../../scenery-phet/js/sceneryPhetString
import ratioAndProportion from '../../../ratioAndProportion.js';
import ratioAndProportionStrings from '../../../ratioAndProportionStrings.js';
import rapConstants from '../../rapConstants.js';
import Property from '../../../../../axon/js/Property.js';
import RAPModel from '../../model/RAPModel.js';

// constants
const RATIO_FITNESS_STRINGS_CAPITALIZED = [
Expand Down Expand Up @@ -52,14 +54,20 @@ const NUMBER_TO_WORD = [
// an unclamped fitness of 0 should map to "somewhatCloseTo" region
const ZERO_FITNESS_REGION_INDEX = 4;

type LinearFunctionType = ( x: number ) => number;

assert && assert( RATIO_FITNESS_STRINGS_LOWERCASE.length === RATIO_FITNESS_STRINGS_CAPITALIZED.length, 'should be the same length' );

class RatioDescriber {

private ratioFitnessProperty: Property<number>;
private unclampedFitnessProperty: Property<number>;
private model: RAPModel;

/**
* @param {RAPModel} model
*/
constructor( model ) {
constructor( model: RAPModel ) {

// @private - from model
this.ratioFitnessProperty = model.ratioFitnessProperty;
Expand All @@ -77,6 +85,8 @@ class RatioDescriber {
* @returns {string}
*/
getRatioFitness( capitalized = true ) {

// @ts-ignore
assert && assert( ZERO_FITNESS_REGION_INDEX !== 0, 'should not be first index' );

const lastIndex = RATIO_FITNESS_STRINGS_CAPITALIZED.length - 1;
Expand All @@ -92,9 +102,9 @@ class RatioDescriber {
// normalize based on the fitness that is not in proportion
const normalizedMax = rapConstants.RATIO_FITNESS_RANGE.max - this.model.getInProportionThreshold();

const lessThanZeroMapping = new LinearFunction( this.model.getMinFitness(), rapConstants.RATIO_FITNESS_RANGE.min, 0, ZERO_FITNESS_REGION_INDEX - 1, true );
const greaterThanZeroMapping = new LinearFunction( rapConstants.RATIO_FITNESS_RANGE.min, normalizedMax,
ZERO_FITNESS_REGION_INDEX, lastIndex, true );
const lessThanZeroMapping = <LinearFunctionType>( new LinearFunction( this.model.getMinFitness(), rapConstants.RATIO_FITNESS_RANGE.min, 0, ZERO_FITNESS_REGION_INDEX - 1, true ) );
const greaterThanZeroMapping = <LinearFunctionType>( new LinearFunction( rapConstants.RATIO_FITNESS_RANGE.min, normalizedMax,
ZERO_FITNESS_REGION_INDEX, lastIndex, true ) );

const unclampedFitness = this.unclampedFitnessProperty.value;

Expand Down Expand Up @@ -129,7 +139,7 @@ class RatioDescriber {
* @param {number} consequent
* @returns {string}
*/
getCurrentChallengeSentence( antecedent, consequent ) {
getCurrentChallengeSentence( antecedent: number, consequent: number ) {
return StringUtils.fillIn( ratioAndProportionStrings.a11y.ratio.currentChallenge, {
targetAntecedent: antecedent,
targetConsequent: consequent
Expand All @@ -142,7 +152,7 @@ class RatioDescriber {
* @param {number} consequent
* @returns {string}
*/
getTargetRatioChangeAlert( antecedent, consequent ) {
getTargetRatioChangeAlert( antecedent: number, consequent: number ) {
return StringUtils.fillIn( ratioAndProportionStrings.a11y.ratio.targetRatioChangedContextResponse, {
proximityToRatio: this.getProximityToNewChallengeRatioSentence(),
currentChallenge: this.getCurrentChallengeSentence( antecedent, consequent )
Expand All @@ -154,7 +164,7 @@ class RatioDescriber {
* @param {number} number
* @returns {string}
*/
getWordFromNumber( number ) {
getWordFromNumber( number: number ) {
assert && assert( Number.isInteger( number ) );
assert && assert( NUMBER_TO_WORD.length > number );
return NUMBER_TO_WORD[ number ];
Expand Down
10 changes: 7 additions & 3 deletions js/common/view/describers/TickMarkDescriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import Utils from '../../../../../dot/js/Utils.js';
import ratioAndProportion from '../../../ratioAndProportion.js';
import ratioAndProportionStrings from '../../../ratioAndProportionStrings.js';
import rapConstants from '../../rapConstants.js';
import TickMarkView from '../TickMarkView.js';
import TickMarkView, { TickMarkViewType } from '../TickMarkView.js';
import Property from '../../../../../axon/js/Property';

// constants
const ORDINAL_TICK_MARKS = [
Expand Down Expand Up @@ -53,11 +54,14 @@ const TOTAL_RANGE = rapConstants.TOTAL_RATIO_TERM_VALUE_RANGE;

class TickMarkDescriber {

private tickMarkRangeProperty: Property<number>;
private tickMarkViewProperty: Property<TickMarkViewType>;

/**
* @param {Property.<number>} tickMarkRangeProperty
* @param {Property.<TickMarkView>} tickMarkViewProperty
*/
constructor( tickMarkRangeProperty, tickMarkViewProperty ) {
constructor( tickMarkRangeProperty: Property<number>, tickMarkViewProperty: Property<TickMarkViewType> ) {

// @private
this.tickMarkRangeProperty = tickMarkRangeProperty;
Expand All @@ -72,7 +76,7 @@ class TickMarkDescriber {
* @param {number} handPosition
* @returns {{tickMarkPosition: number|"zero", relativePosition: string , ordinalPosition: string|null }}
*/
getRelativePositionAndTickMarkNumberForPosition( handPosition ) {
getRelativePositionAndTickMarkNumberForPosition( handPosition: number ) {
assert && assert( TOTAL_RANGE.contains( handPosition ) );

// account for javascript rounding error, don't use rapConstants because we only want to handle rounding trouble.
Expand Down
6 changes: 3 additions & 3 deletions js/common/view/sound/StaccatoFrequencySoundGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ const staccatoSounds = [
[ gSound, g001Sound, g002Sound ]
];

type LinearFunctionStub = ( x: number ) => number;
type LinearFunctionType = ( x: number ) => number;

class StaccatoFrequencySoundGenerator extends SoundGenerator {


private inProportionProperty: Property<boolean>;
private fitnessProperty: Property<number>;
private staccatoSoundClips: SoundClip[][];
private timeLinearFunction: LinearFunctionStub;
private timeLinearFunction: LinearFunctionType;
private timeSinceLastPlay: number;

/**
Expand Down Expand Up @@ -102,7 +102,7 @@ class StaccatoFrequencySoundGenerator extends SoundGenerator {
fitnessRange.max,
500,
120,
true ) as LinearFunctionStub;
true ) as LinearFunctionType;

// @private - in ms, keep track of the amount of time that has passed since the last staccato sound played
this.timeSinceLastPlay = 0;
Expand Down
Loading

0 comments on commit a488ed6

Please sign in to comment.