Message de bienvenue

This commit is contained in:
2026-05-06 20:26:31 +02:00
parent ee6fecbcef
commit 454f8de412
73 changed files with 323 additions and 184 deletions
+115 -26
View File
@@ -4,7 +4,7 @@ import crypto from "node:crypto"
import { Level } from "level"
export const PACK_DEFINITIONS = [
export const CONTENT_PACK_DEFINITIONS = [
{ sourceFile: "armes.json", outputFolder: "armes", type: "Item" },
{ sourceFile: "armures.json", outputFolder: "armures", type: "Item" },
{ sourceFile: "equipements.json", outputFolder: "equipements", type: "Item" },
@@ -16,6 +16,11 @@ export const PACK_DEFINITIONS = [
{ sourceFile: "sortileges.json", outputFolder: "sortileges", type: "Item" },
]
export const SYSTEM_PACK_DEFINITIONS = [
...CONTENT_PACK_DEFINITIONS,
{ sourceFile: "aide-systeme.json", outputFolder: "aide-systeme", type: "JournalEntry" },
]
function slugId(input) {
const hash = crypto.createHash("sha256").update(input).digest()
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
@@ -26,41 +31,122 @@ function slugId(input) {
return id
}
function toPackDocument(entry, index, {
function createDocumentStats({
documentSystemId,
documentSystemVersion,
coreVersion,
createdTime,
lastModifiedBy = "Copilot",
} = {}) {
return {
systemId: documentSystemId,
systemVersion: documentSystemVersion,
coreVersion,
createdTime,
modifiedTime: createdTime,
lastModifiedBy,
compendiumSource: null,
duplicateSource: null,
exportSource: null,
}
}
function toItemPackDocument(entry, index, options = {}) {
const docId = slugId(`${entry.type}:${entry.name}`)
return {
name: entry.name,
type: entry.type,
img: entry.img ?? "icons/svg/item-bag.svg",
system: entry.system ?? {},
effects: Array.isArray(entry.effects) ? entry.effects : [],
flags: entry.flags ?? {},
_stats: {
systemId: documentSystemId,
systemVersion: documentSystemVersion,
coreVersion,
createdTime,
modifiedTime: createdTime,
lastModifiedBy,
compendiumSource: null,
duplicateSource: null,
exportSource: null,
},
_id: docId,
folder: null,
sort: index * 1000,
ownership: {
default: 0,
key: `!items!${docId}`,
value: {
name: entry.name,
type: entry.type,
img: entry.img ?? "icons/svg/item-bag.svg",
system: entry.system ?? {},
effects: Array.isArray(entry.effects) ? entry.effects : [],
flags: entry.flags ?? {},
_stats: createDocumentStats(options),
_id: docId,
folder: null,
sort: index * 1000,
ownership: {
default: 0,
},
},
embedded: [],
}
}
function toJournalPageDocument(entry, journalId, page, pageIndex, options = {}) {
const pageId = slugId(`JournalEntryPage:${entry.name}:${page.name ?? page.title ?? pageIndex}`)
return {
_id: pageId,
name: page.name ?? `Page ${pageIndex + 1}`,
type: page.type ?? "text",
title: {
show: page.title?.show ?? true,
level: page.title?.level ?? 1,
},
text: {
format: page.text?.format ?? 1,
content: page.text?.content ?? "",
},
system: page.system ?? {},
image: page.image ?? {},
video: page.video ?? { controls: true, volume: 0.5 },
src: page.src ?? null,
category: page.category ?? null,
sort: page.sort ?? pageIndex * 1000,
ownership: page.ownership ?? { default: -1 },
flags: page.flags ?? {},
_stats: createDocumentStats(options),
_key: `!journal.pages!${journalId}.${pageId}`,
}
}
function toJournalPackDocument(entry, index, options = {}) {
const docId = slugId(`JournalEntry:${entry.name}`)
const pages = Array.isArray(entry.pages)
? entry.pages.map((page, pageIndex) => toJournalPageDocument(entry, docId, page, pageIndex, options))
: []
return {
key: `!journal!${docId}`,
value: {
name: entry.name,
pages: pages.map((page) => page._id),
ownership: entry.ownership ?? { default: 0 },
flags: entry.flags ?? { core: {} },
_stats: createDocumentStats(options),
folder: null,
sort: entry.sort ?? index * 1000,
_id: docId,
categories: Array.isArray(entry.categories) ? entry.categories : [],
},
embedded: pages.map((page) => ({
key: page._key,
value: {
name: page.name,
type: page.type,
title: page.title,
text: page.text,
system: page.system,
image: page.image,
video: page.video,
src: page.src,
category: page.category,
sort: page.sort,
ownership: page.ownership,
flags: page.flags,
_stats: page._stats,
_id: page._id,
},
})),
}
}
function toPackDocument(entry, index, options = {}) {
if (entry.type === "JournalEntry") return toJournalPackDocument(entry, index, options)
return toItemPackDocument(entry, index, options)
}
async function buildPack({
sourcePath,
outputPath,
@@ -95,7 +181,10 @@ async function buildPack({
createdTime,
lastModifiedBy,
})
batch.put(`!items!${doc._id}`, JSON.stringify(doc))
batch.put(doc.key, JSON.stringify(doc.value))
for (const embedded of doc.embedded) {
batch.put(embedded.key, JSON.stringify(embedded.value))
}
})
await batch.write()
} finally {
@@ -106,7 +195,7 @@ async function buildPack({
export async function buildPacks({
sourceRoot,
outputRoot,
packDefinitions = PACK_DEFINITIONS,
packDefinitions = SYSTEM_PACK_DEFINITIONS,
documentSystemId,
documentSystemVersion,
coreVersion,