Documents and layers
A project is one plain object, the document, with a list of layers.
Both are open: a plugin may keep values of its own on either, and they are saved with the project.
The document
| Key | What it is |
|---|---|
name | The project's name. |
template | What it was started as. 'Blank' is an empty canvas. |
canvas_w, canvas_h | The size of an empty canvas, in pixels. |
pixel | Whether it is pixel art: hard pixels, a pencil, a grid. |
frames, frame_ms | How many frames it has, and how long each shows. |
layers | The layers, bottom to top. |
A layer
| Key | What it is |
|---|---|
id | What the project knows it as. Given by the program when a layer is added. |
kind | 'paint' (painted on), 'shape', 'text', 'image' (a picture) or 'group'. |
name, visible, locked, opacity | As the layers list shows them. |
x, y | How far its middle is from the image's middle. A painted layer: how far it is shifted. |
pixels, cels | A painted layer's picture as a PNG in base64; with frames, one per frame. |
shape, w, h, color, radius, stroke | A shape: 'Rectangle', 'Ellipse' or 'Line', its size, its color, its corners, its outline (0: filled). |
source, size, rotation | A picture: its address, its height as a part of the image's, its turn. |
made | For a plugin's element: { by: 'plugin:key', ...settings }. |
Adding layers
commands: [{
label: 'Three dots',
run(api) {
const dots = [-120, 0, 120].map((x) => ({ kind: 'shape', name: 'Dot', shape: 'Ellipse', w: 64, h: 64, color: api.project.color, radius: 0, stroke: 0, x, y: 0 }));
api.project.addAll(dots, {}, 'Dots'); // all at once, in a group: one step to undo
},
}],
@plugin.command('Three dots')
def three_dots(app):
dots = [dict(kind='shape', name='Dot', shape='Ellipse', w=64, h=64, color=app.color, radius=0, stroke=0, x=x, y=0) for x in (-120, 0, 120)]
app.add_all(dots, group='Dots') # all at once, in a group: one step to undo