Skip to content

Commit

Permalink
Move setDataPoints override to IOType, see: #335
Browse files Browse the repository at this point in the history
(cherry picked from commit 431ad8b)
  • Loading branch information
marlitas committed Aug 13, 2024
1 parent 8425f84 commit 7e26148
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
21 changes: 15 additions & 6 deletions js/balance-point/model/BalancePointModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,28 @@ export default class BalancePointModel extends SoccerModel<BalancePointSceneMode
setDataPoints: {
returnType: VoidIO,
parameterTypes: [ ArrayIO( NumberIO ) ],
implementation: function( this: BalancePointModel, dataPoints: number[] ) {
this.selectedSceneModelProperty.value.setDataPoints( dataPoints );
implementation: function( model: BalancePointModel, dataPoints: number[] ) {
const selectedSceneModel = model.selectedSceneModelProperty.value;
selectedSceneModel.setDataPoints( dataPoints );

// When phet-io clients set the data points statically there should be no animation and therefore no queued kicks.
// We do this work here because soccer-common does not inherently support of numberOfBallsProperty that drives
// the addition and removal of soccer balls. setDataPoints automatically adds balls to the field as desired
// and bypasses targetNumberOfBallsProperty. Ideally we would cancel all listeners to the targetNumberOfBallsProperty
// in this use case, however that is not supported. Therefore, we will zero out the numberOfQueuedKicksProperty
// that is the next link in the chain. We know this is inherently fragile, and should only be used by PhET-iO
// clients. If the listener chain changes, or QueuedKicks behaves differently this will need to be updated.
selectedSceneModel.targetNumberOfBallsProperty.value = Math.min( dataPoints.length, selectedSceneModel.maxKicksProperty.value );
selectedSceneModel.numberOfQueuedKicksProperty.value = 0;
},
documentation: 'Sets the data points for the selected scene model. Array lengths that exceed maxKicks will ignore excess values.'
},

getDataPoints: {
returnType: ArrayIO( NumberIO ),
parameterTypes: [],
implementation: function( this: BalancePointModel ) {
return this.selectedSceneModelProperty.value
.getSortedStackedObjects().map( soccerBall => soccerBall.valueProperty.value );
},
implementation: ( model: BalancePointModel ) =>
model.selectedSceneModelProperty.value.getSortedStackedObjects().map( soccerBall => soccerBall.valueProperty.value ),
documentation: 'Gets the data points for the selected scene model.'
}
}
Expand Down
18 changes: 0 additions & 18 deletions js/balance-point/model/BalancePointSceneModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,24 +412,6 @@ export default class BalancePointSceneModel extends SoccerSceneModel {
this.meanPredictionFulcrumValueProperty.reset();
this.beamSupportsPresentProperty.reset();
}

/**
* Set the data points for the scene model. This is only called by phet-io clients and should not be used by the sim
* itself.
*/
public override setDataPoints( dataPoints: number[] ): void {
super.setDataPoints( dataPoints );

// When phet-io clients set the data points statically there should be no animation and therefore no queued kicks.
// We do this work here because soccer-common does not inherently support of numberOfBallsPorperty that drives
// the addition and removal of soccer balls. super.setDataPoints automatically adds balls to the field as desired
// and bypasses targetNumberOfBallsProperty. Ideally we would cancel all listeners to the targetNumberOfBallsProperty
// in this use case, however that is not supported. Therefore, we will zero out the numberOfQueuedKicksProperty
// that is the next link in the chain. We know this is inherently fragile, and should only be used by PhET-iO
// clients. If the listener chain changes, or QueuedKicks behaves differently this will need to be updated.
this.targetNumberOfBallsProperty.value = Math.min( dataPoints.length, this.maxKicksProperty.value );
this.numberOfQueuedKicksProperty.value = 0;
}
}

type BalanceBeamEndpointYValuesStateObject = {
Expand Down

0 comments on commit 7e26148

Please sign in to comment.