Skip to content

Commit

Permalink
BookNode use idiomatic tandem option passing, remove bad visiblePrope…
Browse files Browse the repository at this point in the history
…rties, add good inputEnabledProperties, #236
  • Loading branch information
zepumph committed Sep 21, 2021
1 parent 5b09114 commit 2c81d29
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
13 changes: 9 additions & 4 deletions js/friction/view/FrictionScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,24 @@ class FrictionScreenView extends ScreenView {

// add physics book
this.addChild( new BookNode( model, physicsString, temperatureIncreasingAlerter, temperatureDecreasingAlerter,
bookMovementAlerter, grabbedDescriber, alertSettledAndCool, tandem.createTandem( 'bottomBookNode' ), {
bookMovementAlerter, grabbedDescriber, alertSettledAndCool, {
x: 50,
y: 225
y: 225,
tandem: tandem.createTandem( 'bottomBookNode' )
} ) );

// add chemistry book
const chemistryBookNode = new BookNode( model, chemistryString, temperatureIncreasingAlerter,
temperatureDecreasingAlerter,
bookMovementAlerter, grabbedDescriber, alertSettledAndCool, tandem.createTandem( 'topBookNode' ), {
bookMovementAlerter, grabbedDescriber, alertSettledAndCool, {
x: 65,
y: 209,
color: FrictionConstants.TOP_BOOK_COLOR_MACRO,
drag: true
drag: true,

// phet-io
tandem: tandem.createTandem( 'topBookNode' ),
phetioInputEnabledPropertyInstrumented: true
} );
this.addChild( chemistryBookNode );

Expand Down
17 changes: 9 additions & 8 deletions js/friction/view/book/BookNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Voicing from '../../../../../scenery/js/accessibility/voicing/Voicing.js'
import Node from '../../../../../scenery/js/nodes/Node.js';
import SoundClip from '../../../../../tambo/js/sound-generators/SoundClip.js';
import soundManager from '../../../../../tambo/js/soundManager.js';
import Tandem from '../../../../../tandem/js/Tandem.js';
import simpleDropSound from '../../../../sounds/simple-drop_mp3.js';
import simplePickupSound from '../../../../sounds/simple-pickup_mp3.js';
import friction from '../../../friction.js';
Expand All @@ -42,10 +43,9 @@ class BookNode extends Node {
* @param {BookMovementAlerter} bookMovementAlerter
* @param {GrabbedDescriber} grabbedDescriber
* @param {function():} alertSettledAndCool
* @param {Tandem} tandem
* @param {Object} [options]
*/
constructor( model, title, temperatureIncreasingAlerter, temperatureDecreasingAlerter, bookMovementAlerter, grabbedDescriber, alertSettledAndCool, tandem, options ) {
constructor( model, title, temperatureIncreasingAlerter, temperatureDecreasingAlerter, bookMovementAlerter, grabbedDescriber, alertSettledAndCool, options ) {

options = merge( {

Expand All @@ -54,7 +54,11 @@ class BookNode extends Node {
color: FrictionConstants.BOTTOM_BOOK_COLOR_MACRO,

// voicing
voicingNameResponse: chemistryBookString
voicingNameResponse: chemistryBookString,

// phet-io
tandem: Tandem.REQUIRED,
phetioVisiblePropertyInstrumented: false
}, options );

assert && assert( typeof options.x === 'number', 'options.x must be specified' );
Expand All @@ -63,16 +67,13 @@ class BookNode extends Node {
super( options );

// add cover, pass the whole tandem to hide the "cover" implementation detail
this.addChild( new CoverNode( title, tandem, options ) );
this.addChild( new CoverNode( title, options.tandem, _.omit( options, [ 'tandem' ] ) ) );

// init drag and a11y options for the draggable book
if ( options.drag ) {

this.initializeVoicing( options );

// instrument this book, but not the other
options.tandem = tandem;

// a11y - We want the highlights to be completely within the bounds of the book.
const focusHighlightRect = new FocusHighlightPath( null );
const highlightLineWidth = focusHighlightRect.getOuterLineWidth( this );
Expand Down Expand Up @@ -142,7 +143,7 @@ class BookNode extends Node {

dragCueNode: arrows,

tandem: tandem.createTandem( 'grabDragInteraction' )
tandem: options.tandem.createTandem( 'grabDragInteraction' )
} );


Expand Down
6 changes: 3 additions & 3 deletions js/friction/view/book/CoverNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class CoverNode extends Node {

/**
* @param {string} title
* @param {Tandem} tandem
* @param {Tandem} tandemParent - not passed to Node and instrumented!
* @param {Object} [options]
*/
constructor( title, tandem, options ) {
constructor( title, tandemParent, options ) {

options = merge( {
stroke: 'gray',
Expand Down Expand Up @@ -86,7 +86,7 @@ class CoverNode extends Node {
fill: FrictionConstants.BOOK_TEXT_COLOR,
pickable: false,
maxWidth: BINDING_LENGTH * 0.97, // for a bit of margin
tandem: tandem.createTandem( 'titleText' )
tandem: tandemParent.createTandem( 'titleText' )
} );
titleText.center = bindingRectangle.center;

Expand Down
4 changes: 4 additions & 0 deletions js/friction/view/magnifier/MagnifierNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ class MagnifierNode extends Node {
fill: null,
cursor: 'pointer',
children: [ background ],

// phet-io
tandem: options.tandem.createTandem( 'atomDragArea' ),
phetioVisiblePropertyInstrumented: false,
phetioInputEnabledPropertyInstrumented: true,

// pdom
focusHighlightLayerable: true,
Expand Down

0 comments on commit 2c81d29

Please sign in to comment.