Skip to content

Commit

Permalink
Move IO Type to core file, see phetsims/tandem#212
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid authored and jessegreenberg committed Apr 21, 2021
1 parent 8452a5d commit 006adbb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 71 deletions.
7 changes: 7 additions & 0 deletions js/photon-absorption/model/Molecule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
21 changes: 0 additions & 21 deletions js/photon-absorption/model/MoleculeIO.js

This file was deleted.

40 changes: 36 additions & 4 deletions js/photon-absorption/model/PhotonAbsorptionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -161,7 +161,7 @@ function PhotonAbsorptionModel( initialPhotonTarget, tandem ) {

PhetioObject.call( this, {
tandem: tandem,
phetioType: PhotonAbsorptionModelIO,
phetioType: PhotonAbsorptionModel.PhotonAbsorptionModelIO,
phetioState: false
} );
}
Expand Down Expand Up @@ -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;
46 changes: 0 additions & 46 deletions js/photon-absorption/model/PhotonAbsorptionModelIO.js

This file was deleted.

0 comments on commit 006adbb

Please sign in to comment.