ScratchAddons icon indicating copy to clipboard operation
ScratchAddons copied to clipboard

New addon: `editor-copy-scratchblocks`

Open just-a-hriday opened this issue 1 year ago • 20 comments

Resolves #2336 Closes #7748 Closes #8572

Changes

Adds an addon that converts blocks in the editor to forums scratchblocks code. Supports all obsolete blocks and handles all edge cases.

Known issues Comments are not included in the output because scratchblocks only allows you to add comments to outer blocks (so comments on reporters inside other blocks, for example, can't be included), and long comments get cut off.

Scratchblocks doesn't support matrix inputs (the ones used in micro:bit), so they get outputted as dropdowns containing a numerical representation of the matrix.


⬇️

Reason for changes

Makes it much easier to post scripts in the forums.

Tests

Testing with Chrome v131.0.6778.109 on 64 bit Windows.

just-a-hriday avatar Dec 10 '24 13:12 just-a-hriday

This addon has already been submitted in #7748 but I haven't checked the differences in the implementation yet.

Samq64 avatar Dec 11 '24 01:12 Samq64

This addon has already been submitted in #7748 but I haven't checked the differences in the implementation yet.

Hmm. Mine only supports english, but does give better (and less buggy) output.

Also, there's another implementation that might be possible - just reading the fields in the blocks instead of hardcoding everything. This would give complete language support too.

I tried this a while ago when the forums were still using 2.0 scratchblocks. It didn't work, because a lot of 3.0 blocks have different text from their 2.0 counterparts, and language support was an issue too - but I think it could work with the 3.0 scratchblocks.

just-a-hriday avatar Dec 11 '24 02:12 just-a-hriday

@WorldLanguages could you review?

just-a-hriday avatar Dec 22 '24 01:12 just-a-hriday

There was also temporarily a way to backpack scratchblocks code on the forums (like the other way around or inverse for this sort of), but it was removed because invalid blocks could be backpacked so I was wondering if a similar thing could be added.

medlans avatar Dec 30 '24 00:12 medlans

That was suggested in #3225 and should probably be a separate addon.

Samq64 avatar Dec 30 '24 01:12 Samq64

There was also temporarily a way to backpack scratchblocks code on the forums (like the other way around or inverse for this sort of), but it was removed because invalid blocks could be backpacked so I was wondering if a similar thing could be added.

I'm working on an addon for that too actually.

just-a-hriday avatar Dec 30 '24 02:12 just-a-hriday

How important is language support? I can add it but it'll take some work.

just-a-hriday avatar Dec 31 '24 14:12 just-a-hriday

How important is language support?

I would think it's fine as long as the user can understand the limitations. What happens if I click "copy block as scratchblocks code" if my Scratch editor is set to Spanish?

WorldLanguages avatar Dec 31 '24 15:12 WorldLanguages

What happens if I click "copy block as scratchblocks code" if my Scratch editor is set to Spanish?

It'll work no matter what the editor language is, but the output is always english.

just-a-hriday avatar Dec 31 '24 16:12 just-a-hriday

What happens if I click "copy block as scratchblocks code" if my Scratch editor is set to Spanish?

It'll work no matter what the editor language is, but the output is always english.

That might actually be a good thing because English blocks work everywhere on the forums. Blocks in other languages only work on that language's forum if it exists.

mxmou avatar Dec 31 '24 16:12 mxmou

If this will only support English, it might be a good thing to add a note to the addon explaining that that's intentional (for users of other languages)?

mybearworld avatar Jan 02 '25 20:01 mybearworld

When copying from a language other than English, the dropdowns are not translated, leading to a weird mix of languages:

image

mybearworld avatar Jan 03 '25 17:01 mybearworld

When copying from a language other than English, the dropdowns are not translated, leading to a weird mix of languages:

Fixed.

just-a-hriday avatar Jan 05 '25 07:01 just-a-hriday

If this will only support English, it might be a good thing to add a note to the addon explaining that that's intentional (for users of other languages)?

How should it be worded? It needs to be clear that users can use it no matter what their editor language is.

Edit: is this alright?

just-a-hriday avatar Jan 05 '25 08:01 just-a-hriday

How should it be worded? It needs to be clear that users can use it no matter what their editor language is.

I don't think it's necessary to clarify that.

Edit: is this alright?

Sure, looks alright to me. Something along the lines of This addon can only output English scratchblocks code. as an info (no need to make it a notice!)

WorldLanguages avatar Jan 05 '25 22:01 WorldLanguages

This conflicts with the other editor-copy-scratchblocks addon I'm working on in PR #7748. There is this addon by just-a-hriday, and another version by me with different code but the same basic features and addon ID.

There are advantages of both versions of the addon. My addon uses the parse-sb3-blocks library by apple502j for block conversion, it has a few bugs but support for (almost?) every block and language in the Scratch editor.

On the other hand, hriday's addon accesses blocks more directly and uses less code, but does not support other languages. I think language support is important for non-English Scratchers who write Forum posts, Scratch Wiki pages and other things, though most parts of the Forums only support blocks in English.

It's fine if you want to use this version of the addon instead of mine. I just don't know if I should keep working on this or not.

pumpkinhasapatch avatar Jan 25 '25 01:01 pumpkinhasapatch

@Samq64 How should I add support for turbowarp blocks? Is there a way to check whether the addon is being run in turbowarp? It doesn't make much sense to add hardcoded turbowarp blocks inside the scratch editor too.

just-a-hriday avatar Sep 20 '25 01:09 just-a-hriday

I think mainatining return [], <is compiled>, etc. in Turbowarp's fork of Scratch Addons is fine. If you want to support all of Turbowarp's extensions though then the mapping approach isn't really feasible since there are almost 100 of them now.

Samq64 avatar Sep 20 '25 02:09 Samq64

The mapping is significantly simpler for turbowarp. With vanilla scratch blocks you have to work around all the inconsistencies and idiosyncrasies of scratchblocks. With the turbowarp blocks you have to override them all to make them render correctly anyways, so it's much simpler. In fact I think it's possible to automate mapping the extension blocks, and I believe that's the best solution here.

For turbowarp blocks Lu Yifei's approach works well too. However it is not reliable for vanilla scratch blocks, so a complicated hybrid approach would have to be used in order to use that method for turbowarp extension blocks and mine for the vanilla blocks. On the other hand there's no need to build mappings for those 100+ extensions if it's done that way.

just-a-hriday avatar Sep 20 '25 05:09 just-a-hriday

If you used the scratch-translations then you'll get most of the mapping for free. But it would require quite a large change to how you're doing things. It is quite a different approach to things.

But you should be able to do most of it dynamically instead of having to hardcode things anymore.

Joeclinton1 avatar Sep 20 '25 15:09 Joeclinton1