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

API

For macro and module authors.

Macros

const sst = game.modules.get("dxcufgbs-scenario-soundtrack").api;
sst.playScenario("Combat");          // by id or name, e.g. a custom theme "Feywild"
sst.playScenario("tavern", { listId: "…" });  // a specific playlist bound to that scenario
sst.playList("Spooky ambience");     // one playlist, by id or name
sst.pause(); sst.resume(); sst.togglePause();
sst.skipTrack(); sst.nextList(); sst.stop();
sst.playSceneScenario(canvas.scene); // play the scenario bound to a scene, unless it is already playing
sst.getState();                      // what is playing: { scenarioId, listId, paused, … }
sst.getLibrary();                    // a copy of { folders, lists, scenarios, automation }
sst.openPanel();
sst.bindScene();                     // ask which scenario belongs to a scene (default: the current one)
sst.exportSetup();                   // download the whole setup as a file
await sst.importSetup(json, { mode: "merge", scenes: true });  // or mode: "replace"

Who may call what

Only the GM can change the music. Every client hears what the GM starts.

  • For players, the playback calls (playScenario, playList, pause, resume, togglePause, skipTrack, nextList, stop, playSceneScenario) are refused with the warning "Only the GM can control the soundtrack.".
  • openPanel shows the same warning, and bindScene does nothing.

Return values

  • The playback calls are async; all but playSceneScenario resolve to true when the music changed, or false when nothing happened (unknown name, no playlists bound, nothing playing, not the GM).
  • GM: importSetup takes the export as an object or JSON text, throws when it isn't a Scenario Soundtracks export, and resolves to the counts of what was added ({ folders, lists, scenarios, bindings, scenes }).
  • exportSetup also returns the exported data.

From another module

The API is set in the ready hook, so use it from ready on and check that it is there:

Hooks.once("ready", () => {
  const sst = game.modules.get("dxcufgbs-scenario-soundtrack")?.api;
  if (!sst) return;   // Scenario Soundtracks not installed or not enabled
  // …
});

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

Scene flag

A scene's soundtrack is the scene flag scenario (scene.getFlag("dxcufgbs-scenario-soundtrack", "scenario")):

  • a scenario id,
  • "" for No soundtrack,
  • or undefined when nobody has decided yet.

Hook

To react to the music changing, listen to dxcufgbs-scenario-soundtrack.changed.

  • It is called with Hooks.callAll(name, state, previous) on every client (GM and players) each time the GM changes what is playing: a new scenario or playlist, pause, resume, skip or stop.
  • state and previous are plain copies of the new and the old state, in the shape getState() returns ({ scenarioId, listId, paused, skip, … }; listId is null when the music stopped).
  • previous is the state this client saw before the change.
  • An error in your listener doesn't stop the music.
Hooks.on("dxcufgbs-scenario-soundtrack.changed", (state, previous) => {
  if (state.listId && !previous.listId) console.log("music started", state.scenarioId);
  if (!state.listId) console.log("music stopped");
});

Clone this wiki locally