From 8f206baf46e580d908949099d2519b77e2856054 Mon Sep 17 00:00:00 2001 From: Eldritch-Oliver Date: Thu, 9 Oct 2025 02:03:18 -0600 Subject: [PATCH] Add initial pack definitions --- .gitignore | 7 ++++ package.json | 2 + scripts/buildCompendia.mjs | 36 ++++++++++++++++++ scripts/extractCompendia.mjs | 31 ++++++++++++++++ system.json | 71 +++++++++++++++++++++++++++++++++++- 5 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 scripts/buildCompendia.mjs create mode 100644 scripts/extractCompendia.mjs diff --git a/.gitignore b/.gitignore index 6ef05ba..e058206 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,10 @@ jspm_packages/ .env.test.local .env.production.local .env.local + +# Ignore all of the binaries and stuff that gets built for Foundry from the raw +# JSON data because it's annoying seeing it in my git changes when it isn't actually +# needed. +/packs/**/* +!/packs/**/*/ +!/packs/**/*.json diff --git a/package.json b/package.json index 1c663e7..5fa77f1 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,8 @@ "eslint": "^9.16.0" }, "scripts": { + "data:build": "node scripts/buildCompendia.mjs", + "data:extract": "node scripts/extractCompendia.mjs", "link": "node scripts/linkFoundry.mjs", "lint": "eslint --fix", "lint:nofix": "eslint" diff --git a/scripts/buildCompendia.mjs b/scripts/buildCompendia.mjs new file mode 100644 index 0000000..88ab4e4 --- /dev/null +++ b/scripts/buildCompendia.mjs @@ -0,0 +1,36 @@ +import { existsSync } from "fs"; +import { readFile } from "fs/promises"; +import { join } from "path"; +import { compilePack } from "@foundryvtt/foundryvtt-cli"; +import { pathToFileURL } from "url"; + +export async function buildCompendia() { + const manifest = JSON.parse(await readFile(`./system.json`, `utf-8`)); + + if (!manifest.packs || manifest.packs.length === 0) { + console.log(`No compendium packs defined`); + process.exit(0); + }; + console.log(`Packing compendia`); + + for (const compendium of manifest.packs) { + console.debug(`Packing ${compendium.label} (${compendium.name})`); + let src = join(process.cwd(), compendium.path, `_source`); + if (!existsSync(src)) { + console.warn(`${compendium.path} doesn't exist, skipping.`) + continue; + }; + await compilePack( + src, + join(process.cwd(), compendium.path), + { recursive: true }, + ); + console.debug(`Finished packing compendium: ${compendium.name}`); + }; + + console.log(`Finished packing all compendia`) +}; + +if (import.meta.url === pathToFileURL(process.argv[1]).href) { + buildCompendia(); +}; diff --git a/scripts/extractCompendia.mjs b/scripts/extractCompendia.mjs new file mode 100644 index 0000000..0730b38 --- /dev/null +++ b/scripts/extractCompendia.mjs @@ -0,0 +1,31 @@ +import { readFile } from "fs/promises"; +import { join } from "path"; +import { extractPack } from "@foundryvtt/foundryvtt-cli"; +import { pathToFileURL } from "url"; + +export async function extractCompendia() { + const manifest = JSON.parse(await readFile(`./system.json`, `utf-8`)); + + if (!manifest.packs || manifest.packs.length === 0) { + console.log(`No compendium packs defined`); + process.exit(0); + }; + console.log(`Extracting compendia`); + + for (const compendium of manifest.packs) { + console.debug(`Unpacking ${compendium.label} (${compendium.name})`); + let src = join(process.cwd(), compendium.path, `_source`); + await extractPack( + join(process.cwd(), compendium.path), + src, + { recursive: true }, + ); + console.debug(`Finished unpacking compendium: ${compendium.name}`); + }; + + console.log(`Finished unpacking all compendia`); +}; + +if (import.meta.url === pathToFileURL(process.argv[1]).href) { + extractCompendia(); +}; diff --git a/system.json b/system.json index 5190f37..d4b61ed 100644 --- a/system.json +++ b/system.json @@ -53,5 +53,74 @@ "skill": {}, "weapon": {} } - } + }, + "packs": [ + { + "name": "protection", + "label": "Armour & Shields", + "system": "ripcrypt", + "path": "packs/protection", + "type": "Item", + "ownership": { + "PLAYER": "OBSERVER", + "ASSISTANT": "OWNER" + } + }, + { + "name": "weapons", + "label": "Weapons & Ammo", + "system": "ripcrypt", + "path": "packs/weapons", + "type": "Item", + "ownership": { + "PLAYER": "OBSERVER", + "ASSISTANT": "OWNER" + } + }, + { + "name": "skills", + "label": "Skills", + "system": "ripcrypt", + "path": "packs/skills", + "type": "Item", + "ownership": { + "PLAYER": "OBSERVER", + "ASSISTANT": "OWNER" + } + }, + { + "name": "geist", + "label": "Geist", + "system": "ripcrypt", + "path": "packs/geist", + "type": "Actor", + "ownership": { + "PLAYER": "NONE", + "ASSISTANT": "OWNER" + } + } + ], + "packFolders": [ + { + "name": "RipCrypt Sprint Start", + "color": "#04262a", + "sorting": "m", + "folders": [ + { + "name": "Character Options", + "color": "#06393f", + "sorting": "m", + "folders": [], + "packs": [ + "protection", + "weapons", + "skills" + ] + } + ], + "packs": [ + "geist" + ] + } + ] }