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

KeyWhat it is
nameThe project's name.
templateWhat it was started as. 'Blank' is an empty canvas.
canvas_w, canvas_hThe size of an empty canvas, in pixels.
pixelWhether it is pixel art: hard pixels, a pencil, a grid.
frames, frame_msHow many frames it has, and how long each shows.
layersThe layers, bottom to top.

A layer

KeyWhat it is
idWhat 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, opacityAs the layers list shows them.
x, yHow far its middle is from the image's middle. A painted layer: how far it is shifted.
pixels, celsA painted layer's picture as a PNG in base64; with frames, one per frame.
shape, w, h, color, radius, strokeA shape: 'Rectangle', 'Ellipse' or 'Line', its size, its color, its corners, its outline (0: filled).
source, size, rotationA picture: its address, its height as a part of the image's, its turn.
madeFor 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