phetsims / mean-share-and-balance

"Mean: Share and Balance" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
2 stars 1 forks source link

GroupSortInteraction can't handle getting a new selectedGroupItem when a plate is removed #209

Closed marlitas closed 2 months ago

marlitas commented 2 months ago

In the Distribute Screen, and while working on https://github.com/phetsims/mean-share-and-balance/issues/137, the groupSortInteraction was not able to assign a new selectedGroupItem when the sorting range changed due to our new arrays approach for handling snacks.

The default rangeListener required knowledge of the snack's current value which we no longer have since it is sent to the unusedSnacks array when a plate is removed. A reasonable solution would be to return a null value for getGroupItemValue and then have the rangeListener recalculate. However, the default rangeListener uses null to determine wether groupItem is in an active scene or not. Since this simulation does not have scenes, this logic is not necessary for us.

I decided to create an option in GroupSortInteractionView that can override the default rangeListener to provide it's own logic on when to recalculate. The commits are incoming.

marlitas commented 2 months ago

This has been committed above and is ready for @zepumph to take a look.

zepumph commented 2 months ago

Amazing. Thanks for the update.