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

toLeopard: Serialize initial rotation style #118

Merged
merged 2 commits into from
Jul 27, 2023

Conversation

towerofnix
Copy link
Member

@towerofnix towerofnix commented Jul 24, 2023

This PR makes toLeopard represent the initial rotation style (which is already represented in IR and loaded by fromSb3).

Implementation notes:

  • Although we convert to the same Sprite.RotationStyle.ALL_AROUND/etc value both in block and initial-state serialization, we're mapping from different values. (sb3 block inputs like "all around" or "don't rotate" in the former, sb-edit values like "normal" or "none" in the latter.) Accordingly, it wasn't appropriate to introduce a constant mapping reused by both — but it's definitely a bit weird that sb-edit represent the input for "set rotation style" with the same values it uses for a sprite's initial rotation style.
  • I had to change the way we stringify sprites to support including an arbitrary expression in the initial-state object. The important part is that each key maps to an already "stringified" value, i.e. the exact expression that will be inserted, instead of implicitly stringifying all values with JSON.stringify on the whole object.
  • The output index.js file needs to import Sprite from Leopard's library file now, as well as Project (as it did before).

Tested with this project: https://scratch.mit.edu/projects/877138925/

And a "boring" project that makes sure the "set rotation style" blocks are still working.

Requested both @PullJosh and @adroitwhiz for review but an OK would be fine from either of you, this isn't a big pull request and improves Scratch compatibility for Leopard in a user-visible way!

@towerofnix towerofnix added the fmt: Leopard Pertains to Leopard format (JavaScript) label Jul 24, 2023
Copy link
Collaborator

@PullJosh PullJosh left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you! 😄

@PullJosh PullJosh merged commit 4e3f8c8 into leopard-js:master Jul 27, 2023
@towerofnix towerofnix deleted the rot-style branch July 27, 2023 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fmt: Leopard Pertains to Leopard format (JavaScript)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preserve rotation style when converting to Leopard
2 participants