diff --git a/build-packs.mjs b/build-packs.mjs new file mode 100644 index 0000000..092ec19 --- /dev/null +++ b/build-packs.mjs @@ -0,0 +1,108 @@ +/** + * build-packs.mjs + * Converts JSON source files in /packs/ into Foundry v14 LevelDB compendium packs. + * + * Usage: node build-packs.mjs + * + * To add new items: edit the relevant JSON file in /packs/, then re-run this script + * and push to GitHub. Foundry will pick up the new items on next install/update. + */ + +import { ClassicLevel } from 'classic-level'; +import { readFileSync, rmSync, existsSync } from 'fs'; +import { join, dirname } from 'path'; +import { fileURLToPath } from 'url'; +import { randomBytes } from 'crypto'; + +const __dir = dirname(fileURLToPath(import.meta.url)); + +/** Generate a Foundry-style 16-char alphanumeric ID */ +function makeId() { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + let id = ''; + const bytes = randomBytes(16); + for (const b of bytes) id += chars[b % chars.length]; + return id; +} + +/** + * Write an array of item objects into a Foundry LevelDB pack directory. + * @param {string} packDir - absolute path to the pack folder (will be wiped & recreated) + * @param {object[]} items - array of Foundry item documents (name, type, img, system) + */ +async function buildPack(packDir, items) { + // Wipe existing pack so we get a clean rebuild + if (existsSync(packDir)) { + rmSync(packDir, { recursive: true, force: true }); + } + + const db = new ClassicLevel(packDir, { keyEncoding: 'utf8', valueEncoding: 'utf8' }); + + for (const item of items) { + const id = makeId(); + const doc = { + _id: id, + name: item.name, + type: item.type, + img: item.img ?? 'icons/svg/item-bag.svg', + system: item.system ?? {}, + effects: [], + flags: {}, + folder: null, + sort: 0, + ownership: { default: 0 }, + _stats: { + systemId: 'zero-engine', + systemVersion: '1.3.0-dev', + coreVersion: '14.359', + createdTime: Date.now(), + modifiedTime: Date.now(), + lastModifiedBy: 'builder' + } + }; + await db.put(`!items!${id}`, JSON.stringify(doc)); + } + + await db.close(); + console.log(` ✓ ${items.length} items → ${packDir.replace(__dir, '.')}`); +} + +// ── Pack definitions ───────────────────────────────────────────────────────── +// Each entry: { id, label, source JSON file } +// To add a new pack: add an entry here and create the matching JSON source file. + +const PACKS = [ + { + id: 'sla-armors', + label: 'SLA Armors', + source: 'packs/armors.json', + }, + { + id: 'sla-drugs', + label: 'SLA Drugs & Consumables', + source: 'packs/drugs.json', + }, + { + id: 'sla-ebb-formulae', + label: 'SLA Ebb Formulae', + source: 'packs/ebb-formulae.json', + }, + { + id: 'sla-specialties', + label: 'SLA Specialties', + source: 'packs/specialties.json', + }, +]; + +// ── Run ────────────────────────────────────────────────────────────────────── +console.log('Building SLA Zero Engine compendium packs…\n'); + +for (const pack of PACKS) { + const sourcePath = join(__dir, pack.source); + const destDir = join(__dir, 'packs', pack.id); + const items = JSON.parse(readFileSync(sourcePath, 'utf8')); + console.log(`Building: ${pack.label} (${items.length} items)`); + await buildPack(destDir, items); +} + +console.log('\nDone. Re-run this script any time you update a source JSON file.'); diff --git a/packs/sla-armors/000003.log b/packs/sla-armors/000003.log new file mode 100644 index 0000000..6eaec18 Binary files /dev/null and b/packs/sla-armors/000003.log differ diff --git a/packs/sla-armors/CURRENT b/packs/sla-armors/CURRENT new file mode 100644 index 0000000..1a84852 --- /dev/null +++ b/packs/sla-armors/CURRENT @@ -0,0 +1 @@ +MANIFEST-000002 diff --git a/packs/sla-armors/LOCK b/packs/sla-armors/LOCK new file mode 100644 index 0000000..e69de29 diff --git a/packs/sla-armors/LOG b/packs/sla-armors/LOG new file mode 100644 index 0000000..33aefa0 --- /dev/null +++ b/packs/sla-armors/LOG @@ -0,0 +1 @@ +2026/06/02-14:23:08.429103 faef85fbefa0 Delete type=3 #1 diff --git a/packs/sla-armors/MANIFEST-000001 b/packs/sla-armors/MANIFEST-000001 new file mode 100644 index 0000000..18e5cab Binary files /dev/null and b/packs/sla-armors/MANIFEST-000001 differ diff --git a/packs/sla-armors/MANIFEST-000002 b/packs/sla-armors/MANIFEST-000002 new file mode 100644 index 0000000..bbbc585 Binary files /dev/null and b/packs/sla-armors/MANIFEST-000002 differ diff --git a/packs/sla-drugs/000003.log b/packs/sla-drugs/000003.log new file mode 100644 index 0000000..e8db882 Binary files /dev/null and b/packs/sla-drugs/000003.log differ diff --git a/packs/sla-drugs/CURRENT b/packs/sla-drugs/CURRENT new file mode 100644 index 0000000..1a84852 --- /dev/null +++ b/packs/sla-drugs/CURRENT @@ -0,0 +1 @@ +MANIFEST-000002 diff --git a/packs/sla-drugs/LOCK b/packs/sla-drugs/LOCK new file mode 100644 index 0000000..e69de29 diff --git a/packs/sla-drugs/LOG b/packs/sla-drugs/LOG new file mode 100644 index 0000000..3defcd3 --- /dev/null +++ b/packs/sla-drugs/LOG @@ -0,0 +1 @@ +2026/06/02-14:23:08.439934 faef77ffefa0 Delete type=3 #1 diff --git a/packs/sla-drugs/MANIFEST-000001 b/packs/sla-drugs/MANIFEST-000001 new file mode 100644 index 0000000..18e5cab Binary files /dev/null and b/packs/sla-drugs/MANIFEST-000001 differ diff --git a/packs/sla-drugs/MANIFEST-000002 b/packs/sla-drugs/MANIFEST-000002 new file mode 100644 index 0000000..bbbc585 Binary files /dev/null and b/packs/sla-drugs/MANIFEST-000002 differ diff --git a/packs/sla-ebb-formulae/000003.log b/packs/sla-ebb-formulae/000003.log new file mode 100644 index 0000000..a317cf7 Binary files /dev/null and b/packs/sla-ebb-formulae/000003.log differ diff --git a/packs/sla-ebb-formulae/CURRENT b/packs/sla-ebb-formulae/CURRENT new file mode 100644 index 0000000..1a84852 --- /dev/null +++ b/packs/sla-ebb-formulae/CURRENT @@ -0,0 +1 @@ +MANIFEST-000002 diff --git a/packs/sla-ebb-formulae/LOCK b/packs/sla-ebb-formulae/LOCK new file mode 100644 index 0000000..e69de29 diff --git a/packs/sla-ebb-formulae/LOG b/packs/sla-ebb-formulae/LOG new file mode 100644 index 0000000..51935fc --- /dev/null +++ b/packs/sla-ebb-formulae/LOG @@ -0,0 +1 @@ +2026/06/02-14:23:08.447905 faef857aefa0 Delete type=3 #1 diff --git a/packs/sla-ebb-formulae/MANIFEST-000001 b/packs/sla-ebb-formulae/MANIFEST-000001 new file mode 100644 index 0000000..18e5cab Binary files /dev/null and b/packs/sla-ebb-formulae/MANIFEST-000001 differ diff --git a/packs/sla-ebb-formulae/MANIFEST-000002 b/packs/sla-ebb-formulae/MANIFEST-000002 new file mode 100644 index 0000000..bbbc585 Binary files /dev/null and b/packs/sla-ebb-formulae/MANIFEST-000002 differ diff --git a/packs/sla-specialties/000003.log b/packs/sla-specialties/000003.log new file mode 100644 index 0000000..663442b Binary files /dev/null and b/packs/sla-specialties/000003.log differ diff --git a/packs/sla-specialties/CURRENT b/packs/sla-specialties/CURRENT new file mode 100644 index 0000000..1a84852 --- /dev/null +++ b/packs/sla-specialties/CURRENT @@ -0,0 +1 @@ +MANIFEST-000002 diff --git a/packs/sla-specialties/LOCK b/packs/sla-specialties/LOCK new file mode 100644 index 0000000..e69de29 diff --git a/packs/sla-specialties/LOG b/packs/sla-specialties/LOG new file mode 100644 index 0000000..8f7875e --- /dev/null +++ b/packs/sla-specialties/LOG @@ -0,0 +1 @@ +2026/06/02-14:23:08.461753 faef85fbefa0 Delete type=3 #1 diff --git a/packs/sla-specialties/MANIFEST-000001 b/packs/sla-specialties/MANIFEST-000001 new file mode 100644 index 0000000..18e5cab Binary files /dev/null and b/packs/sla-specialties/MANIFEST-000001 differ diff --git a/packs/sla-specialties/MANIFEST-000002 b/packs/sla-specialties/MANIFEST-000002 new file mode 100644 index 0000000..bbbc585 Binary files /dev/null and b/packs/sla-specialties/MANIFEST-000002 differ diff --git a/system.json b/system.json index f382cfc..d642db1 100644 --- a/system.json +++ b/system.json @@ -30,6 +30,36 @@ }, "primaryTokenAttribute": "health", "secondaryTokenAttribute": null, + "packs": [ + { + "name": "sla-armors", + "label": "SLA Armors", + "path": "packs/sla-armors", + "type": "Item", + "system": "zero-engine" + }, + { + "name": "sla-drugs", + "label": "SLA Drugs & Consumables", + "path": "packs/sla-drugs", + "type": "Item", + "system": "zero-engine" + }, + { + "name": "sla-ebb-formulae", + "label": "SLA Ebb Formulae", + "path": "packs/sla-ebb-formulae", + "type": "Item", + "system": "zero-engine" + }, + { + "name": "sla-specialties", + "label": "SLA Specialties", + "path": "packs/sla-specialties", + "type": "Item", + "system": "zero-engine" + } + ], "manifest": "https://raw.githubusercontent.com/slaguru666/zero-engine/main/system.json", "download": "https://github.com/slaguru666/zero-engine/archive/refs/heads/main.zip", "url": "https://github.com/slaguru666/zero-engine"