JSON documents; remove the extended format
Documents can be saved as the editor's own JSON (Save as JSON, in Configure's
Serialization row, off by default) and any .anm2 starting with '{' opens as
one. The schema is new, not an XML mirror: content items in arrays (an item's
index is its id), animations keyed by unique name (a repeat saves as "Name 2"),
groups nested, paired values as arrays, a frame on a region storing only the
region, ISO 8601 dates, every default left out, and one line per frame and
content item, with anything else that fits in 100 columns on one line. Unknown
XML isn't kept. Each part is described once (frame_io, track_io, model_io...)
and run by a JsonWriter or a JsonReader; simdjson parses (new submodule). A
JSON file that opens but has unknown keys, wrong types, unknown values or bad
indices lists them by location in a warning toast; libraries toast their load
problems too. With Save as JSON on, saving always shows the Isaac warning.
The extended format is gone: no setting, File menu toggle, ExtendedVersion or
isExtendedFormat. XML saves are always the game's copy with SourceDocument;
old extended files still open. Document saves take Options instead of loose
bools, and model_load reads through model_load_string. docs/json_format.md
replaces docs/extended_format.md; goldens lose ExtendedVersion and the
.extended variants.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d77b2bae71
commit
b69b0eaa1b
121 files changed
+1248
-913
No files matched your search
@@ -1,162 +0,0 @@
|
||||
# Anm2Ed extended format (ExtendedVersion 2)
|
||||
|
||||
An extended `.anm2` is the editor's own document, saved alone. It is the Rebirth `.anm2` XML with extra elements and attributes. This page lists what it adds and how the editor plays it, so that a converter or a game's loader can match the editor exactly.
|
||||
|
||||
A Rebirth document is different: it saves the game's copy, followed by the extended document embedded as `<SourceDocument>`. A loader for extended files can ignore it.
|
||||
|
||||
## Recognizing one
|
||||
```xml
|
||||
<AnimatedActor>
|
||||
<Info CreatedBy="…" CreatedOn="…" Fps="30" Version="…" ExtendedVersion="2"/>
|
||||
…
|
||||
```
|
||||
- **`ExtendedVersion`** is present only on extended documents.
|
||||
- **Version 1** files can only use the features marked *(v1)*.
|
||||
- **Unknown elements and attributes** are kept by the editor and written back unchanged.
|
||||
|
||||
## Content
|
||||
```xml
|
||||
<Content>
|
||||
<Spritesheets>
|
||||
<Spritesheet Id="0" Path="parts.png"/>
|
||||
<Spritesheet Id="1" Path="body.svg">
|
||||
<Region Id="0" Name="head" XCrop="48" YCrop="0" Width="32" Height="32" Origin="Center"/>
|
||||
</Spritesheet>
|
||||
</Spritesheets>
|
||||
<Layers>
|
||||
<Layer Id="0" Name="torso" SpritesheetId="1"/>
|
||||
<Layer Id="1" Name="hx" SpritesheetId="0" Animation="Head"/>
|
||||
<Layer Id="2" Name="shadow" SpritesheetId="0" Library="0" Animation="SmallShadow"/>
|
||||
</Layers>
|
||||
<Nulls>…</Nulls>
|
||||
<Events>
|
||||
<Event Id="0" Name="shoot"/>
|
||||
<Event Id="1" Name="done"/>
|
||||
</Events>
|
||||
<Sounds>…</Sounds>
|
||||
<Libraries>
|
||||
<Library Id="0" Path="shared/shadows.anm2"/>
|
||||
</Libraries>
|
||||
</Content>
|
||||
```
|
||||
|
||||
**SVG spritesheets**
|
||||
- A spritesheet whose path ends in `.svg` is an SVG.
|
||||
- One SVG unit is one pixel. Crops, sizes and pivots are in SVG units.
|
||||
- The editor draws an SVG at whatever resolution it is shown at.
|
||||
|
||||
**Regions** *(v1)*
|
||||
- `Origin` is `TopLeft`, `Center`, or absent (custom, with `XPivot`/`YPivot`).
|
||||
- A layer frame with `RegionId` takes the region's crop, size and pivot.
|
||||
|
||||
**Libraries**
|
||||
- A library is another `.anm2` whose animations layers can play.
|
||||
- `Path` is relative to the file that names it, so a library's own libraries are relative to that library.
|
||||
|
||||
**Layers**
|
||||
- A layer either shows its spritesheet, or plays an animation when `Animation` is set.
|
||||
- **Same file or library:** with no `Library`, the animation comes from this file. With `Library`, it comes from that library.
|
||||
- **`SpritesheetId`** is still written on animation layers (the game expects it) but is not used.
|
||||
- **Instance name:** the layer's `Name` is the name code should use for the instance.
|
||||
- **No self-nesting:** an animation never plays inside itself, even through other animations. That draw is skipped.
|
||||
|
||||
## Animations
|
||||
```xml
|
||||
<Animations DefaultAnimation="Walk">
|
||||
<Animation Name="Walk" FrameNum="24" Loop="true" StartMarker="4" EndMarker="19">
|
||||
<RootAnimation>…frames…</RootAnimation>
|
||||
<LayerAnimations>
|
||||
<LayerAnimation LayerId="0" Visible="true">…frames…</LayerAnimation>
|
||||
<Group Name="arms" IsExpanded="true" Visible="true">
|
||||
<RootAnimation>…frames…</RootAnimation>
|
||||
<LayerAnimation LayerId="3" Visible="true">…</LayerAnimation>
|
||||
</Group>
|
||||
</LayerAnimations>
|
||||
<NullAnimations>…</NullAnimations>
|
||||
<Triggers>
|
||||
<Trigger EventId="0" AtFrame="12"><Sound Id="0"/></Trigger>
|
||||
<Trigger EventId="0" AtFrame="23"><Event Id="1"/></Trigger>
|
||||
</Triggers>
|
||||
</Animation>
|
||||
</Animations>
|
||||
```
|
||||
|
||||
**Markers** *(v1)*
|
||||
- `StartMarker`/`EndMarker` keep editor playback between those frames, inclusive. They are editor-only.
|
||||
|
||||
**Groups** *(v1)*
|
||||
- A group nests tracks and has its own `RootAnimation`, a transform applied to its tracks after the animation's root.
|
||||
|
||||
**Layer order**
|
||||
- Layers draw in `LayerAnimations` order: the first one is drawn first, so it ends up at the bottom.
|
||||
- `Depth` on a layer frame moves it among the layers for that frame. The sort key is (position in the list + depth, depth).
|
||||
|
||||
**Triggers**
|
||||
- A trigger's events are its `EventId`, followed by its `<Event Id/>` children in order. All of them fire on `AtFrame`.
|
||||
- `<Sound Id/>` children are the trigger's sounds. The editor picks one at random.
|
||||
- An older single `SoundId` attribute is still read.
|
||||
|
||||
## Frames
|
||||
Attributes on `<Frame>` (layer, null and root tracks):
|
||||
|
||||
| Attribute | Meaning |
|
||||
|---|---|
|
||||
| `XPosition`, `YPosition` | Position in pixels; y points down. |
|
||||
| `XPivot`, `YPivot` | Pivot in the frame's pixels (layer frames). |
|
||||
| `XCrop`, `YCrop`, `Width`, `Height` | The spritesheet rectangle (layer frames). |
|
||||
| `XScale`, `YScale` | Scale in percent. A negative value flips. |
|
||||
| `Rotation` | Degrees, clockwise on screen. |
|
||||
| `SkewX`, `SkewY` *(v1)* | Skew in percent: `x' = x + SkewX/100·y`, `y' = y + SkewY/100·x`. Older files say `ShearX`/`ShearY`. |
|
||||
| `RedTint` … `AlphaTint` | 0–255, multiplied. |
|
||||
| `RedOffset` … `BlueOffset` | 0–255, added after the tint. |
|
||||
| `AlphaOffset` | 0–255 (may be negative), added to alpha after the tint; the result is clamped to 0–1. |
|
||||
| `Blur` | Flash's low-quality BlurFilter: a box this many canvas pixels wide, averaged over the frame's crop. |
|
||||
| `Depth` *(v1)* | Layer frames only; see Layer order. |
|
||||
| `ShaderId` *(v1)* | A custom shader from `<Shaders>`. |
|
||||
| `Delay` | Duration in frames. |
|
||||
| `Visible` | Hidden frames draw nothing. |
|
||||
| `Interpolated` | `false`, `true` (linear), `EaseIn` (t²), `EaseOut` (1−(1−t)²) or `EaseInOut`. It blends position, scale, skew, rotation, tint, color offset and blur toward the next frame. |
|
||||
|
||||
**A layer frame's transform.** A point `p` of the spritesheet crop, in pixels, lands at:
|
||||
```
|
||||
world = Root · GroupRoot · ( position + Flip · Rotate · Skew · |scale| · (p − pivot) )
|
||||
```
|
||||
- `Flip` holds the signs of the scale. When exactly one axis is flipped, the rotation turns the other way.
|
||||
- A root's transform is `position + Flip · Rotate · Skew · |scale| · p`. A root has no pivot.
|
||||
|
||||
### Animation layer frames
|
||||
On a layer that plays an animation, a frame places and plays the child:
|
||||
|
||||
| Attribute | Default | Meaning |
|
||||
|---|---|---|
|
||||
| `ChildAnimation` | the layer's | The animation this keyframe plays, from the same file or library. |
|
||||
| `ChildMode` | `Loop` | `Loop`, `Once` (stops on its last frame) or `Hold` (stays on the start frame). |
|
||||
| `ChildStart` | `0` | The child's frame when its clock starts, or `Random`. |
|
||||
| `Restart` | `false` | Restarts the child's clock at this keyframe. |
|
||||
|
||||
**Placement.** The child's whole drawing goes through the frame's transform, with the frame's pivot as the child's origin:
|
||||
```
|
||||
world = Root · GroupRoot · ( position + Flip · Rotate · Skew · |scale| · (q − pivot) )
|
||||
```
|
||||
- `q` is a point in the child's space, after the child's own root and groups.
|
||||
- **Colour:** the frame's tint multiplies the child's colour, and its colour offset adds to it.
|
||||
- **Unused fields:** crop, size, region and shader are not used.
|
||||
|
||||
**Timing.** The child's time when the parent is at time `t`:
|
||||
1. **Clock start.** The child's clock starts at the first keyframe. It restarts at any keyframe with `Restart="true"`, or whose `ChildAnimation` differs from the previous keyframe's. Each start begins at that keyframe's `ChildStart`.
|
||||
2. **Child time.** Take the start keyframe that most recently began (call its start frame `S` and its `ChildStart` `C`). The child time is `C + (t − S)`.
|
||||
3. **Mode.** The keyframe playing at `t` decides the mode:
|
||||
- `Loop` wraps the time over the child's `FrameNum`.
|
||||
- `Once` stops at `FrameNum − 1`.
|
||||
- `Hold` uses that keyframe's own `ChildStart`.
|
||||
4. **Random start.** A `Random` start is `(layerId·73856093 xor keyframeIndex·19349663) mod FrameNum`, using unsigned 32-bit arithmetic.
|
||||
|
||||
**Child triggers.** A child fires its trigger on each frame it reaches. That is the frames where its whole-number time, or its animation, differs from the previous parent frame's, and always on parent frame 0. A held child fires once.
|
||||
|
||||
## Rebirth copies
|
||||
A Rebirth document's game copy keeps only what the game reads:
|
||||
- **Animation layers** are flattened into plain layers, one per layer the child draws, named `layer/childLayer`. Their frames are baked one per frame and skew is dropped. A library's spritesheets are added with paths relative to the document.
|
||||
- **Children's trigger events** join the animation's triggers, matched by name.
|
||||
- **Triggers** keep one event each: the first.
|
||||
- **Dropped attributes:** markers, depth, skew, alpha offset, blur, shaders, extra events, trigger sounds and libraries.
|
||||
- **SVG spritesheets** are offered for conversion to PNGs before saving.
|
||||
@@ -0,0 +1,192 @@
|
||||
# Anm2Ed JSON format (version 1)
|
||||
|
||||
The JSON format is the editor's own document, saved alone when **Save as JSON** is on (Configure → Serialization). It holds everything the editor knows about a document; the game can't read it. This page lists its shape and how the editor plays it, so that a converter or a game's loader can match the editor exactly.
|
||||
|
||||
A regular save is different: it writes the game's `.anm2` XML, with the editor's copy embedded as `<SourceDocument>`. See [XML saves](#xml-saves).
|
||||
|
||||
## Recognizing one
|
||||
```json
|
||||
{
|
||||
"anm2ed": 1,
|
||||
"info": {"createdBy": "…", "createdOn": "2026-01-01T12:00:00", "fps": 30, "version": 2},
|
||||
…
|
||||
}
|
||||
```
|
||||
- **`anm2ed`** is the format version. A JSON file without it is not opened.
|
||||
- **Defaults are left out.** Any key missing from an object has its default (listed below).
|
||||
- **Ids are indices.** An item is referred to by its position in its array, starting at 0.
|
||||
- **Unknown keys, wrong types, unknown values and out-of-range indices** are reported by where they are (e.g. `animations.Idle.layers[0].frames[2].pos: expected an array of 2 numbers`); the document still opens, with the default in their place.
|
||||
- **`createdOn`** is ISO 8601 local time.
|
||||
|
||||
## Content
|
||||
```json
|
||||
"spritesheets": [
|
||||
{"path": "parts.png"},
|
||||
{
|
||||
"path": "body.svg",
|
||||
"regions": [
|
||||
{"name": "head", "crop": [48, 0], "size": [32, 32], "pivot": [16, 16], "origin": "center"}
|
||||
]
|
||||
}
|
||||
],
|
||||
"shaders": [
|
||||
{"name": "glow", "vertex": "glow.vs", "fragment": "glow.fs", "uniforms": [{"name": "strength", "value": "0.5"}]}
|
||||
],
|
||||
"layers": [
|
||||
{"name": "torso", "sheet": 1},
|
||||
{"name": "hx", "animation": "Head"},
|
||||
{"name": "shadow", "library": 0, "animation": "SmallShadow"}
|
||||
],
|
||||
"nulls": [
|
||||
{"name": "hitbox", "showRect": true}
|
||||
],
|
||||
"events": [
|
||||
"shoot",
|
||||
"done"
|
||||
],
|
||||
"sounds": [
|
||||
"sounds/step.ogg"
|
||||
],
|
||||
"libraries": [
|
||||
"shared/shadows.anm2"
|
||||
]
|
||||
```
|
||||
|
||||
| Item | Key | Default | Meaning |
|
||||
|---|---|---|---|
|
||||
| Spritesheet | `path` | | The image, relative to the document. |
|
||||
| Region | `name` | `""` | |
|
||||
| | `crop`, `size`, `pivot` | `[0, 0]` | The rectangle in the spritesheet, and its pivot. |
|
||||
| | `origin` | custom | `topLeft` or `center` sets the pivot from the size. |
|
||||
| Shader | `name`, `vertex`, `fragment` | `""` | A custom shader and its source files. |
|
||||
| | `uniforms` | none | `{ name, binding, value, components: [ { index, binding, value } ] }` |
|
||||
| Layer | `name` | `""` | The name code should use for the layer (or its instance). |
|
||||
| | `sheet` | `0` | Its spritesheet; `-1` for one that is missing. |
|
||||
| | `animation` | none | Makes it an animation layer, playing this animation. |
|
||||
| | `library` | none | Where `animation` comes from; none means this file. |
|
||||
| Null | `name` | `""` | |
|
||||
| | `showRect` | `false` | |
|
||||
| Event, sound, library | | | A name, or a path relative to the document. |
|
||||
|
||||
**SVG spritesheets**
|
||||
- A spritesheet whose path ends in `.svg` is an SVG.
|
||||
- One SVG unit is one pixel. Crops, sizes and pivots are in SVG units.
|
||||
- The editor draws an SVG at whatever resolution it is shown at.
|
||||
|
||||
**Libraries**
|
||||
- A library is another `.anm2` (XML or JSON) whose animations layers can play.
|
||||
- A path is relative to the file that names it, so a library's own libraries are relative to that library.
|
||||
|
||||
**Layers**
|
||||
- A layer either shows its spritesheet, or plays an animation when `animation` is set.
|
||||
- **No self-nesting:** an animation never plays inside itself, even through other animations. That draw is skipped.
|
||||
|
||||
## Animations
|
||||
Animations are an object keyed by their name; names are unique (a repeated one is saved as `"Name 2"`, `"Name 3"`…). A key whose object has an `animations` object is a group of animations.
|
||||
```json
|
||||
"defaultAnimation": "Walk",
|
||||
"animations": {
|
||||
"Walk": {
|
||||
"length": 24, "startMarker": 4, "endMarker": 19,
|
||||
"root": […frames…],
|
||||
"layers": [
|
||||
{"layer": 0, "frames": […frames…]},
|
||||
{"group": "arms", "root": […frames…], "layers": [{"layer": 3, "frames": […]}]}
|
||||
],
|
||||
"nulls": [{"null": 0, "frames": […]}],
|
||||
"triggers": [
|
||||
{"at": 12, "events": [0], "sounds": [0]},
|
||||
{"at": 23, "events": [0, 1]}
|
||||
]
|
||||
},
|
||||
"Combat": {"expanded": false, "animations": {"Attack": {…}}}
|
||||
}
|
||||
```
|
||||
|
||||
| Key | Default | Meaning |
|
||||
|---|---|---|
|
||||
| `length` | `1` | Frames in the animation. |
|
||||
| `loop` | `true` | |
|
||||
| `startMarker`, `endMarker` | none | Editor playback stays between these frames, inclusive. Editor-only. |
|
||||
| `root`, `triggers` | none | Frame arrays. |
|
||||
| `layers`, `nulls` | none | Tracks and groups, in order. |
|
||||
| Track `layer` / `null` | | The item the track animates. |
|
||||
| Track `visible` | `true` | |
|
||||
| Group `group` | | The group's name; always present. |
|
||||
| Group `expanded`, `visible` | `true` | Timeline state. |
|
||||
| Group `root` | one default frame | A transform applied to its tracks after the animation's root. |
|
||||
| Trigger `at` | | The frame it fires on. |
|
||||
| Trigger `events` | none | Every event fires on `at`. |
|
||||
| Trigger `sounds` | none | The editor picks one at random. |
|
||||
|
||||
**Layer order**
|
||||
- Layers draw in `layers` order: the first one is drawn first, so it ends up at the bottom.
|
||||
- `depth` on a layer frame moves it among the layers for that frame. The sort key is (position in the list + depth, depth).
|
||||
|
||||
## Frames
|
||||
Keys on a frame of a layer, null or root track:
|
||||
|
||||
| Key | Default | Meaning |
|
||||
|---|---|---|
|
||||
| `pos` | `[0, 0]` | Position in pixels; y points down. |
|
||||
| `region` | none | Layer frames: a region of the layer's spritesheet. The frame takes its crop, size and pivot, and has none of its own. |
|
||||
| `crop`, `size` | `[0, 0]` | Layer frames without a region: the spritesheet rectangle. |
|
||||
| `pivot` | `[0, 0]` | Layer frames without a region: the pivot in the frame's pixels. |
|
||||
| `scale` | `[100, 100]` | Percent. A negative value flips. |
|
||||
| `rotation` | `0` | Degrees, clockwise on screen. |
|
||||
| `skew` | `[0, 0]` | Percent: `x' = x + skew.x/100·y`, `y' = y + skew.y/100·x`. |
|
||||
| `tint` | `[255, 255, 255, 255]` | RGBA, multiplied. |
|
||||
| `offset` | `[0, 0, 0, 0]` | RGBA, added after the tint. Alpha may be negative; the result is clamped to 0–1. |
|
||||
| `blur` | `0` | Layer frames: Flash's low-quality BlurFilter, a box this many canvas pixels wide, averaged over the frame's crop. |
|
||||
| `depth` | `0` | Layer frames; see Layer order. |
|
||||
| `shader` | none | A custom shader from `shaders`. |
|
||||
| `delay` | `1` | Duration in frames. |
|
||||
| `visible` | `true` | Hidden frames draw nothing. |
|
||||
| `interpolation` | none | `linear`, `easeIn` (t²), `easeOut` (1−(1−t)²) or `easeInOut`. It blends position, scale, skew, rotation, tint, color offset and blur toward the next frame. |
|
||||
|
||||
**A layer frame's transform.** A point `p` of the spritesheet crop, in pixels, lands at:
|
||||
```
|
||||
world = Root · GroupRoot · ( pos + Flip · Rotate · Skew · |scale| · (p − pivot) )
|
||||
```
|
||||
- `Flip` holds the signs of the scale. When exactly one axis is flipped, the rotation turns the other way.
|
||||
- A root's transform is `pos + Flip · Rotate · Skew · |scale| · p`. A root has no pivot.
|
||||
|
||||
### Animation layer frames
|
||||
On a layer that plays an animation, a frame places and plays the child:
|
||||
|
||||
| Key | Default | Meaning |
|
||||
|---|---|---|
|
||||
| `child` | the layer's | The animation this keyframe plays, from the same file or library. |
|
||||
| `childMode` | `loop` | `loop`, `once` (stops on its last frame) or `hold` (stays on the start frame). |
|
||||
| `childStart` | `0` | The child's frame when its clock starts. |
|
||||
| `childStartRandom` | `false` | Start on a random frame instead. |
|
||||
| `restart` | `false` | Restarts the child's clock at this keyframe. |
|
||||
|
||||
**Placement.** The child's whole drawing goes through the frame's transform, with the frame's pivot as the child's origin:
|
||||
```
|
||||
world = Root · GroupRoot · ( pos + Flip · Rotate · Skew · |scale| · (q − pivot) )
|
||||
```
|
||||
- `q` is a point in the child's space, after the child's own root and groups.
|
||||
- **Colour:** the frame's tint multiplies the child's colour, and its offset adds to it.
|
||||
- **Unused keys:** crop, size, region and shader are not used.
|
||||
|
||||
**Timing.** The child's time when the parent is at time `t`:
|
||||
1. **Clock start.** The child's clock starts at the first keyframe. It restarts at any keyframe with `restart`, or whose `child` differs from the previous keyframe's. Each start begins at that keyframe's `childStart`.
|
||||
2. **Child time.** Take the start keyframe that most recently began (call its start frame `S` and its `childStart` `C`). The child time is `C + (t − S)`.
|
||||
3. **Mode.** The keyframe playing at `t` decides the mode:
|
||||
- `loop` wraps the time over the child's `length`.
|
||||
- `once` stops at `length − 1`.
|
||||
- `hold` uses that keyframe's own `childStart`.
|
||||
4. **Random start.** A random start is `(layerIndex·73856093 xor keyframeIndex·19349663) mod length`, using unsigned 32-bit arithmetic.
|
||||
|
||||
**Child triggers.** A child fires its trigger on each frame it reaches. That is the frames where its whole-number time, or its animation, differs from the previous parent frame's, and always on parent frame 0. A held child fires once.
|
||||
|
||||
## XML saves
|
||||
A regular save writes the game's `.anm2` XML, keeping only what the game reads, followed by the editor's full copy as `<SourceDocument>` (the same data as the JSON, in XML):
|
||||
- **Animation layers** are flattened into plain layers, one per layer the child draws, named `layer/childLayer`. Their frames are baked one per frame and skew is dropped. A library's spritesheets are added with paths relative to the document.
|
||||
- **Children's trigger events** join the animation's triggers, matched by name.
|
||||
- **Triggers** keep one event each: the first.
|
||||
- **Dropped attributes:** markers, depth, skew, alpha offset, blur, shaders, extra events, trigger sounds and libraries.
|
||||
- **SVG spritesheets** are offered for conversion to PNGs before saving.
|
||||
|
||||
Older editor files saved without a game copy (the former extended format) still open, and are written as above when saved again.
|
||||
Reference in new issue
Block a user