Skip to content

Commit

Permalink
Rename arrays, see #160
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Apr 28, 2023
1 parent b32f862 commit ad4c33c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
31 changes: 15 additions & 16 deletions js/common/model/CAVModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export type CAVModelOptions = SelfOptions;
const TIME_BETWEEN_RAPID_KICKS = 0.5; // in seconds

export default class CAVModel implements TModel {
public readonly soccerBallGroup: CAVObject[];
public readonly soccerBallGroupCountProperty: NumberProperty;
public readonly soccerBalls: CAVObject[];
public readonly soccerBallCountProperty: NumberProperty;

public readonly isShowingTopMeanProperty: BooleanProperty;
public readonly isShowingTopMedianProperty: BooleanProperty;
Expand Down Expand Up @@ -92,12 +92,11 @@ export default class CAVModel implements TModel {

const updateDataMeasures = () => this.updateDataMeasures();

// TODO: Rename to soccerBalls
this.soccerBallGroupCountProperty = new NumberProperty( 0, {
this.soccerBallCountProperty = new NumberProperty( 0, {
range: new Range( 0, this.maxNumberOfObjects )
} );

this.soccerBallGroup = _.range( 0, this.maxNumberOfObjects ).map( index => {
this.soccerBalls = _.range( 0, this.maxNumberOfObjects ).map( index => {

const y0 = CAVObjectType.SOCCER_BALL.radius;
const position = new Vector2( 0, y0 );
Expand Down Expand Up @@ -142,9 +141,9 @@ export default class CAVModel implements TModel {
return soccerBall;
} );

this.soccerBallGroup.forEach( soccerBall => {
this.soccerBalls.forEach( soccerBall => {
soccerBall.isActiveProperty.link( isActive => {
this.soccerBallGroupCountProperty.value = this.getActiveSoccerBalls().length;
this.soccerBallCountProperty.value = this.getActiveSoccerBalls().length;
} );
} );

Expand Down Expand Up @@ -214,8 +213,8 @@ export default class CAVModel implements TModel {

this.numberOfUnkickedBallsProperty = DerivedProperty.deriveAny( [
this.numberOfScheduledSoccerBallsToKickProperty,
...this.soccerBallGroup.map( soccerBall => soccerBall.valueProperty ),
...this.soccerBallGroup.map( soccerBall => soccerBall.animationModeProperty ) ], () => {
...this.soccerBalls.map( soccerBall => soccerBall.valueProperty ),
...this.soccerBalls.map( soccerBall => soccerBall.animationModeProperty ) ], () => {

const kickedSoccerBalls = this.getActiveSoccerBalls().filter(
soccerBall => soccerBall.valueProperty.value !== null ||
Expand Down Expand Up @@ -257,7 +256,7 @@ export default class CAVModel implements TModel {
} );
} );

this.soccerBallGroup.forEach( soccerBall => {
this.soccerBalls.forEach( soccerBall => {
soccerBall.valueProperty.link( updateDataMeasures );
soccerBall.positionProperty.link( updateDataMeasures );
} );
Expand All @@ -272,7 +271,7 @@ export default class CAVModel implements TModel {
const sortedObjects = this.getSortedLandedObjects();
const medianObjects = CAVModel.getMedianObjectsFromSortedArray( sortedObjects );

this.soccerBallGroup.forEach( object => {
this.soccerBalls.forEach( object => {
object.isMedianObjectProperty.value = medianObjects.includes( object );
} );

Expand Down Expand Up @@ -302,7 +301,7 @@ export default class CAVModel implements TModel {
* Returns all other objects at the target position of the provided object.
*/
public getOtherObjectsAtTarget( cavObject: CAVObject ): CAVObject[] {
return this.soccerBallGroup.filter( ( o: CAVObject ) => {
return this.soccerBalls.filter( ( o: CAVObject ) => {
return o.valueProperty.value === cavObject.valueProperty.value && cavObject !== o;
} );
}
Expand Down Expand Up @@ -335,7 +334,7 @@ export default class CAVModel implements TModel {
this.timeWhenLastBallWasKickedProperty.reset();

this.soccerPlayers.forEach( soccerPlayer => soccerPlayer.reset() );
this.soccerBallGroup.forEach( soccerBall => soccerBall.reset() );
this.soccerBalls.forEach( soccerBall => soccerBall.reset() );
this.getNextBallFromPool();

this.activeKickerIndexProperty.reset();
Expand Down Expand Up @@ -405,7 +404,7 @@ export default class CAVModel implements TModel {
const elapsedTime = this.timeProperty.value - frontPlayer.timestampWhenPoisedBegan!;
if ( elapsedTime > 0.075 ) {

const soccerBall = this.soccerBallGroup.find( soccerBall =>
const soccerBall = this.soccerBalls.find( soccerBall =>
soccerBall.valueProperty.value === null &&
soccerBall.isActiveProperty.value &&
soccerBall.animationModeProperty.value === AnimationMode.NONE
Expand Down Expand Up @@ -464,7 +463,7 @@ export default class CAVModel implements TModel {
}

public getActiveSoccerBalls(): CAVObject[] {
return this.soccerBallGroup.filter( soccerBall => soccerBall.isActiveProperty.value );
return this.soccerBalls.filter( soccerBall => soccerBall.isActiveProperty.value );
}

/**
Expand Down Expand Up @@ -556,7 +555,7 @@ export default class CAVModel implements TModel {
}

private getNextBallFromPool(): CAVObject | null {
const nextBallFromPool = this.soccerBallGroup.find( ball => !ball.isActiveProperty.value ) || null;
const nextBallFromPool = this.soccerBalls.find( ball => !ball.isActiveProperty.value ) || null;
if ( nextBallFromPool ) {
nextBallFromPool.isActiveProperty.value = true;
}
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/CAVPlotNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class CAVPlotNode extends Node {

// TODO: This overlaps with draggingEnabled
const dotPlotObjectNodesDraggableProperty = new BooleanProperty( false );
model.soccerBallGroup.forEach( ( soccerBall, index ) => {
model.soccerBalls.forEach( ( soccerBall, index ) => {

// TODO: This should be new DataPointNode
const dotNode = new CAVObjectNode( soccerBall, model.isShowingTopMedianProperty, modelViewTransform, dotPlotObjectNodesDraggableProperty, {
Expand Down
10 changes: 5 additions & 5 deletions js/common/view/CAVScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ export default class CAVScreenView extends ScreenView {
tandem: objectNodeGroupTandem.createTandem( 'inputEnabledProperty' )
} );

model.soccerBallGroup.map( ( soccerBall, index ) => {
model.soccerBalls.map( ( soccerBall, index ) => {
const soccerBallNode = new CAVObjectNode( soccerBall, model.isShowingPlayAreaMedianProperty, modelViewTransform, objectNodesInputEnabledProperty, {
fill: null, // Only depict as a soccer ball
tandem: options.tandem.createTandem( 'soccerBallGroup' ).createTandem( 'soccerBallNode' + index )
tandem: options.tandem.createTandem( 'soccerBalls' ).createTandem( 'soccerBallNode' + index )
} );

this.backObjectLayer.addChild( soccerBallNode );
Expand All @@ -117,9 +117,9 @@ export default class CAVScreenView extends ScreenView {

// add the dragIndicatorArrowNode above the last object when it is added to the play area. if an object was
// moved before this happens, don't show the dragIndicatorArrowNode
if ( model.soccerBallGroupCountProperty.value === this.model.physicalRange.max &&
if ( model.soccerBallCountProperty.value === this.model.physicalRange.max &&
objectNodesInputEnabledProperty.value &&
_.every( model.soccerBallGroup, cavObject => cavObject.valueProperty.value !== null ) &&
_.every( model.soccerBalls, cavObject => cavObject.valueProperty.value !== null ) &&
!objectHasBeenDragged ) {
dragIndicatorArrowNode.centerX = this.modelViewTransform.modelToViewX( value );

Expand Down Expand Up @@ -165,7 +165,7 @@ export default class CAVScreenView extends ScreenView {
if ( visible ) {

// if there is a ball at that location, go above the ball
const ballsAtLocation = model.soccerBallGroup.filter( cavObject => cavObject.valueProperty.value === medianValue );
const ballsAtLocation = model.soccerBalls.filter( cavObject => cavObject.valueProperty.value === medianValue );
const modelHeight = ballsAtLocation.length * CAVObjectType.SOCCER_BALL.radius * 2; // assumes no spacing

const viewHeight = this.modelViewTransform.modelToViewDeltaY( modelHeight );
Expand Down
2 changes: 1 addition & 1 deletion js/mean-and-median/model/MeanAndMedianModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class MeanAndMedianModel extends CAVModel {

private clearAnimation(): void {
this.highlightAnimationIndex = null;
this.soccerBallGroup.forEach( cavObject => cavObject.isShowingAnimationHighlightProperty.set( false ) );
this.soccerBalls.forEach( cavObject => cavObject.isShowingAnimationHighlightProperty.set( false ) );
}

private updateAnimation(): void {
Expand Down
1 change: 1 addition & 0 deletions js/mean-and-median/view/MedianPlotNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default class MedianPlotNode extends CAVPlotNode {
...providedOptions
} );

// TODO: Dead code
// const checkboxGroup = new TopRepresentationCheckboxGroup( model, {
// medianBarIconOptions: {
// notchDirection: 'down',
Expand Down
2 changes: 1 addition & 1 deletion js/median/model/MedianModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class MedianModel extends CAVModel {

public constructor( options: CAVModelOptions ) {
super( options );
this.cards = this.soccerBallGroup.map( ( soccerBall, index ) => new CardModel( soccerBall, {
this.cards = this.soccerBalls.map( ( soccerBall, index ) => new CardModel( soccerBall, {
tandem: options.tandem.createTandem( 'cards' ).createTandem( 'card' + index )
} ) );

Expand Down

0 comments on commit ad4c33c

Please sign in to comment.