-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
74 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 18 additions & 22 deletions
40
js/leveling-out/model/TablePlate.ts → js/leveling-out/model/Plate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,75 @@ | ||
// Copyright 2022-2024, University of Colorado Boulder | ||
|
||
/** | ||
* The model representing the container for candy bars in the bottom representation. | ||
* Tracks the position of a person and their notepadPlate, as well as how many candy bars they have brought | ||
* The model representing the container for candy bars or cookies. | ||
* | ||
* @author Marla Schulz (PhET Interactive Simulations) | ||
* | ||
*/ | ||
|
||
import BooleanProperty from '../../../../axon/js/BooleanProperty.js'; | ||
import NumberProperty from '../../../../axon/js/NumberProperty.js'; | ||
import Property from '../../../../axon/js/Property.js'; | ||
import Range from '../../../../dot/js/Range.js'; | ||
import Vector2 from '../../../../dot/js/Vector2.js'; | ||
import optionize from '../../../../phet-core/js/optionize.js'; | ||
import PickRequired from '../../../../phet-core/js/types/PickRequired.js'; | ||
import { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js'; | ||
import meanShareAndBalance from '../../meanShareAndBalance.js'; | ||
|
||
type SelfOptions = { | ||
isActive: boolean; | ||
position: Vector2; | ||
xPosition: number; | ||
linePlacement: number; | ||
}; | ||
|
||
type TablePlateOptions = SelfOptions & PickRequired<PhetioObjectOptions, 'tandem'>; | ||
type PlateOptions = SelfOptions & PickRequired<PhetioObjectOptions, 'tandem'>; | ||
|
||
export default class TablePlate { | ||
export default class Plate { | ||
|
||
// Whether the cup is enabled in view and data calculations | ||
public readonly isActiveProperty: Property<boolean>; | ||
|
||
// The x and y positions for the person in the view. This specifies relative spacing between the people, and | ||
// another container centers the group. | ||
public readonly position: Vector2; | ||
// The x position of the plate in view coordinates. | ||
public readonly xPosition: number; | ||
|
||
// The amount of candy bar bars the person brought | ||
public readonly candyBarNumberProperty: Property<number>; | ||
// The number of snacks (candy bars or cookies) on this plate. | ||
public readonly snackNumberProperty: Property<number>; | ||
|
||
// the person's index - 0-indexed | ||
// The plate's index, 0-indexed. This is primarily used for debugging. | ||
public readonly linePlacement: number; | ||
|
||
public constructor( providedOptions?: TablePlateOptions ) { | ||
public constructor( providedOptions: PlateOptions ) { | ||
|
||
const options = optionize<TablePlateOptions, SelfOptions, PhetioObjectOptions>()( {}, providedOptions ); | ||
const options = optionize<PlateOptions, SelfOptions, PhetioObjectOptions>()( {}, providedOptions ); | ||
|
||
this.isActiveProperty = new BooleanProperty( options.isActive, { | ||
|
||
// phet-io | ||
tandem: options.tandem.createTandem( 'isActiveProperty' ), | ||
|
||
// Takes its value from LevelingOutModel.numberOfPeopleProperty, so cannot be independently adjusted | ||
// Takes its value from LevelingOutModel.numberOfPeopleProperty, so cannot be independently adjusted. | ||
phetioReadOnly: true | ||
} ); | ||
this.position = options.position; | ||
this.xPosition = options.xPosition; | ||
|
||
this.candyBarNumberProperty = new NumberProperty( options.isActive ? 1 : 0, { | ||
this.snackNumberProperty = new NumberProperty( options.isActive ? 1 : 0, { | ||
|
||
range: new Range( 0, 10 ), | ||
|
||
// phet-io | ||
tandem: options.tandem.createTandem( 'candyBarNumberProperty' ) | ||
tandem: options.tandem.createTandem( 'snackNumberProperty' ) | ||
} ); | ||
|
||
this.linePlacement = options.linePlacement; | ||
|
||
// When the person becomes inactive, delete their candy bars. When a person becomes active, they arrive with 1 candy bar | ||
this.isActiveProperty.lazyLink( isActive => this.candyBarNumberProperty.set( isActive ? 1 : 0 ) ); | ||
this.isActiveProperty.lazyLink( isActive => this.snackNumberProperty.set( isActive ? 1 : 0 ) ); | ||
} | ||
|
||
// LinePlacement and position never changes and hence doesn't need to be reset. | ||
public reset(): void { | ||
this.isActiveProperty.reset(); | ||
this.candyBarNumberProperty.reset(); | ||
this.snackNumberProperty.reset(); | ||
} | ||
} | ||
|
||
meanShareAndBalance.register( 'TablePlate', TablePlate ); | ||
meanShareAndBalance.register( 'Plate', Plate ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters