phetsims / projectile-motion

"Projectile Motion" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
15 stars 13 forks source link

Add projectilObjectType to serialization of Trajectory #242

Closed zepumph closed 3 years ago

zepumph commented 3 years ago

From a design meeting with @arouinfar and @kathy-phet. Please note parent issue in https://github.com/phetsims/projectile-motion/issues/244.

If the ProjectileObjectType is one of the instrumented globals, it would be nice if we could serialize that into the Trajectory, with just a phetioID.

zepumph commented 3 years ago

Something I noted is that every Trajectory has a unique ProjectileObjectType, if that changes, then the Trajectory will change too. Thus, we were able to pretty easily add this to the state of TrajectoryIO as projectileObjectType using ReferenceIO (possible because ProjectileObjectType is Tandem.REQUIRED.

Now a Trajectory in JSON looks like:

 "projectileMotion.introScreen.model.trajectoryGroup.trajectory_0": {
        "mass": 5,
        "diameter": 0.37,
        "dragCoefficient": 0.6,
        "changedInMidAir": true,
        "reachedGround": true,
        "apexPoint": null,
        "projectileObjectType": {
            "phetioID": "projectileMotion.global.model.projectileObjectTypes.pumpkin"
        }
    },

image

Note that this really was a bug, since projectileObjectType looked to be the last piece of data from Trajectory that wasn't stored in the serialization. Likely something weird was occurring downstream if projectileObjectTypes were changing between serializations. I can't be sure though. Most likely there wasn't anything too substantial, but this is definitely an improvement!

@arouinfar please review the above state and close if that data is acceptable.

arouinfar commented 3 years ago

Looks good, thanks!