Skip to content

Commit

Permalink
delete range for NumberProperty because it's failing assertions, #78
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed May 3, 2023
1 parent a2900b3 commit e300b1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 2 additions & 4 deletions js/common/model/Substance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Node } from '../../../../scenery/js/imports.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';
import Property from '../../../../axon/js/Property.js';
import reactantsProductsAndLeftovers from '../../reactantsProductsAndLeftovers.js';
import RPALConstants from '../RPALConstants.js';

export default class Substance {

Expand All @@ -20,7 +19,7 @@ export default class Substance {
public readonly coefficientProperty: Property<number>;

// how much of the substance we have
public readonly quantityProperty: NumberProperty;
public readonly quantityProperty: Property<number>;

// visual representation of the substance, mutable to support the 'Custom' sandwich
public readonly iconProperty: Property<Node>;
Expand All @@ -43,8 +42,7 @@ export default class Substance {
} );

this.quantityProperty = new NumberProperty( quantity, {
numberType: 'Integer',
range: RPALConstants.QUANTITY_RANGE
numberType: 'Integer'
} );

this.iconProperty = new Property( icon );
Expand Down
7 changes: 4 additions & 3 deletions js/common/view/StackNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.
import { Node, NodeOptions, NodeTranslationOptions } from '../../../../scenery/js/imports.js';
import reactantsProductsAndLeftovers from '../../reactantsProductsAndLeftovers.js';
import SubstanceIcon from './SubstanceIcon.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';
import RPALConstants from '../RPALConstants.js';

type SelfOptions = EmptySelfOptions;

Expand All @@ -30,14 +30,14 @@ export default class StackNode extends Node {
* @param deltaY - the vertical spacing between nodes in the stack
* @param [providedOptions]
*/
public constructor( height: number, iconProperty: TReadOnlyProperty<Node>, quantityProperty: NumberProperty,
public constructor( height: number, iconProperty: TReadOnlyProperty<Node>, quantityProperty: TReadOnlyProperty<number>,
startCenterY: number, deltaY: number, providedOptions?: StackNodeOptions ) {

const options = optionize<StackNodeOptions, SelfOptions, NodeOptions>()( {}, providedOptions );

// Eagerly create the maximum number of Nodes in the stack, positioned from the bottom up.
const icons: SubstanceIcon[] = [];
for ( let i = 0; i < quantityProperty.range.max; i++ ) {
for ( let i = 0; i < RPALConstants.QUANTITY_RANGE.max; i++ ) {
icons.push( new SubstanceIcon( iconProperty, {
centerX: 0,
centerY: startCenterY - ( i * deltaY )
Expand All @@ -46,6 +46,7 @@ export default class StackNode extends Node {

// Make the proper number of Nodes visible in the stack, from the bottom up.
const quantityPropertyObserver = ( quantity: number ) => {
assert && assert( RPALConstants.QUANTITY_RANGE.contains( quantity ) );
for ( let i = 0; i < icons.length; i++ ) {
icons[ i ].visible = ( i < quantity );
}
Expand Down

0 comments on commit e300b1d

Please sign in to comment.