Fix issue #64: More modifications to the character sheet
Some checks failed
Test / test (push) Failing after 2s

This commit is contained in:
Gitea OpenCode Agent
2026-10-15 15:01:35 +00:00
parent cdafd1f53a
commit 8418b5c254
8 changed files with 400 additions and 133 deletions

View File

@@ -13,6 +13,15 @@ async function userOwnsCampaign(campaignId, userId) {
return Boolean(campaign);
}
// Hit points and hit dice travel as a bar the sheet fills (`current` of `max`, see models/Actor.js).
// A partial update keeps whatever half of the pair it did not send, and `current` never passes the
// maximum it ends up with.
function barPool(existing, value) {
const max = Math.max(0, Number(value?.max ?? existing?.max) || 0);
const current = Math.max(0, Math.min(Number(value?.current ?? existing?.current) || 0, max));
return { current, max };
}
// Folders the campaign's actors are grouped into, in the shape the sidebar groups by
// (the notes, items and maps each keep a tree of their own, see models/Folder.js).
async function actorFolders(campaignId) {
@@ -56,7 +65,7 @@ router.post('/create', async (req, res) => {
router.post('/update', async (req, res) => {
try {
const { id, name, species, className, subclass, level, abilityScores, armorClass, speed, proficiencies, inventory, traits, spells, image, folder } = req.body;
const { id, name, species, className, subclass, level, abilityScores, armorClass, speed, hitPoints, hitDice, proficiencies, inventory, traits, spells, image, folder } = req.body;
if (!id) return res.json({ status: 'error', msg: 'errors.missing-data' });
const actor = await Actor.findById(id);
@@ -80,6 +89,8 @@ router.post('/update', async (req, res) => {
if (abilityScores !== undefined) actor.abilityScores = abilityScores;
if (armorClass !== undefined) actor.armorClass = Number(armorClass);
if (speed !== undefined) actor.speed = Number(speed);
if (hitPoints !== undefined) actor.hitPoints = barPool(actor.hitPoints, hitPoints);
if (hitDice !== undefined) actor.hitDice = barPool(actor.hitDice, hitDice);
if (proficiencies !== undefined) actor.proficiencies = proficiencies;
if (inventory !== undefined) actor.inventory = inventory;
if (traits !== undefined) actor.traits = traits;