diff --git a/README.md b/README.md index 2932e04..e8dbde9 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,17 @@ If the system is not installed first, Foundry marks the world unavailable. ## Populate A Fresh World -In a new `sla-industries-brp` world with the companion module enabled, run this as a GM script macro: +In a new `sla-industries-brp` world with the companion module enabled: + +1. Open the **Compendium** tab. +2. Use either: + - the new download button in the Compendium header, or + - right-click any `sla-industries-compendium` pack and choose **Import SLA Companion Content**. +3. Choose **Merge** or **Overwrite** when prompted. + +No script macro is required. + +Optional fallback (GM script macro): ```js const { SLASeedImporter } = await import("/systems/sla-industries-brp/module/apps/sla-seed-importer.mjs"); diff --git a/sla-brp/world.json b/sla-brp/world.json index 00ad89e..3d1c3ce 100644 --- a/sla-brp/world.json +++ b/sla-brp/world.json @@ -2,7 +2,7 @@ "id": "sla-brp", "title": "SLA BRP", "description": "A prebuilt SLA BRP world for Foundry Virtual Tabletop.", - "version": "0.1.2", + "version": "0.1.3", "authors": [ { "name": "timevans" @@ -15,7 +15,7 @@ "maximum": "13" }, "system": "sla-industries-brp", - "systemVersion": "13.1.53", + "systemVersion": "13.1.54", "manifest": "https://raw.githubusercontent.com/slaguru666/sla_industries_brp/main/sla-brp/world.json", "download": "https://github.com/slaguru666/sla_industries_brp/releases/latest/download/sla-brp.zip", "url": "https://github.com/slaguru666/sla_industries_brp" diff --git a/sla-industries-brp/system.json b/sla-industries-brp/system.json index 0678c5e..9bc237a 100644 --- a/sla-industries-brp/system.json +++ b/sla-industries-brp/system.json @@ -2,7 +2,7 @@ "id": "sla-industries-brp", "title": "SLA Industries BRP (Draft)", "description": "Draft SLA Industries conversion of the BRP system for FoundryVTT.", - "version": "13.1.53", + "version": "13.1.54", "coreVersion": "13.351", "compatibility": { "minimum": "13", diff --git a/sla-industries-compendium/README.md b/sla-industries-compendium/README.md index d334f28..8e3f124 100644 --- a/sla-industries-compendium/README.md +++ b/sla-industries-compendium/README.md @@ -15,7 +15,16 @@ Companion module for `sla-industries-brp` with: ## Import Content Into A New World -After installing the system and module, run this in a GM script macro: +After installing the system and module: + +1. Open the **Compendium** tab. +2. Click the new import button in the Compendium header, or right-click any `sla-industries-compendium` pack. +3. Choose **Import SLA Companion Content**. +4. Pick **Merge** or **Overwrite**. + +No script macro is required. + +Optional fallback (GM macro): ```js const { SLASeedImporter } = await import("/systems/sla-industries-brp/module/apps/sla-seed-importer.mjs"); diff --git a/sla-industries-compendium/module.json b/sla-industries-compendium/module.json index c5d8f9b..b957bc2 100644 --- a/sla-industries-compendium/module.json +++ b/sla-industries-compendium/module.json @@ -1,7 +1,7 @@ { "id": "sla-industries-compendium", "title": "SLA Industries Compendium (Draft)", - "version": "1.1.0", + "version": "1.2.0", "coreVersion": "13.351", "compatibility": { "minimum": "13", @@ -18,6 +18,9 @@ "flags": {} } ], + "esmodules": [ + "scripts/companion-ui.mjs" + ], "packs": [ { "name": "allegiances", diff --git a/sla-industries-compendium/scripts/companion-ui.mjs b/sla-industries-compendium/scripts/companion-ui.mjs new file mode 100644 index 0000000..4c25e89 --- /dev/null +++ b/sla-industries-compendium/scripts/companion-ui.mjs @@ -0,0 +1,111 @@ +const MODULE_ID = "sla-industries-compendium"; +const SYSTEM_ID = "sla-industries-brp"; +const BUTTON_CLASS = "sla-companion-import-all"; + +function canUseCompanionImport() { + return Boolean(game.user?.isGM && game.system?.id === SYSTEM_ID && game.brp?.SLASeedImporter?.buildDraft2); +} + +function chooseImportMode() { + return new Promise((resolve) => { + let settled = false; + const finish = (value) => { + if (settled) return; + settled = true; + resolve(value); + }; + + new Dialog({ + title: "SLA Companion Import", + content: ` +

Import all SLA companion content into this world?

+

Merge keeps existing world items and only adds missing content.

+

Overwrite updates existing SLA content from companion seeds.

+ `, + buttons: { + merge: { + label: "Merge", + icon: '', + callback: () => finish(false) + }, + overwrite: { + label: "Overwrite", + icon: '', + callback: () => finish(true) + }, + cancel: { + label: "Cancel", + icon: '', + callback: () => finish(null) + } + }, + default: "merge", + close: () => finish(null) + }).render(true); + }); +} + +async function importAllSLACompanionContent() { + if (!canUseCompanionImport()) { + ui.notifications.warn("SLA companion import requires GM role and active sla-industries-brp system."); + return; + } + + const overwrite = await chooseImportMode(); + if (overwrite === null) return; + + ui.notifications.info("SLA companion import started."); + try { + const summary = await game.brp.SLASeedImporter.buildDraft2({ + overwrite, + syncCompendia: true + }); + console.log(`${MODULE_ID} | Companion import summary`, summary); + ui.notifications.info("SLA companion import completed."); + } catch (err) { + console.error(`${MODULE_ID} | Companion import failed`, err); + ui.notifications.error(`SLA companion import failed: ${err?.message ?? "Unknown error"}`); + } +} + +function addCompendiumHeaderButton(app, html) { + if (!canUseCompanionImport()) return; + const root = html?.[0]; + if (!root) return; + + const existing = root.querySelector(`.${BUTTON_CLASS}`); + if (existing) return; + + const container = + root.querySelector(".header-actions") || + root.querySelector(".directory-header .header-search") || + root.querySelector(".directory-header"); + if (!container) return; + + const button = document.createElement("button"); + button.type = "button"; + button.className = `icon ${BUTTON_CLASS}`; + button.title = "Import SLA Companion Content"; + button.innerHTML = ''; + button.addEventListener("click", () => { + importAllSLACompanionContent(); + }); + container.appendChild(button); +} + +Hooks.on("renderCompendiumDirectory", addCompendiumHeaderButton); + +Hooks.on("getCompendiumDirectoryEntryContext", (html, options) => { + options.push({ + name: "Import SLA Companion Content", + icon: '', + condition: (li) => { + if (!canUseCompanionImport()) return false; + const pack = game.packs?.get(li?.data("pack")); + return pack?.metadata?.packageName === MODULE_ID; + }, + callback: () => { + importAllSLACompanionContent(); + } + }); +});