Repository navigation
API
dxcufgb edited this page Oct 30, 2026
·
1 revision
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}-
saveAreaanddeleteAreatake 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;openshows a warning and returnsnullfor them.openreturns the window. -
saveAreacleans the area up before saving it (unknown effects and styles fall back, at most 8 layers), so it needs only anidand itsshapes. A layer without asoundfield 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. Setsoundto choose one yourself;sound: null(or"") means no sound. -
importEffecttakes aFile, 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: putcfgon an area as itseffect. -
exportEffectlists inmissingthe images it could not embed (they keep their address). -
api.effectsis a frozen copy:api.effects[id]={label, icon, params, styles}, withparamsthe sliders it uses andstyles={styleId: {label}}. Changing it changes nothing in the module.
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" }] }
});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.
- 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 lowersort;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). Adderase: trueto 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}, plussrcandfit("tile"or"stretch") for"image",lightfor the effects that can cast light,aboveTokens, andsound(a built-in sound id,"custom"withsoundSrc, or""),soundVolume(0 to 1) andsoundRange(grid squares). - Saved effects are a flag on the User:
flags["dxcufgbs-canvas-effects"].presets, read them withapi.presets(). - Exported files:
<name>.canvas-effect.json,{format: "dxcufgbs-canvas-effects.effect", formatVersion: 1, name, exported, moduleVersion, effect, images}.imagesholds each image of your own as a data URL, keyed by theimagefield of its layer.
Dxcufgb's Workshop: every Foundry VTT project, video and changelog in one place · Support on Ko-fi · MIT License
Using it
- Installation
- Effects
- Painting
- Exclusion Zones
- The Canvas Effect Window
- Sounds
- Saved Effects
- Settings
For module authors
Help