Skip to content

Commit

Permalink
Add hand icon to kittens, see: #81
Browse files Browse the repository at this point in the history
  • Loading branch information
marlitas committed Feb 13, 2025
1 parent 4bfc620 commit 33233ff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
6 changes: 6 additions & 0 deletions js/common/model/NumberPairsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export default class NumberPairsModel implements TModel {
public readonly leftAddendCountingObjectsLengthProperty: TReadOnlyProperty<number>;
public readonly rightAddendCountingObjectsLengthProperty: TReadOnlyProperty<number>;

public readonly hasAttributeBeenSwitchedProperty: Property<boolean>;

protected constructor(
// The totalProperty is derived from the left and right addend numbers.
// In decomposition models (Intro, Ten, and Twenty screens) it is set by the selected scene.
Expand Down Expand Up @@ -190,6 +192,10 @@ export default class NumberPairsModel implements TModel {
hasListenerOrderDependencies: true,
derive: 'lengthProperty'
} );
this.hasAttributeBeenSwitchedProperty = new BooleanProperty( false, {
tandem: options.tandem.createTandem( 'hasAttributeBeenSwitchedProperty' ),
phetioState: false
} );
}

/**
Expand Down
17 changes: 14 additions & 3 deletions js/common/view/KittenNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import CountingObject, { AddendType } from '../model/CountingObject.js';
import { PositionPropertyType } from '../model/NumberPairsModel.js';
import NumberPairsColors from '../NumberPairsColors.js';
import NumberPairsConstants from '../NumberPairsConstants.js';
import hand_png from '../../../../scenery-phet/images/hand_png.js';

type SelfOptions = {
onEndDrag: ( countingObject: CountingObject, positionPropertyType: PositionPropertyType ) => void;
Expand All @@ -58,6 +59,7 @@ export default class KittenNode extends InteractiveHighlightingNode {
public readonly countingObject: CountingObject,
dragBounds: Bounds2,
newKittenSelectedEmitter: Emitter<[CountingObject]>,
hasAttributeBeenSwitchedProperty: Property<boolean>,
providedOptions: KittenNodeOptions
) {

Expand All @@ -70,8 +72,8 @@ export default class KittenNode extends InteractiveHighlightingNode {
// a Property that allows us to toggle between the left and right addend while also still respecting the
// INACTIVE options that addendTypeProperty supports.
const isLeftAddendProperty = new BooleanProperty( countingObject.addendTypeProperty.value === AddendType.LEFT, {} );
isLeftAddendProperty.link( isLeftAddend => {

isLeftAddendProperty.lazyLink( isLeftAddend => {
hasAttributeBeenSwitchedProperty.value = true;
// Only update the addendTypeProperty if it is not inactive. We should not be changing the state of an
// inactive counting object.
if ( countingObject.addendTypeProperty.value !== AddendType.INACTIVE ) {
Expand Down Expand Up @@ -99,6 +101,8 @@ export default class KittenNode extends InteractiveHighlightingNode {
tandem: options.tandem.createTandem( 'kittenAttributeSwitch' ),
setLabelEnabled: _.noop // We do not want the labels to change opacity
} );
const handIconVisibleProperty = new DerivedProperty( [ hasAttributeBeenSwitchedProperty, countingObject.kittenSelectedProperty ],
( hasAttributeBeenSwitched, selected ) => !hasAttributeBeenSwitched && selected );

// When a countingObject is focused the panel with a switch is visible
const panelBounds = new Bounds2( 0, 0, KITTEN_PANEL_WIDTH, KITTEN_PANEL_HEIGHT );
Expand All @@ -114,6 +118,13 @@ export default class KittenNode extends InteractiveHighlightingNode {
stroke: null
} );

const handIcon = new Image( hand_png, {
maxWidth: 24,
centerX: focusPanel.centerX + 6,
y: 13,
visibleProperty: handIconVisibleProperty
} );

const leftAddendKittenImage = new Image( kittenYellow_svg, {
centerX: focusPanel.centerX + KITTEN_OFFSET,
bottom: focusPanel.bottom - KITTEN_PANEL_MARGIN,
Expand All @@ -133,7 +144,7 @@ export default class KittenNode extends InteractiveHighlightingNode {

// TODO: use options.children = instead, etc.
const superOptions = combineOptions<NodeOptions>( {
children: [ focusPanel, leftAddendKittenImage, rightAddendKittenImage ],
children: [ focusPanel, leftAddendKittenImage, rightAddendKittenImage, handIcon ],
focusHighlight: Shape.bounds( focusPanel.bounds )
}, options );
super( superOptions );
Expand Down
5 changes: 3 additions & 2 deletions js/common/view/KittensLayerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ import CountingObject, { AddendType } from '../model/CountingObject.js';
import NumberPairsConstants from '../NumberPairsConstants.js';
import CountingAreaNode from './CountingAreaNode.js';
import KittenNode from './KittenNode.js';
import Property from '../../../../axon/js/Property.js';

type KittensLayerNodeOptions = PickRequired<NodeOptions, 'tandem'> & StrictOmit<NodeOptions, 'children'>;
export default class KittensLayerNode extends Node {
public readonly kittenNodes: KittenNode[];

public constructor( countingObjects: CountingObject[], countingAreNode: CountingAreaNode, providedOptions: KittensLayerNodeOptions ) {
public constructor( countingObjects: CountingObject[], countingAreNode: CountingAreaNode, hasAttributeBeenSwitchedProperty: Property<boolean>, providedOptions: KittensLayerNodeOptions ) {
const newKittenSelectedEmitter = new Emitter<[ CountingObject ]>( { parameters: [ { valueType: CountingObject } ] } );
const kittenNodes: KittenNode[] = [];

countingObjects.forEach( ( countingObject, i ) => {
kittenNodes.push( new KittenNode( countingObject, NumberPairsConstants.COUNTING_AREA_BOUNDS, newKittenSelectedEmitter, {
kittenNodes.push( new KittenNode( countingObject, NumberPairsConstants.COUNTING_AREA_BOUNDS, newKittenSelectedEmitter, hasAttributeBeenSwitchedProperty, {
switchFocusToFirstKitten: () => {
const firstKitten = kittenNodes[ 0 ];
assert && assert( firstKitten.countingObject.addendTypeProperty.value !== AddendType.INACTIVE, 'first kitten should not be inactive' );
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/NumberPairsScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export default class NumberPairsScreenView extends ScreenView {
*/
if ( model.representationTypeProperty.validValues?.includes( RepresentationType.KITTENS ) ) {
const kittensLayerVisibleProperty = DerivedProperty.valueEqualsConstant( model.representationTypeProperty, RepresentationType.KITTENS );
const kittensLayerNode = new KittensLayerNode( model.countingObjects, countingAreaNode, {
const kittensLayerNode = new KittensLayerNode( model.countingObjects, countingAreaNode, model.hasAttributeBeenSwitchedProperty, {
visibleProperty: kittensLayerVisibleProperty,
tandem: options.tandem.createTandem( 'kittensLayerNode' )
} );
Expand Down

0 comments on commit 33233ff

Please sign in to comment.