Skip to content

Commit

Permalink
Fix reset, see #172
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed May 6, 2023
1 parent 6e8d554 commit a75baad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion js/common/model/SoccerBall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,15 @@ export default class SoccerBall {
}

public reset(): void {

// Reset the drag position first, since it triggers a change in the position property and the value property (if it is clamped)
// TODO: It is odd and awkward that it takes this value through value = 1 during reset, should we fix it? See https://github.com/phetsims/center-and-variability/issues/172
this.dragPositionProperty.reset();

this.positionProperty.reset();
this.velocityProperty.reset();
this.animationModeProperty.reset();
this.valueProperty.reset();
this.dragPositionProperty.reset();
this.isMedianObjectProperty.reset();
this.isQ1ObjectProperty.reset();
this.isQ3ObjectProperty.reset();
Expand Down
19 changes: 16 additions & 3 deletions js/median/view/CardNodeContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ export default class CardNodeContainer extends Node {
totalDragDistanceProperty.value += distance;
} );

const removeCardCell = ( cardNode: CardNode ) => {
const index = this.cardNodeCells.indexOf( cardNode );

if ( index >= 0 ) {
this.cardNodeCells.splice( index, 1 );
this.cardNodeCellsChangedEmitter.emit();
}
};

cardModel.isActiveProperty.link( isActive => {
if ( isActive && !phet.joist.sim.isSettingPhetioStateProperty.value ) {

Expand All @@ -206,9 +215,13 @@ export default class CardNodeContainer extends Node {
this.cardNodeCellsChangedEmitter.emit();
}
else if ( !isActive ) {
const index = this.cardNodeCells.indexOf( cardNode );
this.cardNodeCells.splice( index, 1 );
this.cardNodeCellsChangedEmitter.emit();
removeCardCell( cardNode );
}
} );

cardModel.soccerBall.valueProperty.link( value => {
if ( value === null ) {
removeCardCell( cardNode );
}
} );

Expand Down

0 comments on commit a75baad

Please sign in to comment.