Closed jessegreenberg closed 6 months ago
Here is a patch for this before needing to work on something else.
This required a brand new implementation for copying programs and templates. Since we don't have unit tests Ill have to test as much as I can manually.
I was able to test ~half way through the above list and so far its looking good. I was able to successfully create 3 programs that use a Derived component from a template (template Described Grid), which was the original motivation for the issue. @brettfiedler offered to take on the rest, thanks so much! Ill commit the changes to the dev branch.
Able to create copies of programs with animation link as well as standard link components. Verified this worked for inter- and intra- program links.
Custom Code Copying
Tried a custom code PhET Checkbox in bf-tests (after fixing all references of paperProgramNumber
-> paperNumber
and paperPoints
-> points
) - copying worked a-okay.
Tried copying both the Circle and Position custom code programs in creator-tests > custom-code-test. Using the copies in place of the originals worked fine!
Okay! There's potential funk here, but it might be the details of the implementation of this program.
I can successfully recall custom code programs from a template. I did this in local spaces using the PhET Checkbox and the Circle test above. I decided to try something more complicated and made a copy of AE's camera capture projection demo.
This all worked fine! Successfully used the program as it was in AE's space.
___ END OF PIECES FOR THIS ISSUE - I THINK EVERYTHING WORKS FINE____
___BEGIN NOTES ON WHAT I THINK IS A NON-ISSUE____
I think this might be due to line 172 in the Output Area_Copy where the inputBounds has not been renamed "inputBounds_copy", which makes sense since that program is external to the program that was copied and there is no anticipation that the other program was going to be copied! I think the onus here might be on the user to fix the dependencies in this instance.
// Draws the video feed onto the canvas
function drawVideo() {
// the input bounds come from another program so we need to be graceful in how we
// access it (it might not be added to the camera yet)
const inputModelBoundsProperty = phet.paperLand.getModelComponent( 'inputBounds' ); ***LINE 172***
if ( inputModelBoundsProperty ) {
const inputModelBounds = inputModelBoundsProperty.value;
const inputViewBounds = phet.paperLand.utils.paperToBoardBounds( inputModelBounds, sharedData.displaySize.width, sharedData.displaySize.height );
const outputModelBounds = phet.paperLand.getModelComponent( 'outputBounds_Copy1' ).value;
const outputViewBounds = phet.paperLand.utils.paperToBoardBounds( outputModelBounds, sharedData.displaySize.width, sharedData.displaySize.height );
canvasContext.clearRect(0, 0, canvasElement.width, canvasElement.height );
@jessegreenberg, I think all of copying and templating works for these! Is there anything else you wanted to see or more trials?
Awesome, thanks so much for going through this! I read through https://github.com/phetsims/paper-land/issues/200#issuecomment-1814978295 and agree with what you found. OK, closing!
When creating multiple programs from a single template, the order of operations is wrong. We load each program sequentially, loading dependencies before dependent components. What we need to do is load all dependencies in all programs and then load all dependent components in all programs (like how we do for loading a project).
I noticed this when trying to load a template that used a NamedDerivedProperty with dependencies in a different program.