Skip to content
dxcufgb edited this page Oct 30, 2026 · 1 revision

API

For macro and module authors. Areas are stored on the scene: flags["dxcufgbs-canvas-effects"].areas.

const api = game.modules.get("dxcufgbs-canvas-effects").api;
api.areas();                          // the areas of the viewed scene, bottom first (api.areas(scene) for another scene)
api.open(areaId);                     // GM: open the Canvas effect window for an area
await api.saveArea(area);             // GM: add an area or replace the one with the same id -> the saved area, or null
await api.deleteArea(areaId);         // GM: remove an area
api.effects;                          // effects and their styles, by id (a frozen copy)
api.presets();                        // this user's saved effects: [{id, name, cfg}]
await api.exportEffect(cfg, name);    // download cfg as one .canvas-effect.json file -> {file, data, missing}
await api.importEffect(file);         // read such a file, upload its images to this world -> {name, cfg, uploaded, skipped}
  • saveArea and deleteArea take the scene as an optional last argument (default: the viewed scene). They do nothing for a player, or for a GM who can't update the scene; open shows a warning and returns null for them. open returns the window.
  • saveArea cleans the area up before saving it (unknown effects and styles fall back, at most 8 layers), so it needs only an id and its shapes. A layer without a sound field gets its effect's standard sound, as when you paint a new area by hand, unless the Standard sounds for new effects setting is off. Set sound to choose one yourself; sound: null (or "") means no sound.
  • importEffect takes a File, the file's text or the parsed object, and also a bare {layers: [...]}. It throws on a file it can't read or one from a newer version of the module. Images are uploaded only when the user may upload files. It doesn't save anything: put cfg on an area as its effect.
  • exportEffect lists in missing the images it could not embed (they keep their address).
  • api.effects is a frozen copy: api.effects[id] = {label, icon, params, styles}, with params the sliders it uses and styles = {styleId: {label}}. Changing it changes nothing in the module.

Example

Paint rain over the whole scene, drawn above the tokens:

const api = game.modules.get("dxcufgbs-canvas-effects").api;
const r = canvas.dimensions.sceneRect;
await api.saveArea({
  id: foundry.utils.randomID(),
  name: "Rain",
  shapes: [{ type: "rect", x: r.x, y: r.y, width: r.width, height: r.height }],
  effect: { layers: [{ effect: "rain", style: "downpour", aboveTokens: true, sound: "rain-steady" }] }
});

From another module

The API is set during init, so it is ready from setup on. The module calls no hooks of its own; watch updateScene for changes to the flag. Make the integration optional:

Hooks.once("ready", () => {
  const mod = game.modules.get("dxcufgbs-canvas-effects");
  if (!mod?.active) return;   // Dxcufgb's canvas effects not installed or not enabled
  const areas = mod.api.areas();
});

Add { "id": "dxcufgbs-canvas-effects", "type": "module" } to relationships.recommends in your module.json.

Data

  • Areas are stored on the scene: flags["dxcufgbs-canvas-effects"].areas.
  • An area: {id, name, visible, exclude, ignoreExclusions, feather, elevation, sort, shapes, effect}. visible: players see it; exclude: an exclusion zone, which hides the effects of areas with a lower sort; ignoreExclusions: no exclusion zone hides this area; feather: the soft edge in grid squares (0 to 4); sort: the drawing order, higher on top.
  • A shape, in scene pixels: {type: "rect" | "ellipse", x, y, width, height}, {type: "polygon", points: [x0, y0, x1, y1, …]} or {type: "stroke", points, width} (a brush stroke or wall). Add erase: true to cut the shape out of the area.
  • An effect: {layers: [...]}, drawn bottom to top. A layer: {effect, style, scale, speed, alpha, density, direction, wind, pulse, rainbow, color, blend}, plus src and fit ("tile" or "stretch") for "image", light for the effects that can cast light, aboveTokens, and sound (a built-in sound id, "custom" with soundSrc, or ""), soundVolume (0 to 1) and soundRange (grid squares).
  • Saved effects are a flag on the User: flags["dxcufgbs-canvas-effects"].presets, read them with api.presets().
  • Exported files: <name>.canvas-effect.json, {format: "dxcufgbs-canvas-effects.effect", formatVersion: 1, name, exported, moduleVersion, effect, images}. images holds each image of your own as a data URL, keyed by the image field of its layer.

Clone this wiki locally