phetsims / keplers-laws

"Kepler's Laws" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
1 stars 1 forks source link

KeplersLawsModel overwrites `defaultBodyState` in superclass #192

Closed pixelzoom closed 1 year ago

pixelzoom commented 1 year ago

Discovered while adding missing readonly keywords in https://github.com/phetsims/my-solar-system/issues/214 ...

In SolarSystemCommonModel, defaultBodyState should be readonly, and it's assigned once in the constructor:

  protected defaultBodyState: BodyInfo[];
...
    this.defaultBodyState = this.availableBodies.map( body => body.info );

class KeplersLawsModel extends SolarSystemCommonModel, and overwrites defaultBodyState:

    this.defaultBodyState = [
      { active: true, mass: 200, position: new Vector2( 0, 0 ), velocity: new Vector2( 0, 0 ) },
      { active: true, mass: 50, position: new Vector2( 200, 0 ), velocity: new Vector2( 0, 81.6 ) }
    ];

defaultBodyState should be added as an option to SolarSystemCommonModelOptions.

AgustinVallejo commented 1 year ago

Made the above changes to correct this, let me know if they seem like the right approach.

pixelzoom commented 1 year ago

Looks good, and defaultBodyState is now readonly. Closing.