diff --git a/js/photon-absorption/model/Molecule.js b/js/photon-absorption/model/Molecule.js index 1971665f..b58b7caa 100644 --- a/js/photon-absorption/model/Molecule.js +++ b/js/photon-absorption/model/Molecule.js @@ -17,6 +17,7 @@ import Vector2Property from '../../../../dot/js/Vector2Property.js'; import inherit from '../../../../phet-core/js/inherit.js'; import merge from '../../../../phet-core/js/merge.js'; import Tandem from '../../../../tandem/js/Tandem.js'; +import IOType from '../../../../tandem/js/types/IOType.js'; import moleculesAndLight from '../../moleculesAndLight.js'; import Atom from './atoms/Atom.js'; import AtomicBond from './atoms/AtomicBond.js'; @@ -606,4 +607,10 @@ inherit( Object, Molecule, { // @public {number} - distance from the molecule to query a photon for absorption, in picometers Molecule.PHOTON_ABSORPTION_DISTANCE = PHOTON_ABSORPTION_DISTANCE; +Molecule.MoleculeIO = new IOType( 'MoleculeIO', { + valueType: Molecule, + toStateObject: molecule => molecule.toStateObject(), + fromStateObject: Molecule.fromStateObject +} ); + export default Molecule; diff --git a/js/photon-absorption/model/MoleculeIO.js b/js/photon-absorption/model/MoleculeIO.js deleted file mode 100644 index a485036f..00000000 --- a/js/photon-absorption/model/MoleculeIO.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2020, University of Colorado Boulder - -/** - * IO Type for Molecule - * - * @author Sam Reid (PhET Interactive Simulations) - * @author Andrew Adare (PhET Interactive Simulations) - */ - -import IOType from '../../../../tandem/js/types/IOType.js'; -import moleculesAndLight from '../../moleculesAndLight.js'; -import Molecule from './Molecule.js'; - -const MoleculeIO = new IOType( 'MoleculeIO', { - valueType: Molecule, - toStateObject: molecule => molecule.toStateObject(), - fromStateObject: Molecule.fromStateObject -} ); - -moleculesAndLight.register( 'MoleculeIO', MoleculeIO ); -export default MoleculeIO; \ No newline at end of file diff --git a/js/photon-absorption/model/PhotonAbsorptionModel.js b/js/photon-absorption/model/PhotonAbsorptionModel.js index 9c289153..0aa27373 100644 --- a/js/photon-absorption/model/PhotonAbsorptionModel.js +++ b/js/photon-absorption/model/PhotonAbsorptionModel.js @@ -27,9 +27,10 @@ import EnumerationIO from '../../../../phet-core/js/EnumerationIO.js'; import inherit from '../../../../phet-core/js/inherit.js'; import TimeSpeed from '../../../../scenery-phet/js/TimeSpeed.js'; import PhetioObject from '../../../../tandem/js/PhetioObject.js'; +import IOType from '../../../../tandem/js/types/IOType.js'; import NumberIO from '../../../../tandem/js/types/NumberIO.js'; import moleculesAndLight from '../../moleculesAndLight.js'; -import MoleculeIO from './MoleculeIO.js'; +import Molecule from './Molecule.js'; import CH4 from './molecules/CH4.js'; import CO from './molecules/CO.js'; import CO2 from './molecules/CO2.js'; @@ -39,7 +40,6 @@ import NO2 from './molecules/NO2.js'; import O2 from './molecules/O2.js'; import O3 from './molecules/O3.js'; import Photon from './Photon.js'; -import PhotonAbsorptionModelIO from './PhotonAbsorptionModelIO.js'; import PhotonIO from './PhotonIO.js'; import PhotonTarget from './PhotonTarget.js'; import WavelengthConstants from './WavelengthConstants.js'; @@ -133,7 +133,7 @@ function PhotonAbsorptionModel( initialPhotonTarget, tandem ) { this.activeMolecules = new ObservableArray( { tandem: tandem.createTandem( 'molecules' ), - phetioType: ObservableArray.ObservableArrayIO( MoleculeIO ) + phetioType: ObservableArray.ObservableArrayIO( Molecule.MoleculeIO ) } ); // Elements are of type Molecule. // @public (read-only) {Emitter} - emitter for when a photon is emitted from the emission point - useful in addition @@ -161,7 +161,7 @@ function PhotonAbsorptionModel( initialPhotonTarget, tandem ) { PhetioObject.call( this, { tandem: tandem, - phetioType: PhotonAbsorptionModelIO, + phetioType: PhotonAbsorptionModel.PhotonAbsorptionModelIO, phetioState: false } ); } @@ -494,4 +494,36 @@ inherit( PhetioObject, PhotonAbsorptionModel, { // @public {number} - horizontal velocity of photons when they leave the emitter, in picometers/second PhotonAbsorptionModel.PHOTON_VELOCITY = PHOTON_VELOCITY; +PhotonAbsorptionModel.PhotonAbsorptionModelIO = new IOType( 'PhotonAbsorptionModelIO', { + valueType: PhotonAbsorptionModel, + + /** + * @public + * @param photonAbsorptionModel + * TODO: eliminate this legacy pattern, see https://github.com/phetsims/tandem/issues/87 + */ + clearChildInstances( photonAbsorptionModel ) { + photonAbsorptionModel.clearPhotons(); + // instance.chargedParticles.clear(); + // instance.electricFieldSensors.clear(); + }, + + /** + * Create a dynamic particle as specified by the phetioID and state. + * @public + * @param {Object} photonAbsorptionModel + * @param {Tandem} tandem + * @param {Object} stateObject + * @returns {ChargedParticle} + */ + addChildElementDeprecated( photonAbsorptionModel, tandem, stateObject ) { + const value = PhotonIO.fromStateObject( stateObject ); + + const photon = new phet.moleculesAndLight.Photon( value.wavelength, tandem ); + photon.setVelocity( stateObject.vx, stateObject.vy ); + photonAbsorptionModel.photons.add( photon ); + return photon; + } +} ); + export default PhotonAbsorptionModel; diff --git a/js/photon-absorption/model/PhotonAbsorptionModelIO.js b/js/photon-absorption/model/PhotonAbsorptionModelIO.js deleted file mode 100644 index ab9f5bdf..00000000 --- a/js/photon-absorption/model/PhotonAbsorptionModelIO.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2017-2020, University of Colorado Boulder - -/** - * IO Type for PhotonAbsorptionModel - * - * @author Sam Reid (PhET Interactive Simulations) - */ - -import IOType from '../../../../tandem/js/types/IOType.js'; -import moleculesAndLight from '../../moleculesAndLight.js'; -import PhotonIO from './PhotonIO.js'; - -const PhotonAbsorptionModelIO = new IOType( 'PhotonAbsorptionModelIO', { - isValidValue: v => v instanceof phet.moleculesAndLight.PhotonAbsorptionModel, - - /** - * @public - * @param photonAbsorptionModel - * TODO: eliminate this legacy pattern, see https://github.com/phetsims/tandem/issues/87 - */ - clearChildInstances( photonAbsorptionModel ) { - photonAbsorptionModel.clearPhotons(); - // instance.chargedParticles.clear(); - // instance.electricFieldSensors.clear(); - }, - - /** - * Create a dynamic particle as specified by the phetioID and state. - * @public - * @param {Object} photonAbsorptionModel - * @param {Tandem} tandem - * @param {Object} stateObject - * @returns {ChargedParticle} - */ - addChildElementDeprecated( photonAbsorptionModel, tandem, stateObject ) { - const value = PhotonIO.fromStateObject( stateObject ); - - const photon = new phet.moleculesAndLight.Photon( value.wavelength, tandem ); - photon.setVelocity( stateObject.vx, stateObject.vy ); - photonAbsorptionModel.photons.add( photon ); - return photon; - } -} ); - -moleculesAndLight.register( 'PhotonAbsorptionModelIO', PhotonAbsorptionModelIO ); -export default PhotonAbsorptionModelIO; \ No newline at end of file