Preset API

The Preset API allows exporting and importing configuration presets, including themes, attributes, custom menus, and macros.

Export Preset

Export current configuration as a shareable preset:

const api = game.modules.get("stylish-action-hud").api;

const preset = await api.exportPreset({
  includeTheme: true,           // Include theme setting
  includeGlobalAttributes: true, // Include global bar attributes
  includeCustomMenu: true,       // Include custom action menu
  includeActorPresets: true,     // Include actor-specific presets
});

// Preset structure
console.log(preset);
// {
//   meta: { name, description, systemId, systemTitle, moduleVersion, exportDate, foundryVersion },
//   data: { theme, globalAttributes, customMenu, actorPresets },
//   macros: { [macroId]: { uuid, name, img, type, command } }
// }

Import Preset

Apply a preset configuration:

const result = await api.importPreset(presetData, {
  merge: false,          // true = merge with existing, false = replace
  skipSystemCheck: false, // Skip system compatibility warning
});

// Result structure
console.log(result);
// {
//   success: true,
//   macrosCreated: ["Macro Name 1"],
//   macrosSkipped: ["Macro Name 2"],
//   warnings: [],
//   actorPresetsImported: 3
// }

Download Preset

Save preset as a JSON file:

const preset = await api.exportPreset();
preset.meta.name = "My Custom Setup";
preset.meta.description = "Description of this preset";

api.downloadPreset(preset, "my-custom-setup"); // Downloads as my_custom_setup.json

Import from File

Open file picker and import preset:

const result = await api.importPresetFromFile({
  merge: false,
  skipSystemCheck: false,
});

if (result.success) {
  ui.notifications.info("Preset imported successfully!");
} else {
  ui.notifications.error(result.error);
}