Deploy deepseek 2
This commit is contained in:
@@ -86,6 +86,14 @@ const ActorSchema = new Schema({
|
||||
// for, shown on the left of the inventory row.
|
||||
icon: { type: String, default: '' }
|
||||
}],
|
||||
// The character's features as the world writes them (Syndria98/dragonroll#89): one row
|
||||
// per Foundry `feat` item, with the item's own picture and text. The free-form `traits`
|
||||
// above keeps the details a world has no item for.
|
||||
features: [{
|
||||
name: { type: String, trim: true, default: '' },
|
||||
description: { type: String, default: '' },
|
||||
icon: { type: String, default: '' }
|
||||
}],
|
||||
traits: { type: String, default: '' },
|
||||
spells: { type: String, default: '' },
|
||||
campaign: {
|
||||
|
||||
@@ -14,9 +14,10 @@ const NoteSchema = new Schema({
|
||||
ref: 'Folder'
|
||||
},
|
||||
color: { type: String },
|
||||
// The journal page this note is written as in the linked Foundry world: the
|
||||
// page of the one "Dragonroll" journal whose rows carry this note's id in
|
||||
// their `dragonroll-foundry.noteId` flag (see the module's notes sync).
|
||||
// The journal page this note is written as in the linked Foundry world: a page
|
||||
// of the journal of this note's folder (root notes: "Dragonroll") whose rows
|
||||
// carry this note's id in their `dragonroll-foundry.noteId` flag (see the
|
||||
// module's notes sync).
|
||||
foundryPageId: { type: String },
|
||||
date: { type: Date, default: Date.now }
|
||||
});
|
||||
|
||||
@@ -74,7 +74,7 @@ router.post('/update', async (req, res) => {
|
||||
try {
|
||||
const {
|
||||
id, name, species, className, subclass, level, abilityScores, armorClass, speed, hitPoints, hitDice,
|
||||
proficiencies, skills, savingThrows, tools, languages, currency, inventory, traits, spells, image, folder
|
||||
proficiencies, skills, savingThrows, tools, languages, currency, inventory, features, traits, spells, image, folder
|
||||
} = req.body;
|
||||
if (!id) return res.json({ status: 'error', msg: 'errors.missing-data' });
|
||||
|
||||
@@ -111,6 +111,7 @@ router.post('/update', async (req, res) => {
|
||||
if (languages !== undefined) actor.languages = textList(languages);
|
||||
if (currency !== undefined) actor.currency = currency;
|
||||
if (inventory !== undefined) actor.inventory = inventory;
|
||||
if (features !== undefined) actor.features = features;
|
||||
if (traits !== undefined) actor.traits = traits;
|
||||
if (spells !== undefined) actor.spells = spells;
|
||||
if (image !== undefined) actor.image = String(image);
|
||||
|
||||
@@ -66,6 +66,9 @@ function resolveWorldAssets(fields, campaign) {
|
||||
if (Array.isArray(fields.inventory)) {
|
||||
for (const entry of fields.inventory) entry.icon = worldAssetUrl(entry.icon, worldUrl);
|
||||
}
|
||||
if (Array.isArray(fields.features)) {
|
||||
for (const entry of fields.features) entry.icon = worldAssetUrl(entry.icon, worldUrl);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveFoundryActor(campaign, source, fullSync = false, replace = false) {
|
||||
@@ -580,24 +583,89 @@ router.post('/sync/map-item', async (req, res) => {
|
||||
});
|
||||
|
||||
// --- Note pages ------------------------------------------------------------
|
||||
// The campaign's notes are read where their authors' table sits: every note
|
||||
// stands as a page of the one journal the world calls "Dragonroll". Notes are
|
||||
// written in Dragonroll, so this copy runs one way — the module reads the notes
|
||||
// and rewrites their pages; nothing of the journal travels back. Its pages keep
|
||||
// the note's id in a `dragonroll-foundry.noteId` flag, and the note keeps the
|
||||
// page's id here, so either side recognises the pairing again after a restart.
|
||||
// The campaign's notes are read where their authors' table sits: each note
|
||||
// stands as a page of the journal of the folder it lives in, and root notes share
|
||||
// the journal the world calls "Dragonroll". Notes are written in Dragonroll, so
|
||||
// this copy runs one way — the module reads the notes and rewrites their pages;
|
||||
// nothing of the journal travels back. Its pages keep the note's id in a
|
||||
// `dragonroll-foundry.noteId` flag, and the note keeps the page's id here, so
|
||||
// either side recognises the pairing again after a restart.
|
||||
|
||||
const NOTE_FOLDER_SEPARATOR = ' / ';
|
||||
|
||||
// The path of the folder a note lives in, from the root down: the module names a
|
||||
// journal after it, so a note in "Sessions / Arc 1" is written into that journal.
|
||||
// A broken parent chain stops at the first folder seen twice instead of looping.
|
||||
function noteFolderPath(folderId, foldersById) {
|
||||
const names = [];
|
||||
const seen = new Set();
|
||||
let folder = folderId ? foldersById.get(String(folderId)) : null;
|
||||
while (folder && !seen.has(String(folder._id))) {
|
||||
seen.add(String(folder._id));
|
||||
if (folder.name) names.unshift(String(folder.name));
|
||||
folder = folder.parentFolder ? foldersById.get(String(folder.parentFolder)) : null;
|
||||
}
|
||||
return names.join(NOTE_FOLDER_SEPARATOR);
|
||||
}
|
||||
|
||||
// The note folders of a campaign, keyed by id, for the path of each note.
|
||||
async function campaignNoteFolders(campaignId) {
|
||||
const folders = await Folder.find({ campaign: campaignId })
|
||||
.select('_id name parentFolder')
|
||||
.lean();
|
||||
return new Map(folders.map((folder) => [String(folder._id), folder]));
|
||||
}
|
||||
|
||||
// A cheap summary of the campaign's notes for the module's change check: the same
|
||||
// notes `/sync/notes` would send, folded into one hash, so a world can tell whether
|
||||
// anything changed without pulling every note's markdown over on every poll. The
|
||||
// folder path travels in the hash too: renaming or moving a folder moves a note to
|
||||
// another journal. The page a note is already mapped to is left out — mapping is
|
||||
// not an edit.
|
||||
router.get('/sync/notes/revision', async (req, res) => {
|
||||
try {
|
||||
const campaign = await syncCampaign(req, res);
|
||||
if (!campaign) return;
|
||||
const notes = await Note.find({ campaign: campaign._id })
|
||||
.select('_id title content folder')
|
||||
.sort({ _id: 1 })
|
||||
.lean();
|
||||
const foldersById = await campaignNoteFolders(campaign._id);
|
||||
const revision = crypto.createHash('sha256')
|
||||
.update(notes.map((note) => [
|
||||
note._id,
|
||||
note.title ?? '',
|
||||
note.content ?? '',
|
||||
note.folder ?? '',
|
||||
noteFolderPath(note.folder, foldersById),
|
||||
].join('\u0000')).join('\u0001'))
|
||||
.digest('hex');
|
||||
res.json({ status: 'ok', revision });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.json({ status: 'error', msg: 'errors.internal' });
|
||||
}
|
||||
});
|
||||
|
||||
// Every note of the campaign, content included: enough for the module to write
|
||||
// each one as a page. Folders of the notes do not travel — the journal is flat.
|
||||
// each one as a page. A note also carries the path of its folder, which names the
|
||||
// journal the page belongs to; root notes carry an empty path.
|
||||
router.get('/sync/notes', async (req, res) => {
|
||||
try {
|
||||
const campaign = await syncCampaign(req, res);
|
||||
if (!campaign) return;
|
||||
const notes = await Note.find({ campaign: campaign._id })
|
||||
.select('_id title content foundryPageId date')
|
||||
.select('_id title content foundryPageId date folder')
|
||||
.sort({ date: -1 })
|
||||
.lean();
|
||||
res.json({ status: 'ok', notes });
|
||||
const foldersById = await campaignNoteFolders(campaign._id);
|
||||
res.json({
|
||||
status: 'ok',
|
||||
notes: notes.map((note) => ({
|
||||
...note,
|
||||
folderPath: noteFolderPath(note.folder, foldersById),
|
||||
})),
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.json({ status: 'error', msg: 'errors.internal' });
|
||||
|
||||
@@ -111,23 +111,27 @@ function foundryCurrency(system) {
|
||||
return Object.fromEntries(CURRENCIES.map((key) => [key, Math.max(0, numberOr(coins[key], 0))]));
|
||||
}
|
||||
|
||||
// The character's traits as the world writes them: the free-text details field some
|
||||
// system releases keep, or its trait items, which are how a monster's traits and a
|
||||
// character's racial and class features are written. `undefined` says the world holds
|
||||
// no traits to show.
|
||||
function foundryTraits(source, items) {
|
||||
// The character's features: D&D 5e files species, background, class and monster features
|
||||
// under the `feat` item type, each with its text and picture on the item. They are what
|
||||
// the sheet's traits tab lists, one row per feature.
|
||||
function foundryFeatures(items) {
|
||||
return items
|
||||
.filter((item) => item.type === 'feat')
|
||||
.map((item) => ({
|
||||
name: asText(item.name).trim(),
|
||||
description: plainText(item.system?.description?.value ?? item.system?.description),
|
||||
icon: asText(item.img).trim()
|
||||
}))
|
||||
.filter((feature) => feature.name);
|
||||
}
|
||||
|
||||
// The free-form traits text: the details field some system releases keep, or what the
|
||||
// campaign wrote and the module carries back on its flag. `undefined` says the world
|
||||
// holds no text of its own, which keeps a live edit from clearing the campaign's.
|
||||
function foundryTraits(source, savedDragonrollFields, replace) {
|
||||
const text = plainText(source.system?.details?.trait);
|
||||
if (text) return text;
|
||||
const features = items
|
||||
.filter((item) => item.type === 'feat' && stringList(item.system?.featType?.value ?? item.system?.featType)
|
||||
.some((type) => asText(type).toLowerCase().startsWith('tr')))
|
||||
.map((item) => {
|
||||
const name = asText(item.name).trim();
|
||||
const description = plainText(item.system?.description?.value ?? item.system?.description);
|
||||
return name ? `${name}\n${description}`.trim() : '';
|
||||
})
|
||||
.filter(Boolean);
|
||||
return features.length ? features.join('\n\n') : undefined;
|
||||
const campaignTraits = replace ? '' : asText(savedDragonrollFields.traits);
|
||||
return text || campaignTraits || undefined;
|
||||
}
|
||||
|
||||
// `replace` is a forced actor sync from the module's context menu (Syndria98/dragonroll#96):
|
||||
@@ -188,7 +192,11 @@ function foundryActorToCharacter(foundryActor, replace = false) {
|
||||
icon: asText(item.img).trim()
|
||||
}))
|
||||
.filter((item) => item.name),
|
||||
spells: items.filter((item) => item.type === 'spell').map((item) => asText(item.name)).filter(Boolean).join('\n')
|
||||
spells: items.filter((item) => item.type === 'spell').map((item) => asText(item.name)).filter(Boolean).join('\n'),
|
||||
// The features themselves, icons and all: the traits tab draws them like the
|
||||
// inventory, and a live edit sends the world's whole item list, so a feature the
|
||||
// GM removed in Foundry goes here too.
|
||||
features: foundryFeatures(items)
|
||||
};
|
||||
|
||||
// What the world says about each of these, when it says anything: leaving a field
|
||||
@@ -206,9 +214,8 @@ function foundryActorToCharacter(foundryActor, replace = false) {
|
||||
if (languages) fields.languages = languages;
|
||||
const currency = foundryCurrency(system);
|
||||
if (currency) fields.currency = currency;
|
||||
const worldTraits = foundryTraits(foundryActor, items);
|
||||
const campaignTraits = replace ? '' : asText(savedDragonrollFields.traits);
|
||||
if (worldTraits || campaignTraits) fields.traits = worldTraits || campaignTraits;
|
||||
const worldTraits = foundryTraits(foundryActor, savedDragonrollFields, replace);
|
||||
if (worldTraits) fields.traits = worldTraits;
|
||||
|
||||
// A replace writes the fields a live edit would leave out when the world says
|
||||
// nothing, so the campaign's toggles, lists and text for this actor go with it and
|
||||
|
||||
Reference in New Issue
Block a user