Skip to content

Commit

Permalink
Rename NumberCardContainer -> CardNodeContainer.ts, fix relevant nami…
Browse files Browse the repository at this point in the history
…ng, see #45
  • Loading branch information
chrisklus committed Feb 28, 2022
1 parent 1b703ad commit 03763d6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
9 changes: 4 additions & 5 deletions js/common/view/CardNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import CardModel from '../model/CardModel.js';
import { RequiredTandem } from '../../../../tandem/js/PhetioObject.js';
import Emitter from '../../../../axon/js/Emitter.js';

// TODO: Rename options
type NumberCardSelfOptions = {};
export type NumberCardOptions = NodeOptions & RequiredTandem;
type CardNodeSelfOptions = {};
export type CardNodeOptions = CardNodeSelfOptions & NodeOptions & RequiredTandem;

class CardNode extends Node {
readonly positionProperty: Vector2Property;
Expand All @@ -36,7 +35,7 @@ class CardNode extends Node {

static readonly CARD_WIDTH = 43;

constructor( cardModel: CardModel, position: Vector2, getDragRange: () => Range, providedOptions?: NumberCardOptions ) {
constructor( cardModel: CardModel, position: Vector2, getDragRange: () => Range, providedOptions: CardNodeOptions ) {

const cornerRadius = 10;
const rectangle = new Rectangle( 0, 0, CardNode.CARD_WIDTH, CardNode.CARD_WIDTH, cornerRadius, cornerRadius, {
Expand All @@ -53,7 +52,7 @@ class CardNode extends Node {
text.center = rectangle.center;
} );

const options = optionize<NumberCardOptions, NumberCardSelfOptions, NodeOptions>( {
const options = optionize<CardNodeOptions, CardNodeSelfOptions, NodeOptions>( {
tandem: Tandem.REQUIRED,
children: [ rectangle, text ],
cursor: 'pointer'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ import stepTimer from '../../../../axon/js/stepTimer.js';
const CARD_SPACING = 10;
const getCardPositionX = ( index: number ) => index * ( CardNode.CARD_WIDTH + CARD_SPACING );

type NumberCardContainerSelfOptions = {};
export type NumberCardOptions = NodeOptions & RequiredTandem;
type CardNodeContainerSelfOptions = {};
export type CardNodeContainerOptions = CardNodeContainerSelfOptions & NodeOptions & RequiredTandem;

// TODO: Rename CardNodeContainer
class NumberCardContainer extends Node {
class CardNodeContainer extends Node {
readonly cardNodeCells: CardNode[];
readonly cardNodeCellsChangedEmitter: Emitter<[]>;

Expand All @@ -56,11 +55,11 @@ class NumberCardContainer extends Node {
private readonly hasDraggedCardProperty: IReadOnlyProperty<boolean>;
private readonly cardLayer: Node;

constructor( model: CASModel, providedOptions?: NumberCardOptions ) {
constructor( model: CASModel, providedOptions: CardNodeContainerOptions ) {

const options = optionize<NumberCardOptions, NumberCardContainerSelfOptions, NodeOptions>( {
const options = optionize<CardNodeContainerOptions, CardNodeContainerSelfOptions, NodeOptions>( {
tandem: Tandem.REQUIRED,
phetioType: NumberCardContainerIO,
phetioType: CardNodeContainerIO,
phetioState: true
}, providedOptions );

Expand Down Expand Up @@ -118,7 +117,7 @@ class NumberCardContainer extends Node {
model.objectGroup.elementCreatedEmitter.addListener( objectCreatedListener );

model.cardModelGroup.elementDisposedEmitter.addListener( cardModel => {
const cardNode = this.getNumberCardNode( cardModel.casObject );
const cardNode = this.getCardNode( cardModel.casObject );

// cardNode may not exist if the ball was still in the air
if ( cardNode ) {
Expand Down Expand Up @@ -346,7 +345,7 @@ class NumberCardContainer extends Node {
}
}

getNumberCardNode( casObject: CASObject ): CardNode | null {
getCardNode( casObject: CASObject ): CardNode | null {
return this.cardNodeCells.find( cardNode => cardNode.casObject === casObject ) || null;
}

Expand Down Expand Up @@ -421,14 +420,14 @@ class NumberCardContainer extends Node {

// Track the order of the cards as self-state, so that the downstream sim can get the cards in the desired cells
const CardNodeReferenceIO = ReferenceIO( Node.NodeIO );
const NumberCardContainerIO = new IOType( 'NumberCardContainerIO', {
valueType: NumberCardContainer,
toStateObject: ( n: NumberCardContainer ) => {
const CardNodeContainerIO = new IOType( 'CardNodeContainerIO', {
valueType: CardNodeContainer,
toStateObject: ( n: CardNodeContainer ) => {
return {
cardNodes: n.cardNodeCells.map( cardNode => CardNodeReferenceIO.toStateObject( cardNode ) )
};
},
applyState: ( n: NumberCardContainer, state: any ) => {
applyState: ( n: CardNodeContainer, state: any ) => {
const cardNodes = state.cardNodes.map( ( element: any ) => CardNodeReferenceIO.fromStateObject( element ) );
n.cardNodeCells.length = 0;
n.cardNodeCells.push( ...cardNodes );
Expand All @@ -443,5 +442,5 @@ const NumberCardContainerIO = new IOType( 'NumberCardContainerIO', {
}
} );

centerAndSpread.register( 'NumberCardContainer', NumberCardContainer );
export default NumberCardContainer;
centerAndSpread.register( 'CardNodeContainer', CardNodeContainer );
export default CardNodeContainer;
2 changes: 1 addition & 1 deletion js/common/view/DotPlotNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class DotPlotNode extends Node {
}

/**
* No implementation because this node is powered by the model. Reset needed for uniformity with NumberCardContainer.
* No implementation because this node is powered by the model. Reset needed for uniformity with CardNodeContainer.
*/
reset() {}

Expand Down
8 changes: 4 additions & 4 deletions js/common/view/MeanOrMedianScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import SoccerScreenView, { SoccerScreenViewOptions } from '../../common/view/Soc
import centerAndSpreadStrings from '../../centerAndSpreadStrings.js';
import CASAccordionBox from '../../common/view/CASAccordionBox.js';
import CASConstants from '../../common/CASConstants.js';
import NumberCardContainer from '../../common/view/NumberCardContainer.js';
import CardNodeContainer from '../../common/view/CardNodeContainer.js';
import DotPlotNode from './DotPlotNode.js';
import SoccerModel from '../model/SoccerModel.js';
import ValueReadoutsNode from './ValueReadoutsNode.js';
Expand All @@ -31,7 +31,7 @@ class MeanOrMedianScreenView extends SoccerScreenView {
private readonly accordionBox: CASAccordionBox;

// TODO: need reset, but may want to make an interface for a resettable Node
protected readonly accordionBoxContents: NumberCardContainer | DotPlotNode;
protected readonly accordionBoxContents: CardNodeContainer | DotPlotNode;

constructor( model: SoccerModel, providedOptions: MeanOrMedianScreenViewOptions ) {

Expand All @@ -44,10 +44,10 @@ class MeanOrMedianScreenView extends SoccerScreenView {
const accordionBoxTandem = options.tandem.createTandem( 'accordionBox' );

if ( options.isMedianScreen ) {
this.accordionBoxContents = new NumberCardContainer( this.model, {
this.accordionBoxContents = new CardNodeContainer( this.model, {

// Expose this intermediate layer to make it so that clients can hide the number cards with one call
tandem: accordionBoxTandem.createTandem( 'numberCardContainer' )
tandem: accordionBoxTandem.createTandem( 'cardNodeContainer' )
} );
}
else {
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/MedianBarsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Renders non-interactive red bars that show how the median splits up into the lower and upper groups.
* This appears within the NumberCardContainer and in the DotPlotNode
* This appears within the CardNodeContainer and in the DotPlotNode
*
* @author Chris Klusendorf (PhET Interactive Simulations)
* @author Sam Reid (PhET Interactive Simulations)
Expand Down

0 comments on commit 03763d6

Please sign in to comment.