Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call into V2SVGAdapter instead of SVGRenderer #2800

Closed

Conversation

adroitwhiz
Copy link
Contributor

@adroitwhiz adroitwhiz commented Jan 8, 2021

Depends on scratchfoundation/scratch-svg-renderer#213 and scratchfoundation/scratch-gui#6547

Resolves

Resolves scratchfoundation/scratch-svg-renderer#211

Proposed Changes

This PR changes the costume loading API to use the new V2SVGAdapter API (a function) instead of the SvgRenderer API (a class).

Reason for Changes

By depending only on the parts of the SVG renderer API that are actually used here, this will allow the monolithic SvgRenderer class to be removed.

Test Coverage

Tested manually

@@ -8,8 +8,7 @@ const loadVector_ = function (costume, runtime, rotationCenter, optVersion) {
if (optVersion && optVersion === 2 && !runtime.v2SvgAdapter) {
log.error('No V2 SVG adapter present; SVGs may not render correctly.');
} else if (optVersion && optVersion === 2 && runtime.v2SvgAdapter) {
runtime.v2SvgAdapter.loadString(svgString, true /* fromVersion2 */);
svgString = runtime.v2SvgAdapter.toString();
svgString = runtime.v2SvgAdapter(svgString);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning to change this to always run, regardless of whether optVersion === 2 or not, since we want to run fixup on all SVGs. After that, we shouldn't need to export V2SVGAdapter from ScratchSVGRenderer, and we shouldn't need to run fixup in paint (since SVGs will pass through loadCostume before being loaded in paint)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know once that change goes in--I can rebase this after it does, to instead call:

serializeSvgToString(loadSvgString(svgString, optVersion === 2 /* fromVersion2 */));

One issue is that once we start exporting multiple individual functions, passing them all in from the GUI (whereas before, we only had to pass in a single SVGRenderer object) could start to get cumbersome. IIRC this change was made to make updating the SVG renderer dependency less painful--is there some way to encode "this package works with any version of scratch-svg-renderer, but use the parent package's version"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think peer dependencies? I would have to research them more.

@adroitwhiz
Copy link
Contributor Author

Closing in favor of #2954

@adroitwhiz adroitwhiz closed this Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split up the SvgRenderer monolith
2 participants