Fix issue #64: More modifications to the character sheet
Some checks failed
Test / test (push) Failing after 2s
Some checks failed
Test / test (push) Failing after 2s
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user