Skip to content

Commit

Permalink
Simplify SoccerBall options, see #172
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed May 11, 2023
1 parent c895a51 commit f5603af
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
3 changes: 1 addition & 2 deletions js/common/model/CAVSceneModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ export default abstract class CAVSceneModel extends PhetioObject implements TMod
range: new Range( 0, this.maxKicksLimit )
} );
this.soccerBalls = _.range( 0, this.maxKicksLimit ).map( index => {
const soccerBall = new SoccerBall( {
isFirstObject: index === 0,
const soccerBall = new SoccerBall( index === 0, {
tandem: options.tandem.createTandem( 'soccerBalls' ).createTandem( `soccerBall${index}` )
} );

Expand Down
18 changes: 2 additions & 16 deletions js/common/model/SoccerBall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import centerAndVariability from '../../centerAndVariability.js';
import Vector2Property from '../../../../dot/js/Vector2Property.js';
import PhetioObject, { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import optionize from '../../../../phet-core/js/optionize.js';
import CAVObjectType from './CAVObjectType.js';
import NumberIO from '../../../../tandem/js/types/NumberIO.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
Expand All @@ -26,13 +25,7 @@ import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import TEmitter from '../../../../axon/js/TEmitter.js';
import SoccerPlayer from './SoccerPlayer.js';

type SelfOptions = {
isFirstObject?: boolean;
};
export type CAVObjectOptions =
SelfOptions
& PhetioObjectOptions
& PickRequired<PhetioObjectOptions, 'tandem'>;
export type CAVObjectOptions = PhetioObjectOptions & PickRequired<PhetioObjectOptions, 'tandem'>;

// Global counter for debugging
let count = 0;
Expand All @@ -52,7 +45,6 @@ export default class SoccerBall extends PhetioObject {
public readonly isQ1ObjectProperty: BooleanProperty;
public readonly isQ3ObjectProperty: BooleanProperty;
public readonly isShowingAnimationHighlightProperty: BooleanProperty;
public readonly isFirstObject: boolean;

// Where the object is animating to, or null if not yet animating
public targetXProperty: Property<number | null>;
Expand All @@ -72,19 +64,13 @@ export default class SoccerBall extends PhetioObject {
parameters: [ { valueType: SoccerBall } ]
} );

public constructor( providedOptions: CAVObjectOptions ) {

const options = optionize<CAVObjectOptions, SelfOptions, PhetioObjectOptions>()( {
isFirstObject: false
}, providedOptions );
public constructor( public readonly isFirstSoccerBall: boolean, options: CAVObjectOptions ) {

super( {
...options,
phetioState: false
} );

this.isFirstObject = options.isFirstObject;

this.positionProperty = new Vector2Property( new Vector2( 0, CAVObjectType.SOCCER_BALL.radius ), {
tandem: options.tandem.createTandem( 'positionProperty' ),
valueComparisonStrategy: 'equalsFunction',
Expand Down
5 changes: 3 additions & 2 deletions js/common/view/CAVObjectNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export default abstract class CAVObjectNode extends Node {

protected readonly medianHighlight: Circle;

public constructor( public readonly soccerBall: SoccerBall, isShowingPlayAreaMedianProperty: TReadOnlyProperty<boolean>,
public constructor( public readonly soccerBall: SoccerBall,
isShowingPlayAreaMedianProperty: TReadOnlyProperty<boolean>,
modelViewTransform: ModelViewTransform2,
modelRadius: number,
providedOptions?: CAVObjectNodeOptions ) {
Expand All @@ -57,7 +58,7 @@ export default abstract class CAVObjectNode extends Node {
// they don't look like part of the data set, but still look kickable.
Multilink.multilink( [ soccerBall.valueProperty, soccerBall.animationModeProperty ],
( value, animationMode ) => {
this.opacity = value === null && animationMode === AnimationMode.NONE && !soccerBall.isFirstObject ? 0.4 : 1;
this.opacity = value === null && animationMode === AnimationMode.NONE && soccerBall.isFirstSoccerBall ? 1 : 0.4;
} );

// Show index when debugging with ?dev
Expand Down

0 comments on commit f5603af

Please sign in to comment.