Add one-click companion import action in UI
This commit is contained in:
@@ -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");
|
||||
|
||||
+2
-2
@@ -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"
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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: `
|
||||
<p>Import all SLA companion content into this world?</p>
|
||||
<p><strong>Merge</strong> keeps existing world items and only adds missing content.</p>
|
||||
<p><strong>Overwrite</strong> updates existing SLA content from companion seeds.</p>
|
||||
`,
|
||||
buttons: {
|
||||
merge: {
|
||||
label: "Merge",
|
||||
icon: '<i class="fas fa-plus-square"></i>',
|
||||
callback: () => finish(false)
|
||||
},
|
||||
overwrite: {
|
||||
label: "Overwrite",
|
||||
icon: '<i class="fas fa-sync"></i>',
|
||||
callback: () => finish(true)
|
||||
},
|
||||
cancel: {
|
||||
label: "Cancel",
|
||||
icon: '<i class="fas fa-times"></i>',
|
||||
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 = '<i class="fas fa-download"></i>';
|
||||
button.addEventListener("click", () => {
|
||||
importAllSLACompanionContent();
|
||||
});
|
||||
container.appendChild(button);
|
||||
}
|
||||
|
||||
Hooks.on("renderCompendiumDirectory", addCompendiumHeaderButton);
|
||||
|
||||
Hooks.on("getCompendiumDirectoryEntryContext", (html, options) => {
|
||||
options.push({
|
||||
name: "Import SLA Companion Content",
|
||||
icon: '<i class="fas fa-download"></i>',
|
||||
condition: (li) => {
|
||||
if (!canUseCompanionImport()) return false;
|
||||
const pack = game.packs?.get(li?.data("pack"));
|
||||
return pack?.metadata?.packageName === MODULE_ID;
|
||||
},
|
||||
callback: () => {
|
||||
importAllSLACompanionContent();
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user