From 8418b5c254d7b7625e4bf595b8642787e8cb5dba Mon Sep 17 00:00:00 2001 From: Gitea OpenCode Agent Date: Thu, 15 Oct 2026 15:01:35 +0000 Subject: [PATCH] Fix issue #64: More modifications to the character sheet --- backend/src/models/Actor.js | 11 + backend/src/routes/actor.js | 13 +- .../windows/CharacterSheetWindow.vue | 324 +++++++++++------- frontend/i18n/locales/ca/campaigns.json | 3 +- frontend/i18n/locales/en/campaigns.json | 3 +- frontend/i18n/locales/es/campaigns.json | 3 +- tests/character-sheet-portrait-column.test.js | 167 +++++++++ tests/character-sheet-tabs.test.js | 9 +- 8 files changed, 400 insertions(+), 133 deletions(-) create mode 100644 tests/character-sheet-portrait-column.test.js diff --git a/backend/src/models/Actor.js b/backend/src/models/Actor.js index 787b19e7..bf5d9608 100644 --- a/backend/src/models/Actor.js +++ b/backend/src/models/Actor.js @@ -22,6 +22,17 @@ const ActorSchema = new Schema({ }, armorClass: { type: Number, min: 0, default: 10 }, speed: { type: Number, min: 0, default: 30 }, + // The two pools the sheet draws as bars under the portrait (Syndria98/dragonroll#64): the bar + // fills `current` of `max`, so both travel together. `current` is kept below `max` by whoever + // writes them (routes/actor.js), the same way the sheet clamps the bar. + hitPoints: { + current: { type: Number, min: 0, default: 10 }, + max: { type: Number, min: 0, default: 10 } + }, + hitDice: { + current: { type: Number, min: 0, default: 1 }, + max: { type: Number, min: 0, default: 1 } + }, proficiencies: { type: String, default: '' }, inventory: [{ name: { type: String, trim: true, default: '' }, diff --git a/backend/src/routes/actor.js b/backend/src/routes/actor.js index 2a9f881b..d67375c2 100644 --- a/backend/src/routes/actor.js +++ b/backend/src/routes/actor.js @@ -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; diff --git a/frontend/app/components/windows/CharacterSheetWindow.vue b/frontend/app/components/windows/CharacterSheetWindow.vue index 91b6467e..9d6c0908 100644 --- a/frontend/app/components/windows/CharacterSheetWindow.vue +++ b/frontend/app/components/windows/CharacterSheetWindow.vue @@ -34,6 +34,11 @@ const tabs = [ ]; const activeTab = ref('abilities'); +// Les pestanyes pengen del marc de la finestra, per fora del contingent (vegeu .sheet-tabs). La +// finestra es fa més estreta perquè el marge que la centra sigui prou ample per aguantar-les; +// per sota de 760px el marc les fa estar a dins i el marge deixa de fer falta. +const TAB_RAIL_WIDTH = 150; + function normalizeActor(actor) { return { name: actor?.name ?? '', @@ -44,6 +49,16 @@ function normalizeActor(actor) { abilityScores: Object.fromEntries(abilityStats.map(({ key }) => [key, Number(actor?.abilityScores?.[key] ?? 10)])), armorClass: Number(actor?.armorClass ?? 10), speed: Number(actor?.speed ?? 30), + // Les barres sota la imatge: `current` de `max`. Un personatge que encara no en té + // rep un dau de cop per nivell, que és el que D&D compta. + hitPoints: { + current: Number(actor?.hitPoints?.current ?? actor?.hitPoints?.max ?? 10), + max: Number(actor?.hitPoints?.max ?? actor?.hitPoints?.current ?? 10) + }, + hitDice: { + current: Number(actor?.hitDice?.current ?? actor?.level ?? 1), + max: Number(actor?.hitDice?.max ?? actor?.level ?? 1) + }, proficiencies: actor?.proficiencies ?? '', inventory: (actor?.inventory ?? []).map((item) => ({ name: item.name ?? '', quantity: Number(item.quantity ?? 1), weight: Number(item.weight ?? 0) @@ -60,8 +75,11 @@ original.value = normalizeActor(props.data.actor); onMounted(() => { Top(wrapper); SetupHandle(id, handle); + // Les pestanyes pengen del marc per fora del cos: com que la finestra es centra, el marge que + // li queda a la dreta és la meitat del que li sobra, i cal reservar-nos el doble. + const railRoom = window.innerWidth > 760 ? 2 * TAB_RAIL_WIDTH : 0; SetSize(id, { - width: Math.max(320, Math.min(900, window.innerWidth - 24)), + width: Math.max(320, Math.min(900, window.innerWidth - 24 - railRoom)), height: Math.max(360, Math.min(700, window.innerHeight - 32)) }); ResetPosition(id, 'center'); @@ -79,6 +97,15 @@ onMounted(() => emitter.on('campaign-entry-updated', handleActorSync)); onBeforeUnmount(() => emitter.off('campaign-entry-updated', handleActorSync)); const proficiencyBonus = computed(() => Math.ceil(form.value.level / 4) + 1); +// La iniciativa és el modificador de DESTÀ, que és el que D&D compta quan el personatge no +// porta cap do extra que l'augmenti. +const initiativeBonus = computed(() => abilityModifier(form.value.abilityScores.dex)); +// Quina part del màxim representa la barra; buida (màxim 0) o per sobre, tot tallat. +function barPercent(current, max) { + return max > 0 ? Math.min(100, Math.max(0, ((Number(current) || 0) / max) * 100)) : 0; +} +const hitPointsPercent = computed(() => barPercent(form.value.hitPoints.current, form.value.hitPoints.max)); +const hitDicePercent = computed(() => barPercent(form.value.hitDice.current, form.value.hitDice.max)); const carryingCapacity = computed(() => form.value.abilityScores.str * 15); const carriedWeight = computed(() => form.value.inventory.reduce((total, item) => total + (Number(item.quantity) || 0) * (Number(item.weight) || 0), 0)); const carryPercent = computed(() => Math.min(100, carryingCapacity.value ? (carriedWeight.value / carryingCapacity.value) * 100 : 0)); @@ -179,6 +206,21 @@ async function saveSheet() {