mirror of
https://github.com/migatu/vtt_work.git
synced 2026-07-14 21:38:39 +00:00
40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
// GK – Import Items From Module into Items Directory
|
||
(async () => {
|
||
const FILES = [
|
||
"fvtt-Item-archetype-grey-knight_v5.json",
|
||
"fvtt-Item-ability-aegis-of-titan_v5.json",
|
||
"fvtt-Item-nemesis-force-halberd_v4.json",
|
||
"fvtt-Item-gk-armour-integrated-storm-bolter_v2.json",
|
||
"fvtt-Item-aegis-power-armour_v2.json",
|
||
"fvtt-Item-terminator-aegis-gk_v4.json"
|
||
];
|
||
const MODULE_ID = "gk-greyknight";
|
||
const base = `modules/${MODULE_ID}/foundry`;
|
||
|
||
const ensureFolder = async (name, color="#4b6eaf") => {
|
||
let f = game.folders.find(x => x.type === "Item" && x.name === name);
|
||
if (!f) f = await Folder.create({name, type:"Item", color});
|
||
return f;
|
||
};
|
||
const worldFolder = await ensureFolder("Grey Knight Pack", "#4b6eaf");
|
||
|
||
const fetchJSON = async (path) => {
|
||
const res = await fetch(`/${path}`);
|
||
if (!res.ok) throw new Error(`Nie mogę pobrać: ${path} (HTTP ${res.status})`);
|
||
return await res.json();
|
||
};
|
||
|
||
let created = 0, updated = 0;
|
||
for (const fn of FILES) {
|
||
const full = `${base}/${fn}`;
|
||
try {
|
||
const data = await fetchJSON(full);
|
||
if (data._id) delete data._id;
|
||
data.folder = worldFolder.id;
|
||
const existing = game.items.getName(data.name);
|
||
if (existing) { await existing.update(data); updated++; }
|
||
else { await Item.create(data); created++; }
|
||
} catch (e) { console.error("Import err", full, e); ui.notifications.warn(`Błąd importu: ${fn}`); }
|
||
}
|
||
ui.notifications.info(`GK Module Import: utworzono ${created}, zaktualizowano ${updated}.`);
|
||
})(); |