Skip to content

Commit

Permalink
gravityAccordionBox refactored to use model.gravityProperty and model…
Browse files Browse the repository at this point in the history
….bodyProperty instead of the whole model. #64
  • Loading branch information
Denz1994 committed Mar 1, 2019
1 parent 0358e0f commit 1b9d627
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 9 additions & 9 deletions js/lab/view/GravityAccordionBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ define( require => {

class GravityAccordionBox extends AccordionBox {
/**
* @param {MassesAndSpringsModel} model
* @param {Property} gravityProperty
* @param {Property} bodyProperty
* @param {Node} listNodeParent
* @param {AlignGroup} alignGroup
* @param {Tandem} tandem
* @param {Object} [options]
*
*/

constructor( model, listNodeParent, alignGroup, tandem, options ) {
constructor( gravityProperty, bodyProperty, listNodeParent, alignGroup, tandem, options ) {

options = _.extend( {
buttonYMargin: 4,
Expand All @@ -53,7 +53,7 @@ define( require => {
}, options );

// Create gravity slider
const gravitySlider = new HSlider( model.gravityProperty, MassesAndSpringsConstants.GRAVITY_RANGE, {
const gravitySlider = new HSlider( gravityProperty, MassesAndSpringsConstants.GRAVITY_RANGE, {
majorTickLength: 5,
minorTickLength: 5,
trackSize: new Dimension2( 165, 0.1 ),
Expand Down Expand Up @@ -82,7 +82,7 @@ define( require => {
} );

// Manages the items associated with the gravity panel in a combo box
const gravityComboBox = new GravityComboBox( model.bodyProperty, listNodeParent, tandem, {
const gravityComboBox = new GravityComboBox( bodyProperty, listNodeParent, tandem, {
cornerRadius: 3,
buttonYMargin: 0,
itemYMargin: 3,
Expand All @@ -92,7 +92,7 @@ define( require => {
} );

// Responsible for managing bodies
model.bodyProperty.link( ( newBody, oldBody ) => {
bodyProperty.link( ( newBody, oldBody ) => {
const body = _.find( Body.BODIES, newBody );

// Set visibility of question node
Expand All @@ -101,17 +101,17 @@ define( require => {

// If it's not custom, set it to its value
if ( body !== Body.CUSTOM ) {
model.gravityProperty.set( body.gravity );
gravityProperty.set( body.gravity );
}
else {
// If we are switching from Planet X to Custom, don't let them cheat (go back to last custom value)
if ( oldBody === Body.PLANET_X ) {
model.gravityProperty.value = Body.CUSTOM.gravity;
gravityProperty.value = Body.CUSTOM.gravity;
}

// For non-Planet X, update our internal custom gravity
else {
Body.CUSTOM.gravity = model.gravityProperty.value;
Body.CUSTOM.gravity = gravityProperty.value;
}
}
} );
Expand Down
4 changes: 3 additions & 1 deletion js/lab/view/LabScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ define( require => {
// Panel that will display all the toggleable options.
const optionsPanel = this.createOptionsPanel( optionsVBox, this.rightPanelAlignGroup, tandem );

const gravityAccordionBox = new GravityAccordionBox( model,
const gravityAccordionBox = new GravityAccordionBox(
model.gravityProperty,
model.bodyProperty,
this,
this.rightPanelAlignGroup,
tandem.createTandem( 'gravityAccordionBox' ), {
Expand Down

0 comments on commit 1b9d627

Please sign in to comment.