sb-edit icon indicating copy to clipboard operation
sb-edit copied to clipboard

CLI: scratchblocks output

Open towerofnix opened this issue 1 year ago • 2 comments
trafficstars

Following https://github.com/leopard-js/sb-edit/pull/129, we should be able to export to the other formats sb-edit has complete or partial support for.

Some notes:

  • scratchblocks conversion (#15) does support exporting every sprite at once, though it discards / ignores assets like costumes, sounds, initial sprite position/state, etc. But that's OK, since scratchblocks isn't a programming language (boo hoo).
    • Again, since it's not a programming language, we don't have precedent for a specific format to represent the entire project at once by. The interface outputs a mapping of target name to string including all its scripts. It's not the interface's job to make a call on what to do with the output; the CLI needs to choose an output structure.
    • Any output structure will work; personally, we'd just put all the results in a folder and write a txt for each target, containing exactly the string output by toScratchblocks.
  • There's no standard file extension for scratchblocks (spoilers: .sb is used by Scratch 1.4 projects) so we can never infer this output type; it's up to the user to specify -ot scratchblocks / --output-type scratchblocks. Otherwise we'll just export the default (when to a folder), which is leopard.
  • We don't really need to support .zip output for scratchblocks, but it would be nice, because leopard-zip and sb3 are both already portable / easy-to-share output types.
    • The CLI uses JSZip for zipping Leopard output (it's certainly not part of toLeopard's own behavior). There's not really any logic to factor out here since we're skipping costume/sound output and JSZip's own interface is pretty dead simple.

towerofnix avatar Apr 24 '24 11:04 towerofnix

One use case I can see for this is if users want to copy a script from a Scratch project into bbcode on the Scratch forums. I'm wondering if it would be useful to provide an interactive terminal output option where you can use arrow keys to select a certain sprite, then arrow keys to select a certain script, and then view that script as scratchblocks and potentially copy it to your clipboard.

PullJosh avatar Apr 24 '24 17:04 PullJosh

That would be really awesome. I wonder how difficult it would be? I think it would be the most useful if you can see a full preview of the script you have selected as you navigate through (and not just, for example, guess based on the top block). But that involves either a full-screen interface or "repainting" a possibly large (e.g. 8-12 lines) region of the terminal. Commander (used in the CLI right now) appears to be much more about just making a useful entry interface, not doing interesting live interaction effects, so we'd probably need to find some other library to handle this stuff.

towerofnix avatar Apr 24 '24 17:04 towerofnix