Skip to content

Commit

Permalink
address TODOs by removing CandyBar class and documenting a phet-io-on…
Browse files Browse the repository at this point in the history
…ly property, see #258
  • Loading branch information
jbphet committed Jun 7, 2024
1 parent 98b6ba2 commit db1aa87
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 58 deletions.
4 changes: 2 additions & 2 deletions js/common/SnackStacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MeanShareAndBalanceConstants from './MeanShareAndBalanceConstants.js';
import Plate from './model/Plate.js';
import Vector2 from '../../../dot/js/Vector2.js';
import { CUEING_ARROW_MARGIN } from '../distribute/view/DistributeScreenView.js';
import CandyBar from '../distribute/model/CandyBar.js';
import Snack from '../common/model/Snack.js';

// constants
const VERTICAL_SPACE_BETWEEN_APPLES = 4; // in screen coords, empirically determined
Expand Down Expand Up @@ -82,7 +82,7 @@ class SnackStacker {
return new Vector2( xPosition, yPosition );
}

public static getCueingArrowPosition( plate: Plate<CandyBar>, plateHeight: number ): Vector2 {
public static getCueingArrowPosition( plate: Plate<Snack>, plateHeight: number ): Vector2 {
const topSnackIndex = plate.snacksOnNotepadPlate.length - 1;
const plateXPosition = plate.xPositionProperty.value;
return SnackStacker.getStackedCandyBarPosition( plateXPosition, topSnackIndex )
Expand Down
2 changes: 1 addition & 1 deletion js/common/model/Snack.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022-2024, University of Colorado Boulder

/**
* Base class for snacks, which, in this sim, are items that can be shared between people.
* Snack defines attributes of an item that can be shared between people.
*
* @author Marla Schulz (PhET Interactive Simulations)
* @author John Blanco (PhET Interactive Simulations)
Expand Down
29 changes: 0 additions & 29 deletions js/distribute/model/CandyBar.ts

This file was deleted.

28 changes: 12 additions & 16 deletions js/distribute/model/DistributeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import meanShareAndBalance from '../../meanShareAndBalance.js';
import MeanShareAndBalanceConstants from '../../common/MeanShareAndBalanceConstants.js';
import Plate from '../../common/model/Plate.js';
import CandyBar from './CandyBar.js';
import SharingModel, { SharingModelOptions } from '../../common/model/SharingModel.js';
import GroupSortInteractionModel from '../../../../scenery-phet/js/accessibility/group-sort/model/GroupSortInteractionModel.js';
import Range from '../../../../dot/js/Range.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import Emitter from '../../../../axon/js/Emitter.js';
import { SnackOptions } from '../../common/model/Snack.js';
import Snack, { SnackOptions } from '../../common/model/Snack.js';
import SnackStacker from '../../common/SnackStacker.js';
import isSettingPhetioStateProperty from '../../../../tandem/js/isSettingPhetioStateProperty.js';
import Property from '../../../../axon/js/Property.js';
Expand All @@ -40,10 +39,10 @@ type DistributeModelOptions = SelfOptions & PickRequired<SharingModelOptions, 't
const INITIAL_PLATE_VALUES = [ 3, 1, 5, 3, 8, 10, 5 ];
export const NOTEPAD_PLATE_BOTTOM_Y = 330;

export default class DistributeModel extends SharingModel<CandyBar> {
export default class DistributeModel extends SharingModel<Snack> {

// Class properties needed for alt-input group sort interaction.
public readonly groupSortInteractionModel: GroupSortInteractionModel<CandyBar>;
public readonly groupSortInteractionModel: GroupSortInteractionModel<Snack>;
public readonly sortingRangeProperty: TReadOnlyProperty<Range>;

// Properties for the mean prediction tool.
Expand All @@ -63,14 +62,13 @@ export default class DistributeModel extends SharingModel<CandyBar> {
// phet-io specific Properties
public readonly successIndicatorsOperatingProperty: Property<boolean>;

// TODO: This is does not need to be a class member, but I'm not sure how to get around linting errors since
// it is needed for PhET-iO studio. https://github.com/phetsims/mean-share-and-balance/issues/258
public readonly meanWithRemainderProperty: TReadOnlyProperty<MeanWithRemainder>;

// A Property Object that holds the mean value as a whole number and a remainder. For instance, if there are two
// plates and five snacks, the whole portion would be 2 and the remainder 1. This is for phet-io client use only.
private readonly meanWithRemainderProperty: TReadOnlyProperty<MeanWithRemainder>;

public constructor( providedOptions?: DistributeModelOptions ) {

const createCandyBar = ( options: SnackOptions ) => new CandyBar( options );
const createCandyBar = ( options: SnackOptions ) => new Snack( options );

const options = optionize<DistributeModelOptions, SelfOptions, SharingModelOptions>()( {
initialPlateValues: INITIAL_PLATE_VALUES,
Expand All @@ -80,7 +78,7 @@ export default class DistributeModel extends SharingModel<CandyBar> {
super( createCandyBar, SnackStacker.getStackedCandyBarPosition, _.noop, options );

// Create and define the keyboard interaction for candy bars.
this.groupSortInteractionModel = new GroupSortInteractionModel<CandyBar>( {
this.groupSortInteractionModel = new GroupSortInteractionModel<Snack>( {
getGroupItemValue: candyBar => {
const plate = this.getPlateForSnack( candyBar );
return plate ? plate.linePlacement : null;
Expand Down Expand Up @@ -226,7 +224,6 @@ export default class DistributeModel extends SharingModel<CandyBar> {
phetioValueType: BooleanIO
} );

// For phet-io client use only.
this.meanWithRemainderProperty = new DerivedProperty( [
this.numberOfPlatesProperty,
this.totalSnacksProperty
Expand All @@ -241,7 +238,6 @@ export default class DistributeModel extends SharingModel<CandyBar> {
phetioValueType: ObjectLiteralIO
} );


this.successIndicatorsOperatingProperty = new BooleanProperty( true, {
tandem: options.tandem.createTandem( 'successIndicatorsOperatingProperty' )
} );
Expand All @@ -250,7 +246,7 @@ export default class DistributeModel extends SharingModel<CandyBar> {
/**
* This function returns an array of all active plates that have not reached full capacity.
*/
public getPlatesWithSpace(): Array<Plate<CandyBar>> {
public getPlatesWithSpace(): Array<Plate<Snack>> {
return this.plates.filter( plate =>
plate.isActiveProperty.value &&
plate.getNumberOfNotepadSnacks() < MeanShareAndBalanceConstants.MAX_NUMBER_OF_SNACKS_PER_PLATE
Expand All @@ -260,15 +256,15 @@ export default class DistributeModel extends SharingModel<CandyBar> {
/**
* This function returns an array of active plates that have at least one candy bar on them.
*/
public getPlatesWithSnacks(): Array<Plate<CandyBar>> {
public getPlatesWithSnacks(): Array<Plate<Snack>> {
return this.plates.filter( plate => plate.isActiveProperty.value && plate.getNumberOfNotepadSnacks() > 0 );
}


/**
* Get the plate with the most snacks, null if no plates have any.
*/
public getPlateWithMostSnacks(): Plate<CandyBar> | null {
public getPlateWithMostSnacks(): Plate<Snack> | null {
const sortedPlatesWithSnacks = this.getPlatesWithSnacks().sort(
( plateA, plateB ) => plateB.getNumberOfNotepadSnacks() - plateA.getNumberOfNotepadSnacks()
);
Expand All @@ -278,7 +274,7 @@ export default class DistributeModel extends SharingModel<CandyBar> {
/**
* Get the plate with the fewest snacks, null if all plates are full.
*/
private getPlateWithFewestSnacks(): Plate<CandyBar> | null {
private getPlateWithFewestSnacks(): Plate<Snack> | null {
const sortedPlatesWithSpace = this.getPlatesWithSpace().sort(
( plateA, plateB ) => plateA.getNumberOfNotepadSnacks() - plateB.getNumberOfNotepadSnacks()
);
Expand Down
4 changes: 2 additions & 2 deletions js/distribute/view/DistributeNotepadPlateNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import meanShareAndBalance from '../../meanShareAndBalance.js';
import Plate from '../../common/model/Plate.js';
import ModelViewTransform2 from '../../../../phetcommon/js/view/ModelViewTransform2.js';
import notepadPlateSketch_svg from '../../../images/notepadPlateSketch_svg.js';
import CandyBar from '../model/CandyBar.js';
import MeanShareAndBalanceConstants from '../../common/MeanShareAndBalanceConstants.js';
import Snack from '../../common/model/Snack.js';

type NotepadPlateNodeOptions = StrictOmit<NodeOptions, 'children'>;

Expand All @@ -26,7 +26,7 @@ const PLATE_X_OFFSET = 2; // The plate can appear off center since there is empt

export default class DistributeNotepadPlateNode extends Node {

public constructor( plate: Plate<CandyBar>,
public constructor( plate: Plate<Snack>,
mvt: ModelViewTransform2, providedOptions?: NotepadPlateNodeOptions ) {

const plateNode = new Image( notepadPlateSketch_svg, {
Expand Down
8 changes: 4 additions & 4 deletions js/distribute/view/DistributeScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import PatternStringProperty from '../../../../axon/js/PatternStringProperty.js';
import NotepadNode from '../../common/view/NotepadNode.js';
import GroupSortInteractionView from '../../../../scenery-phet/js/accessibility/group-sort/view/GroupSortInteractionView.js';
import CandyBar from '../model/CandyBar.js';
import Utils from '../../../../dot/js/Utils.js';
import ModelViewTransform2 from '../../../../phetcommon/js/view/ModelViewTransform2.js';
import { Shape } from '../../../../kite/js/imports.js';
Expand All @@ -40,6 +39,7 @@ import SoundClip from '../../../../tambo/js/sound-generators/SoundClip.js';
import ResetAllButton from '../../../../scenery-phet/js/buttons/ResetAllButton.js';
import soundManager from '../../../../tambo/js/soundManager.js';
import dragIndicatorHand_png from '../../../../scenery-phet/images/dragIndicatorHand_png.js';
import Snack from '../../common/model/Snack.js';

type SelfOptions = EmptySelfOptions;
type DistributeScreenViewOptions = SelfOptions & StrictOmit<SharingScreenViewOptions, 'children' | 'snackType'>;
Expand All @@ -49,12 +49,12 @@ const CANDY_BAR_FOCUS_X_MARGIN = 10; // in screen coords, empirically determined
const CUEING_ARROW_SCALE = 0.7;
export const CUEING_ARROW_MARGIN = 2; // in screen coords, empirically determined

export default class DistributeScreenView extends SharingScreenView<CandyBar> {
export default class DistributeScreenView extends SharingScreenView<Snack> {
private readonly notepadBoundsProperty: Property<Bounds2>;

// class members needed for the group sort interaction
private readonly groupSortInteractionView: GroupSortInteractionView<CandyBar, NotepadCandyBarNode>;
private readonly groupSortInteractionModel: GroupSortInteractionModel<CandyBar>;
private readonly groupSortInteractionView: GroupSortInteractionView<Snack, NotepadCandyBarNode>;
private readonly groupSortInteractionModel: GroupSortInteractionModel<Snack>;
private readonly keyboardSortCueNode: Node;
private readonly mouseSortIndicatorArrowNode: Node;
private readonly cueingHighlight: Node;
Expand Down
8 changes: 4 additions & 4 deletions js/distribute/view/NotepadCandyBarNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';
import WithRequired from '../../../../phet-core/js/types/WithRequired.js';
import CandyBar from '../model/CandyBar.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import ModelViewTransform2 from '../../../../phetcommon/js/view/ModelViewTransform2.js';
import Multilink from '../../../../axon/js/Multilink.js';
Expand All @@ -26,17 +25,18 @@ import releaseCandyBarV2_mp3 from '../../../sounds/releaseCandyBarV2_mp3.js';
import sketchedCandyBarFill_svg from '../../../images/sketchedCandyBarFill_svg.js';
import MeanShareAndBalanceConstants from '../../common/MeanShareAndBalanceConstants.js';
import GroupSortInteractionModel from '../../../../scenery-phet/js/accessibility/group-sort/model/GroupSortInteractionModel.js';
import Snack from '../../common/model/Snack.js';

type SelfOptions = EmptySelfOptions;
type NotepadCandyBarNodeOptions = SelfOptions & StrictOmit<WithRequired<NodeOptions, 'tandem'>, 'children'>;

export default class NotepadCandyBarNode extends InteractiveHighlighting( Node ) {

public readonly dragListener: DragListener;
public readonly candyBar: CandyBar;
public readonly candyBar: Snack;

public constructor( candyBar: CandyBar,
groupSortInteractionModel: GroupSortInteractionModel<CandyBar>,
public constructor( candyBar: Snack,
groupSortInteractionModel: GroupSortInteractionModel<Snack>,
modelViewTransform: ModelViewTransform2,
notebookPaperBoundsProperty: TReadOnlyProperty<Bounds2>,
candyBarDropped: ( candyBarNode: NotepadCandyBarNode ) => void,
Expand Down

0 comments on commit db1aa87

Please sign in to comment.