Snap! file format spec?

Hi, I recently decided to attempt to make a snap to scratch comverter because I thought it would be fun, and because it appears one doesn't exist yet (someone asked in the scratch ATs, and the answer was no). I know that it will be impossible to properly comvert some aspectsof snap to scratch, but for now I'm just going for direct block-block translation. However, I can't seem to find a source anywhere which explains how snap's xml files are structured and what to expect from them, and I can't seem to make much sense of the source code, and I'll never be able to get a full understanding just by loooing at the examples and other projects that I download.
So the question is: does anyone have a guide of some sort that explains exactly how snap project xml will be laid out, or if not, does anyone have a good enough understanding of it (and enough willing to write it all out) that they could explain it in a post?
Thanks for any help you can provide :slight_smile:

Welcome to the forums, but no, I can't help.
Maybe you should ask @bh or @jens?

Hey, have I seen you on the Scratch forums?
I honestly don't know because it looks awfully complicated, so it's probably a question for the developers.

Yup, you have :slight_smile: I'm pufferfish_test and pufferfish101007 there.

Also, for anyone answering this, I've developed a basic understanding of the xml format - if a dev could let me know if this is correct and maybe expand on it that would be great :slight_smile:
Here's a bad template of it if you can make sense of it:

  • project with name = project name, app = Snap! ${MAJOR_VERSION_NUMBER},, version = 1
    • notes
    • thumbnail - as a data url
    • stage with name = Stage and a list of effects such as pan, volume, height etc
      • pentrail - as a data url
      • costumes - as a list
      • sounds - ditto
      • variables - ditti
      • blocks - custom blocks for the stage?
      • scripts - I'm assuming the same format as sprite scripts, for stage scripts
      • sprites - list of sprites
        • sprite - one for each sprite, similar attrs to the stage for effects
          • costumes, sounds, blocks, scripts all the same as in stage
    • hidden - not sure
    • headers - not sure
    • code - not sure
    • blocks - global custom blocks maybe? Idk if they exist
    • variables - global variables I guess, as a list element

Lists are list elements, with ls as items?
Scripts have script elements, which have block elements, which have l elements, assumingly inputs/fields, and thise gave different things depending on what type of inout it is, includingoption for options. C-blocks' inputs are represented as scripts.


if you look at @wunder_wulfe's xml generator project, I think you will get an understanding of the xml block files.

Thanks - that's going to be incredibly helpful for the block generation.
Still looking for some more info on the entire project structure though...

Your understanding seems correct. <hidden> stores hidden primitives (you can do that by right-clicking blocks in the palette), and I believe <headers> and <code> are related to codification, and since Scratch doesn't have those you can safely ignore them.

The definitive source on the Snap! file format is store.js in the source code:

You may also find the Snapinator source code useful since it does what you want to, but in reverse:

Thank you so much - both of those links are incredibly useful. I don't know how I missed store.js before :crazy_face:
I did notice that list items are in fact item elements - I'm not quite sure where I got l from.

Oh, I missed that. The l element represents a datum like a string or number. You'll often see it as an argument for blocks and sometimes inside an item element.

Ah thanks, that makes sense.