Import wrath-and-glory-gk-0.2.0.zip do wg-greyknights (2025-08-21T20:12:55Z)

This commit is contained in:
2025-08-21 20:12:55 +00:00
parent 24ad39dc6f
commit b4ee703fdc
14 changed files with 208 additions and 43 deletions
@@ -0,0 +1,29 @@
// GK Importer: drop a folder path that contains JSON items exported from Foundry and import them.
(async () => {
const dir = await new Promise(resolve => {
new Dialog({
title: "GK Importer — pick folder URL or paste path",
content: `<p>Paste a data path (e.g. /worlds/your-world/foundry/items)</p><input type="text" name="path" style="width:100%"/>`,
buttons: {
ok: { label: "Import", callback: html => resolve(html.find('input[name="path"]').val()) },
cancel: { label: "Cancel", callback: () => resolve(null) }
},
default: "ok"
}).render(true);
});
if (!dir) return;
const response = await FilePicker.browse("data", dir);
const files = response.files.filter(f => f.endsWith(".json"));
for (const f of files) {
try {
const json = await (await fetch(f)).json();
if (json.type && (json.name || json.label)) {
if (!json.name && json.label) json.name = json.label;
await Item.create(json);
}
} catch (err) {
ui.notifications.error(`Import failed for ${f}: ${err.message}`);
}
}
ui.notifications.info("GK Import complete.");
})();