Skip to content

Commit

Permalink
State schema improvements, see #183
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Sep 30, 2021
1 parent 18e56ce commit 8bba72b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
13 changes: 13 additions & 0 deletions js/common/model/Bond.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @author Jonathan Olson <[email protected]>
*/

import IOType from '../../../../tandem/js/types/IOType.js';
import NumberIO from '../../../../tandem/js/types/NumberIO.js';
import moleculeShapes from '../../moleculeShapes.js';

class Bond {
Expand Down Expand Up @@ -84,5 +86,16 @@ class Bond {
}
}

// @public {IOType}
Bond.BondIO = new IOType( 'BondIO', {
valueType: Bond,
stateSchema: {
a: NumberIO,
b: NumberIO,
order: NumberIO,
length: NumberIO
}
} );

moleculeShapes.register( 'Bond', Bond );
export default Bond;
23 changes: 2 additions & 21 deletions js/common/model/MoleculeShapesModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import BooleanIO from '../../../../tandem/js/types/BooleanIO.js';
import IOType from '../../../../tandem/js/types/IOType.js';
import NullableIO from '../../../../tandem/js/types/NullableIO.js';
import NumberIO from '../../../../tandem/js/types/NumberIO.js';
import ObjectLiteralIO from '../../../../tandem/js/types/ObjectLiteralIO.js';
import moleculeShapes from '../../moleculeShapes.js';
import Bond from './Bond.js';
import ElectronGeometry from './ElectronGeometry.js';
Expand Down Expand Up @@ -194,26 +193,8 @@ MoleculeShapesModel.MoleculeShapesModelIO = new IOType( 'MoleculeShapesModelIO',

stateSchema: {
isReal: BooleanIO,

// TODO: Provide IO Types to specify these schemas instead of ObjectLiteralIO, see https://github.com/phetsims/molecule-shapes/issues/183
// Shaped like this:
// {
// position: Vector3.Vector3IO,
// velocity: Vector3.Vector3IO,
// isLonePair: BooleanIO,
// element: NullableIO( StringIO ),
// isCentralAtom: BooleanIO
// }
groups: ArrayIO( ObjectLiteralIO ),

// Shaped like this:
// {
// a: NumberIO,
// b: NumberIO,
// order: NumberIO,
// length: NumberIO
// }
bonds: ArrayIO( ObjectLiteralIO ),
groups: ArrayIO( PairGroup.PairGroupIO ),
bonds: ArrayIO( Bond.BondIO ),
realMoleculeShape: NullableIO( RealMoleculeShape.RealMoleculeShapeIO ),
bondLengthOverride: NullableIO( NumberIO )
}
Expand Down
16 changes: 16 additions & 0 deletions js/common/model/PairGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import Property from '../../../../axon/js/Property.js';
import Vector3 from '../../../../dot/js/Vector3.js';
import Element from '../../../../nitroglycerin/js/Element.js';
import merge from '../../../../phet-core/js/merge.js';
import BooleanIO from '../../../../tandem/js/types/BooleanIO.js';
import IOType from '../../../../tandem/js/types/IOType.js';
import NullableIO from '../../../../tandem/js/types/NullableIO.js';
import StringIO from '../../../../tandem/js/types/StringIO.js';
import moleculeShapes from '../../moleculeShapes.js';

let nextId = 0;
Expand Down Expand Up @@ -323,4 +327,16 @@ function interpolate( a, b, ratio ) {
return a * ( 1 - ratio ) + b * ratio;
}

// @public {IOType}
PairGroup.PairGroupIO = new IOType( 'PairGroupIO', {
valueType: PairGroup,
stateSchema: {
position: Vector3.Vector3IO,
velocity: Vector3.Vector3IO,
isLonePair: BooleanIO,
element: NullableIO( StringIO ),
isCentralAtom: BooleanIO
}
} );

export default PairGroup;
2 changes: 1 addition & 1 deletion js/common/view/OptionsNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OptionsNode extends VBox {
const showLonePairsLabel = new Text( controlShowLonePairsString, {
font: optionsFont,
fill: MoleculeShapesColors.controlPanelTextProperty,
tandem: showBondAnglesCheckboxTandem.createTandem( 'labelText' )
tandem: showLonePairsCheckboxTandem.createTandem( 'labelText' )
} );

const showBondAnglesLabel = new Text( controlShowBondAnglesString, {
Expand Down

0 comments on commit 8bba72b

Please sign in to comment.