For macro and module authors.
const api = game.modules.get("dxcufgbs-dice-trails").api;
api.open(); // the Dice trails window (selected token's, or yours)
api.open(actor); // the window on a character's trails
await api.preview("fire"); // roll dice with a damage type trail (default formula 2d6)
await api.previewAll(); // every damage type in turn
await api.preview({ layers: [{ design: "flame", style: "blue" }] }); // roll dice with a custom trail
await api.setTrail("attack", { layers: [ // your trail for attack rolls, bottom to top
{ design: "storm", style: "golden", glow: 0.5 },
{ design: "custom", src: "path/to/crest.png", motion: "orbit", count: 4, size: 0.8, colorMode: "colorize", color: "#ff8a2a" }
] });
await api.setTrail(["check", "save"], cfg); // several kinds at once
await api.clearTrail("attack");
await api.setTrail("attack", cfg, actor); await api.clearTrail("attack", actor); // a character's trails (an Actor you own)
api.trails(); // your trails by kind; api.trails(actor) a character's
api.defaultTrail(actor); // the trail a character gets from its class, species and background
await api.applyDefaultTrail(actor); // give it to the character now (as the GM does automatically)
api.designs; api.kinds; api.types; // designs and styles, kinds of roll, damage types
api.sounds; api.playSound("thunder", 1); // the sound themes; play one's bounce hit (strength 0-1)
api.presets(); // your saved trails: [{ id, name, cfg }]
const id = await api.savePreset("Golden storm", cfg); // save a trail under a name (same name: replaced); returns its id
await api.deletePreset(id); // delete a saved trail
await api.exportTrail(cfg, "My trail"); // download it as one file, images included
const { name, cfg } = await api.importTrail(file); // read such a file (a File or its text)
api.preview, api.previewAll and api.open need Dice So Nice to be active; the trail and saved-trail functions only change flags and work without it.
Trail format
Trails are { layers: [layer, ...] }, at most 20 layers, drawn bottom to top. A layer has:
| Field | Values |
|---|---|
design, style |
ids from api.designs, e.g. "flame" / "blue" |
scale |
0.4–2.5 (fine-tuning) |
length |
0.3–2.5 (fine-tuning) |
speed |
0–3 (fine-tuning) |
alpha |
0.1–1 (fine-tuning) |
density |
0–2.5 (fine-tuning) |
color |
"#rrggbb", or null for the style's |
glow, pulse, sparkle, wave |
0–1 (effects) |
sound |
a theme from api.sounds, "none", or null for the design's own |
A layer with design: "custom" is your own image: src, motion (trail, orbit, rise, burst, flutter, spin), count (1–40), size (0.05–4), blend ("add" or "normal") and colorMode ("original", "tint", "colorize").
Missing fields get their defaults and every value is clamped. An unknown design becomes a silver Comet, an unknown style the design's first.
Kinds and owners
- Kinds (
api.kinds):attack,check,save,death,initiative,other.setTrail/clearTrailignore other names and resolve tofalseif none is left, elsetrue. - Owners: a trail belongs to the current user (the default) or an Actor; for an unlinked token pass its own actor (
token.actor).setTrail/clearTrailupdate that document directly, so the caller needs permission to update it. - Saved trails (
presets,savePreset,deletePreset) are always the current user's.
Members
api.designsis{ id: { label, icon, sound, styles: { id: { label, colors } }, build } }. Readlabel,icon,soundandstyles; a design'sbuildis how the module draws it and not a stable contract, so don't call it.api.typesthe damage type ids (fire,cold, ...,healing,temphp).api.soundsthe 23 sound theme ids.api.trails(owner)returns{ kind: trail }for the kinds that have one, a character's unsaved default trail included.api.applyDefaultTrail(actor)resolves tofalsewhen there is nothing to save (or Default trails from class, species and background is off).api.exportTrail(cfg, name)resolves to{ file, data, missing }(missing: images that could not be packed).api.importTrail(source)takes aFile, the file's text or the parsed object (a bare{ layers }trail works too), uploads its images when the user may upload files, and resolves to{ name, cfg, uploaded, skipped }. It does not save the trail anywhere: passcfgtosetTrailorsavePreset. It throws on a file that is not a dice trail or is from a newer version of the module.api.ownerRefandapi.ownerFromRefare internal helpers (the module's own owner references on dice) and may change without notice; don't rely on them.
From another module
The API is set during init, so it is ready from setup on. Make the integration optional:
Hooks.once("ready", async () => {
const api = game.modules.get("dxcufgbs-dice-trails")?.active ? game.modules.get("dxcufgbs-dice-trails").api : null;
if (!api) return; // Dxcufgb's dice trails not installed or not enabled
await api.setTrail("initiative", { layers: [{ design: "comet", style: "gold" }] });
});
Add { "id": "dxcufgbs-dice-trails", "type": "module" } to relationships.recommends in your module.json. The module calls no hooks of its own.
Stored data
flags.dxcufgbs-dice-trails.trailson Users and Actors:{ kind: trail }.flags.dxcufgbs-dice-trails.presetson Users:[{ id, name, cfg }].flags.dxcufgbs-dice-trails.defaultTrailon Actors: the default trail last saved on it.
Read them through api.trails() / api.presets() and write through the API, not directly.
Exported files
Exported files: <name>.dice-trail.json, { "format": "dxcufgbs-dice-trails.trail", "formatVersion": 1, name, exported, moduleVersion, trail, images }. A custom layer's image key points into images, where each image is { name, type, size, data } with the bytes as a data URL.
This page mirrors the Dice Trails wiki on GitHub.