mirror of
https://github.com/migatu/vtt_work.git
synced 2026-07-14 21:38:39 +00:00
Import wrath-and-glory-gk-0.2.0.zip do wg-greyknights (2025-08-21T20:12:55Z)
This commit is contained in:
@@ -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.");
|
||||
})();
|
||||
Reference in New Issue
Block a user