Merge pull request 'Fix #64: More modifications to the character sheet' (#70) from ai/issue-64 into master
Reviewed-on: #70
This commit was merged in pull request #70.
This commit is contained in:
@@ -22,6 +22,17 @@ const ActorSchema = new Schema({
|
|||||||
},
|
},
|
||||||
armorClass: { type: Number, min: 0, default: 10 },
|
armorClass: { type: Number, min: 0, default: 10 },
|
||||||
speed: { type: Number, min: 0, default: 30 },
|
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: '' },
|
proficiencies: { type: String, default: '' },
|
||||||
inventory: [{
|
inventory: [{
|
||||||
name: { type: String, trim: true, default: '' },
|
name: { type: String, trim: true, default: '' },
|
||||||
|
|||||||
@@ -13,6 +13,15 @@ async function userOwnsCampaign(campaignId, userId) {
|
|||||||
return Boolean(campaign);
|
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
|
// 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).
|
// (the notes, items and maps each keep a tree of their own, see models/Folder.js).
|
||||||
async function actorFolders(campaignId) {
|
async function actorFolders(campaignId) {
|
||||||
@@ -56,7 +65,7 @@ router.post('/create', async (req, res) => {
|
|||||||
|
|
||||||
router.post('/update', async (req, res) => {
|
router.post('/update', async (req, res) => {
|
||||||
try {
|
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' });
|
if (!id) return res.json({ status: 'error', msg: 'errors.missing-data' });
|
||||||
|
|
||||||
const actor = await Actor.findById(id);
|
const actor = await Actor.findById(id);
|
||||||
@@ -80,6 +89,8 @@ router.post('/update', async (req, res) => {
|
|||||||
if (abilityScores !== undefined) actor.abilityScores = abilityScores;
|
if (abilityScores !== undefined) actor.abilityScores = abilityScores;
|
||||||
if (armorClass !== undefined) actor.armorClass = Number(armorClass);
|
if (armorClass !== undefined) actor.armorClass = Number(armorClass);
|
||||||
if (speed !== undefined) actor.speed = Number(speed);
|
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 (proficiencies !== undefined) actor.proficiencies = proficiencies;
|
||||||
if (inventory !== undefined) actor.inventory = inventory;
|
if (inventory !== undefined) actor.inventory = inventory;
|
||||||
if (traits !== undefined) actor.traits = traits;
|
if (traits !== undefined) actor.traits = traits;
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ const tabs = [
|
|||||||
];
|
];
|
||||||
const activeTab = ref('abilities');
|
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) {
|
function normalizeActor(actor) {
|
||||||
return {
|
return {
|
||||||
name: actor?.name ?? '',
|
name: actor?.name ?? '',
|
||||||
@@ -44,6 +49,16 @@ function normalizeActor(actor) {
|
|||||||
abilityScores: Object.fromEntries(abilityStats.map(({ key }) => [key, Number(actor?.abilityScores?.[key] ?? 10)])),
|
abilityScores: Object.fromEntries(abilityStats.map(({ key }) => [key, Number(actor?.abilityScores?.[key] ?? 10)])),
|
||||||
armorClass: Number(actor?.armorClass ?? 10),
|
armorClass: Number(actor?.armorClass ?? 10),
|
||||||
speed: Number(actor?.speed ?? 30),
|
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 ?? '',
|
proficiencies: actor?.proficiencies ?? '',
|
||||||
inventory: (actor?.inventory ?? []).map((item) => ({
|
inventory: (actor?.inventory ?? []).map((item) => ({
|
||||||
name: item.name ?? '', quantity: Number(item.quantity ?? 1), weight: Number(item.weight ?? 0)
|
name: item.name ?? '', quantity: Number(item.quantity ?? 1), weight: Number(item.weight ?? 0)
|
||||||
@@ -60,8 +75,11 @@ original.value = normalizeActor(props.data.actor);
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
Top(wrapper);
|
Top(wrapper);
|
||||||
SetupHandle(id, handle);
|
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, {
|
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))
|
height: Math.max(360, Math.min(700, window.innerHeight - 32))
|
||||||
});
|
});
|
||||||
ResetPosition(id, 'center');
|
ResetPosition(id, 'center');
|
||||||
@@ -79,6 +97,15 @@ onMounted(() => emitter.on('campaign-entry-updated', handleActorSync));
|
|||||||
onBeforeUnmount(() => emitter.off('campaign-entry-updated', handleActorSync));
|
onBeforeUnmount(() => emitter.off('campaign-entry-updated', handleActorSync));
|
||||||
|
|
||||||
const proficiencyBonus = computed(() => Math.ceil(form.value.level / 4) + 1);
|
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 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 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));
|
const carryPercent = computed(() => Math.min(100, carryingCapacity.value ? (carriedWeight.value / carryingCapacity.value) * 100 : 0));
|
||||||
@@ -179,6 +206,21 @@ async function saveSheet() {
|
|||||||
<template>
|
<template>
|
||||||
<div class="window-wrapper sheet-window" :id="'window-wrapper-' + id" ref="wrapper">
|
<div class="window-wrapper sheet-window" :id="'window-wrapper-' + id" ref="wrapper">
|
||||||
<WindowHandle :window="id" ref="handle" />
|
<WindowHandle :window="id" ref="handle" />
|
||||||
|
|
||||||
|
<!-- Pestilletes del marc de la finestra: pengen del cantó dret, per fora del
|
||||||
|
contingent, i no s'enrolen quan la fitxa desfila. -->
|
||||||
|
<nav class="sheet-tabs" role="tablist" aria-orientation="vertical">
|
||||||
|
<button
|
||||||
|
v-for="tab in tabs"
|
||||||
|
:key="tab.key"
|
||||||
|
class="sheet-tab"
|
||||||
|
:class="{ active: activeTab === tab.key }"
|
||||||
|
type="button"
|
||||||
|
role="tab"
|
||||||
|
:aria-selected="activeTab === tab.key"
|
||||||
|
@click="activeTab = tab.key"
|
||||||
|
>{{ $t(tab.label) }}</button>
|
||||||
|
</nav>
|
||||||
<div class="sheet-body">
|
<div class="sheet-body">
|
||||||
<header class="sheet-hero">
|
<header class="sheet-hero">
|
||||||
<div class="character-mark" aria-hidden="true">{{ form.name.slice(0, 1).toUpperCase() }}</div>
|
<div class="character-mark" aria-hidden="true">{{ form.name.slice(0, 1).toUpperCase() }}</div>
|
||||||
@@ -217,9 +259,8 @@ async function saveSheet() {
|
|||||||
|
|
||||||
<div v-if="error" class="sheet-error">{{ error }}</div>
|
<div v-if="error" class="sheet-error">{{ error }}</div>
|
||||||
|
|
||||||
<div class="sheet-layout">
|
|
||||||
<div class="sheet-content">
|
|
||||||
<main v-show="activeTab === 'abilities'" class="sheet-grid">
|
<main v-show="activeTab === 'abilities'" class="sheet-grid">
|
||||||
|
<div class="character-column">
|
||||||
<div v-if="form.image || editing" class="sheet-portrait" :class="{ empty: !form.image }">
|
<div v-if="form.image || editing" class="sheet-portrait" :class="{ empty: !form.image }">
|
||||||
<img v-if="form.image" :src="imageUrl" :alt="$t('campaigns.character-sheet.photo')">
|
<img v-if="form.image" :src="imageUrl" :alt="$t('campaigns.character-sheet.photo')">
|
||||||
<button v-if="editing && !form.image" class="portrait-upload" type="button" :disabled="uploadingPhoto" @click="pickPhoto">
|
<button v-if="editing && !form.image" class="portrait-upload" type="button" :disabled="uploadingPhoto" @click="pickPhoto">
|
||||||
@@ -234,6 +275,58 @@ async function saveSheet() {
|
|||||||
<input ref="photoInput" class="photo-input" type="file" accept="image/*" @change="onPhotoSelected">
|
<input ref="photoInput" class="photo-input" type="file" accept="image/*" @change="onPhotoSelected">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- El que es mira primer: classe d'armadura, velocitat i els bonificadors
|
||||||
|
que acompanyen els cops, tot just sota la imatge. -->
|
||||||
|
<section class="sheet-panel vitals-panel">
|
||||||
|
<div class="vital-stats">
|
||||||
|
<div class="vital-stat">
|
||||||
|
<span>{{ $t('campaigns.character-sheet.armor-class') }}</span>
|
||||||
|
<input v-if="editing" v-model.number="form.armorClass" type="number" min="0" :aria-label="$t('campaigns.character-sheet.armor-class')">
|
||||||
|
<strong v-else>{{ form.armorClass }}</strong>
|
||||||
|
</div>
|
||||||
|
<div class="vital-stat">
|
||||||
|
<span>{{ $t('campaigns.character-sheet.speed') }}</span>
|
||||||
|
<label v-if="editing" class="number-with-unit"><input v-model.number="form.speed" type="number" min="0" :aria-label="$t('campaigns.character-sheet.speed')"><small>ft</small></label>
|
||||||
|
<strong v-else>{{ form.speed }} <small>ft</small></strong>
|
||||||
|
</div>
|
||||||
|
<div class="vital-stat">
|
||||||
|
<span>{{ $t('campaigns.character-sheet.proficiency-bonus') }}</span>
|
||||||
|
<strong>+{{ proficiencyBonus }}</strong>
|
||||||
|
</div>
|
||||||
|
<div class="vital-stat">
|
||||||
|
<span>{{ $t('campaigns.character-sheet.initiative') }}</span>
|
||||||
|
<strong>{{ initiativeBonus }}</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="vital-bar hit-points-bar">
|
||||||
|
<div class="vital-bar-head">
|
||||||
|
<span>{{ $t('campaigns.character-sheet.hit-points') }}</span>
|
||||||
|
<strong v-if="!editing">{{ form.hitPoints.current }} / {{ form.hitPoints.max }}</strong>
|
||||||
|
<label v-else class="vital-bar-inputs">
|
||||||
|
<input v-model.number="form.hitPoints.current" type="number" min="0" :aria-label="$t('campaigns.character-sheet.hit-points')">
|
||||||
|
<span>/</span>
|
||||||
|
<input v-model.number="form.hitPoints.max" type="number" min="0" :aria-label="$t('campaigns.character-sheet.max-hit-points')">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="vital-bar-track"><div class="vital-bar-fill" :style="{ width: `${hitPointsPercent}%` }" /></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="vital-bar hit-dice-bar">
|
||||||
|
<div class="vital-bar-head">
|
||||||
|
<span>{{ $t('campaigns.character-sheet.hit-dice') }}</span>
|
||||||
|
<strong v-if="!editing">{{ form.hitDice.current }} / {{ form.hitDice.max }}</strong>
|
||||||
|
<label v-else class="vital-bar-inputs">
|
||||||
|
<input v-model.number="form.hitDice.current" type="number" min="0" :aria-label="$t('campaigns.character-sheet.hit-dice')">
|
||||||
|
<span>/</span>
|
||||||
|
<input v-model.number="form.hitDice.max" type="number" min="0" :aria-label="$t('campaigns.character-sheet.max-hit-dice')">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="vital-bar-track"><div class="vital-bar-fill" :style="{ width: `${hitDicePercent}%` }" /></div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
<section class="sheet-panel abilities-panel">
|
<section class="sheet-panel abilities-panel">
|
||||||
<h2>{{ $t('campaigns.character-sheet.ability-scores') }}</h2>
|
<h2>{{ $t('campaigns.character-sheet.ability-scores') }}</h2>
|
||||||
<div class="ability-grid">
|
<div class="ability-grid">
|
||||||
@@ -244,28 +337,11 @@ async function saveSheet() {
|
|||||||
<span class="ability-modifier">{{ abilityModifier(form.abilityScores[stat.key]) }}</span>
|
<span class="ability-modifier">{{ abilityModifier(form.abilityScores[stat.key]) }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="proficiency-badge">
|
|
||||||
<span>{{ $t('campaigns.character-sheet.proficiency-bonus') }}</span>
|
|
||||||
<strong>+{{ proficiencyBonus }}</strong>
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="sheet-panel combat-panel">
|
<section class="sheet-panel proficiencies-panel">
|
||||||
<h2>{{ $t('campaigns.character-sheet.combat') }}</h2>
|
<h2>{{ $t('campaigns.character-sheet.proficiencies') }}</h2>
|
||||||
<div class="combat-stats">
|
<textarea v-if="editing" v-model="form.proficiencies" rows="7" :placeholder="$t('campaigns.character-sheet.proficiencies-placeholder')" />
|
||||||
<div class="combat-stat">
|
|
||||||
<span>{{ $t('campaigns.character-sheet.armor-class') }}</span>
|
|
||||||
<input v-if="editing" v-model.number="form.armorClass" type="number" min="0">
|
|
||||||
<strong v-else>{{ form.armorClass }}</strong>
|
|
||||||
</div>
|
|
||||||
<div class="combat-stat">
|
|
||||||
<span>{{ $t('campaigns.character-sheet.speed') }}</span>
|
|
||||||
<label v-if="editing" class="number-with-unit"><input v-model.number="form.speed" type="number" min="0"><small>ft</small></label>
|
|
||||||
<strong v-else>{{ form.speed }} <small>ft</small></strong>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<h3>{{ $t('campaigns.character-sheet.proficiencies') }}</h3>
|
|
||||||
<textarea v-if="editing" v-model="form.proficiencies" rows="5" :placeholder="$t('campaigns.character-sheet.proficiencies-placeholder')" />
|
|
||||||
<p v-else class="sheet-copy">{{ form.proficiencies || $t('campaigns.character-sheet.empty-proficiencies') }}</p>
|
<p v-else class="sheet-copy">{{ form.proficiencies || $t('campaigns.character-sheet.empty-proficiencies') }}</p>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
@@ -321,21 +397,6 @@ async function saveSheet() {
|
|||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav class="sheet-tabs" role="tablist" aria-orientation="vertical">
|
|
||||||
<button
|
|
||||||
v-for="tab in tabs"
|
|
||||||
:key="tab.key"
|
|
||||||
class="sheet-tab"
|
|
||||||
:class="{ active: activeTab === tab.key }"
|
|
||||||
type="button"
|
|
||||||
role="tab"
|
|
||||||
:aria-selected="activeTab === tab.key"
|
|
||||||
@click="activeTab = tab.key"
|
|
||||||
>{{ $t(tab.label) }}</button>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -359,15 +420,15 @@ async function saveSheet() {
|
|||||||
.sheet-button:disabled { opacity: .55; cursor: wait; }
|
.sheet-button:disabled { opacity: .55; cursor: wait; }
|
||||||
.sheet-button.compact { padding: 5px 9px; font-size: 12px; }
|
.sheet-button.compact { padding: 5px 9px; font-size: 12px; }
|
||||||
.sheet-grid { display: grid; grid-template-columns: minmax(200px, 34%) minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto auto; gap: 11px; align-items: start; }
|
.sheet-grid { display: grid; grid-template-columns: minmax(200px, 34%) minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto auto; gap: 11px; align-items: start; }
|
||||||
.sheet-layout { display: flex; align-items: flex-start; gap: 10px; }
|
|
||||||
.sheet-content { flex: 1 1 auto; min-width: 0; }
|
|
||||||
.sheet-tab-body { display: block; }
|
.sheet-tab-body { display: block; }
|
||||||
.sheet-tabs { flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; align-self: flex-start; }
|
/* Pestilletes del marc: arrencen del cantó dret de la finestra, per fora del cos, i queden
|
||||||
|
fora del contingent que desfila. Per sota de 760px no hi ha lloc fora (vegeu a sota). */
|
||||||
|
.sheet-tabs { position: absolute; left: 100%; top: 34px; display: flex; flex-direction: column; align-items: flex-start; gap: 5px; padding-top: 6px; }
|
||||||
.sheet-tab {
|
.sheet-tab {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
padding: 9px 14px 9px 11px;
|
padding: 9px 14px 9px 11px;
|
||||||
border: 1px solid var(--color-border);
|
border: 1px solid var(--color-border);
|
||||||
border-left-width: 3px;
|
border-left: 0;
|
||||||
border-radius: 0 9px 9px 0;
|
border-radius: 0 9px 9px 0;
|
||||||
background: var(--color-background-soft);
|
background: var(--color-background-soft);
|
||||||
color: var(--color-text);
|
color: var(--color-text);
|
||||||
@@ -378,11 +439,11 @@ async function saveSheet() {
|
|||||||
transition: background .15s ease, border-color .15s ease, color .15s ease;
|
transition: background .15s ease, border-color .15s ease, color .15s ease;
|
||||||
}
|
}
|
||||||
.sheet-tab:hover { background: var(--color-button-hover); }
|
.sheet-tab:hover { background: var(--color-button-hover); }
|
||||||
.sheet-tab.active { background: var(--color-background-light); color: var(--color-link); border-left-color: var(--color-link); box-shadow: 0 3px 12px var(--color-window-shadow); }
|
.sheet-tab.active { background: var(--color-background-light); color: var(--color-link); border-color: var(--color-link); box-shadow: 0 3px 12px var(--color-window-shadow); }
|
||||||
.sheet-panel { min-width: 0; padding: 13px; border: 1px solid var(--color-border); border-radius: 10px; background: var(--color-background-light); box-shadow: 0 3px 12px var(--color-window-shadow); }
|
.sheet-panel { min-width: 0; padding: 13px; border: 1px solid var(--color-border); border-radius: 10px; background: var(--color-background-light); box-shadow: 0 3px 12px var(--color-window-shadow); }
|
||||||
.sheet-panel h2 { margin: 0 0 12px; padding-bottom: 7px; border-bottom: 1px solid var(--color-border); font: 17px MrEavesRemake; letter-spacing: .03em; }
|
.sheet-panel h2 { margin: 0 0 12px; padding-bottom: 7px; border-bottom: 1px solid var(--color-border); font: 17px MrEavesRemake; letter-spacing: .03em; }
|
||||||
.sheet-panel h3 { margin: 13px 0 7px; font: 14px MrEavesRemake; }
|
.sheet-panel h3 { margin: 13px 0 7px; font: 14px MrEavesRemake; }
|
||||||
.sheet-portrait { grid-column: 1; grid-row: 1 / -1; position: relative; overflow: hidden; border: 1px solid var(--color-border); border-radius: 10px; background: var(--color-background-soft); }
|
.sheet-portrait { position: relative; overflow: hidden; border: 1px solid var(--color-border); border-radius: 10px; background: var(--color-background-soft); }
|
||||||
.sheet-portrait.empty { display: grid; place-items: center; min-height: 220px; border-style: dashed; }
|
.sheet-portrait.empty { display: grid; place-items: center; min-height: 220px; border-style: dashed; }
|
||||||
.sheet-portrait img { display: block; width: 100%; height: auto; }
|
.sheet-portrait img { display: block; width: 100%; height: auto; }
|
||||||
.portrait-upload { border: 0; padding: 8px 10px; background: transparent; color: var(--color-link); font-size: 12px; cursor: pointer; }
|
.portrait-upload { border: 0; padding: 8px 10px; background: transparent; color: var(--color-link); font-size: 12px; cursor: pointer; }
|
||||||
@@ -392,21 +453,34 @@ async function saveSheet() {
|
|||||||
.portrait-controls button:hover { background: var(--color-button-hover); }
|
.portrait-controls button:hover { background: var(--color-button-hover); }
|
||||||
.portrait-controls button:disabled { opacity: .55; cursor: wait; }
|
.portrait-controls button:disabled { opacity: .55; cursor: wait; }
|
||||||
.photo-input { display: none; }
|
.photo-input { display: none; }
|
||||||
|
/* La columna de la fitxa: la imatge dalt i, just a sota, el que es consulta d'anada i
|
||||||
|
tornada — classe d'armadura, velocitat, bonificadors i les barres de cops. */
|
||||||
|
.character-column { grid-column: 1; grid-row: 1 / -1; display: flex; flex-direction: column; gap: 11px; min-width: 0; }
|
||||||
.abilities-panel { grid-column: 2 / -1; grid-row: 1; }
|
.abilities-panel { grid-column: 2 / -1; grid-row: 1; }
|
||||||
.combat-panel { grid-column: 2 / -1; grid-row: 2; }
|
.proficiencies-panel { grid-column: 2 / -1; grid-row: 2; }
|
||||||
.ability-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 7px; }
|
.ability-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 7px; }
|
||||||
.ability-card { min-height: 83px; padding: 8px 5px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-background-soft); }
|
.ability-card { min-height: 83px; padding: 8px 5px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-background-soft); }
|
||||||
.ability-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; opacity: .75; }
|
.ability-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; opacity: .75; }
|
||||||
.ability-score { font: 25px MrEavesRemake; }
|
.ability-score { font: 25px MrEavesRemake; }
|
||||||
.ability-modifier { min-width: 33px; text-align: center; padding: 2px 5px; border-radius: 999px; background: var(--color-background); font-size: 12px; }
|
.ability-modifier { min-width: 33px; text-align: center; padding: 2px 5px; border-radius: 999px; background: var(--color-background); font-size: 12px; }
|
||||||
.ability-card input { width: 55px; text-align: center; font-size: 21px; }
|
.ability-card input { width: 55px; text-align: center; font-size: 21px; }
|
||||||
.proficiency-badge { display: flex; justify-content: space-between; align-items: center; margin-top: 9px; padding: 8px; border-radius: 8px; background: var(--color-background-soft); font-size: 12px; }
|
.vitals-panel { display: flex; flex-direction: column; gap: 11px; }
|
||||||
.proficiency-badge strong { font-size: 15px; color: var(--color-link); }
|
.vital-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
|
||||||
.combat-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
|
.vital-stat { min-height: 68px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 6px 4px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-background-soft); text-align: center; }
|
||||||
.combat-stat { min-height: 72px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-background-soft); }
|
.vital-stat > span { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; opacity: .72; }
|
||||||
.combat-stat > span { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; opacity: .72; }
|
.vital-stat > strong { font: 25px MrEavesRemake; }
|
||||||
.combat-stat > strong { font: 25px MrEavesRemake; }
|
.vital-stat small { font-size: 11px; opacity: .7; }
|
||||||
.combat-stat small { font-size: 11px; opacity: .7; }
|
.vital-stat input { width: 57px; text-align: center; }
|
||||||
|
/* Les dues barres: punts de cop i daus de cop, plenes fins on arriben. */
|
||||||
|
.vital-bar-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
|
||||||
|
.vital-bar-head > span { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; opacity: .72; }
|
||||||
|
.vital-bar-head > strong { font: 15px MrEavesRemake; white-space: nowrap; }
|
||||||
|
.vital-bar-inputs { display: flex; align-items: center; gap: 4px; }
|
||||||
|
.vital-bar-inputs input { width: 52px; text-align: center; }
|
||||||
|
.vital-bar-track { height: 8px; margin-top: 5px; overflow: hidden; border-radius: 999px; background: var(--color-background); }
|
||||||
|
.vital-bar-fill { height: 100%; border-radius: inherit; transition: width .2s ease; }
|
||||||
|
.hit-points-bar .vital-bar-fill { background: var(--color-red); }
|
||||||
|
.hit-dice-bar .vital-bar-fill { background: var(--color-link); }
|
||||||
.number-with-unit { display: flex; align-items: center; gap: 4px; }
|
.number-with-unit { display: flex; align-items: center; gap: 4px; }
|
||||||
.number-with-unit input { width: 57px; }
|
.number-with-unit input { width: 57px; }
|
||||||
.sheet-copy { min-height: 74px; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.45; opacity: .85; }
|
.sheet-copy { min-height: 74px; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.45; opacity: .85; }
|
||||||
@@ -434,16 +508,16 @@ textarea { resize: vertical; width: 100%; min-height: 88px; font-size: 12px; }
|
|||||||
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
|
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
|
||||||
@media (max-width: 760px) {
|
@media (max-width: 760px) {
|
||||||
.sheet-grid { grid-template-columns: 1fr; grid-template-rows: none; }
|
.sheet-grid { grid-template-columns: 1fr; grid-template-rows: none; }
|
||||||
.sheet-portrait, .abilities-panel, .combat-panel { grid-column: 1 / -1; grid-row: auto; }
|
.character-column, .abilities-panel, .proficiencies-panel { grid-column: 1 / -1; grid-row: auto; }
|
||||||
|
/* El cantó dret no dona prou per penjar-hi les pestanyes: llavors es queden al marc, per
|
||||||
|
dins, en una filera sota la barra de la finestra. */
|
||||||
|
.sheet-tabs { position: static; align-self: stretch; flex-direction: row; flex-wrap: wrap; gap: 4px; padding: 6px 8px 0; }
|
||||||
|
.sheet-tab { flex: 1 1 auto; text-align: center; border-left: 1px solid var(--color-border); border-radius: 8px 8px 0 0; }
|
||||||
}
|
}
|
||||||
@media (max-width: 520px) {
|
@media (max-width: 520px) {
|
||||||
.sheet-body { padding: 10px; }
|
.sheet-body { padding: 10px; }
|
||||||
.sheet-hero { align-items: flex-start; flex-wrap: wrap; }
|
.sheet-hero { align-items: flex-start; flex-wrap: wrap; }
|
||||||
.sheet-actions { margin-left: auto; }
|
.sheet-actions { margin-left: auto; }
|
||||||
.ability-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
.ability-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
||||||
.sheet-layout { flex-direction: column; }
|
|
||||||
.sheet-tabs { flex-direction: row; flex-wrap: wrap; order: -1; }
|
|
||||||
.sheet-tab { flex: 1 1 auto; text-align: center; border-radius: 7px; border-left-width: 1px; border-top-width: 3px; }
|
|
||||||
.sheet-tab.active { border-left-color: var(--color-border); border-top-color: var(--color-link); }
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -108,7 +108,8 @@
|
|||||||
"tabs": { "abilities": "Característiques", "inventory": "Inventari", "traits": "Trets", "spells": "Conjurs" },
|
"tabs": { "abilities": "Característiques", "inventory": "Inventari", "traits": "Trets", "spells": "Conjurs" },
|
||||||
"level": "Nivell", "species": "Espècie", "unset-species": "Espècie sense definir", "edit": "Edita la fitxa", "cancel": "Cancel·la",
|
"level": "Nivell", "species": "Espècie", "unset-species": "Espècie sense definir", "edit": "Edita la fitxa", "cancel": "Cancel·la",
|
||||||
"saving": "Desant...", "save": "Desa la fitxa", "save-error": "No s'ha pogut desar aquesta fitxa de personatge.", "photo": "Foto", "upload-photo": "Pujar foto", "change-photo": "Canviar foto", "remove-photo": "Treure foto", "uploading-photo": "Pujant...", "photo-error": "No s'ha pogut pujar aquesta foto.", "ability-scores": "Característiques", "proficiency-bonus": "Bonificador de competència",
|
"saving": "Desant...", "save": "Desa la fitxa", "save-error": "No s'ha pogut desar aquesta fitxa de personatge.", "photo": "Foto", "upload-photo": "Pujar foto", "change-photo": "Canviar foto", "remove-photo": "Treure foto", "uploading-photo": "Pujant...", "photo-error": "No s'ha pogut pujar aquesta foto.", "ability-scores": "Característiques", "proficiency-bonus": "Bonificador de competència",
|
||||||
"combat": "Combat", "armor-class": "Classe d'armadura", "speed": "Velocitat", "proficiencies": "Competències",
|
"combat": "Combat", "armor-class": "Classe d'armadura", "speed": "Velocitat", "initiative": "Iniciativa",
|
||||||
|
"hit-points": "Punts de cop", "max-hit-points": "Punts de cop màxims", "hit-dice": "Daus de cop", "max-hit-dice": "Daus de cop màxims", "proficiencies": "Competències",
|
||||||
"proficiencies-placeholder": "Afegeix salvacions, habilitats, armadures, armes, eines i idiomes...", "empty-proficiencies": "No hi ha competències afegides.",
|
"proficiencies-placeholder": "Afegeix salvacions, habilitats, armadures, armes, eines i idiomes...", "empty-proficiencies": "No hi ha competències afegides.",
|
||||||
"traits": "Trets", "traits-placeholder": "Afegeix trets, capacitats i altres detalls...", "empty-traits": "No hi ha trets afegits.",
|
"traits": "Trets", "traits-placeholder": "Afegeix trets, capacitats i altres detalls...", "empty-traits": "No hi ha trets afegits.",
|
||||||
"spells": "Conjurs", "spells-placeholder": "Escriu els conjurs, un per línia...", "empty-spells": "No hi ha conjurs afegits.",
|
"spells": "Conjurs", "spells-placeholder": "Escriu els conjurs, un per línia...", "empty-spells": "No hi ha conjurs afegits.",
|
||||||
|
|||||||
@@ -114,7 +114,8 @@
|
|||||||
"saving": "Saving...", "save": "Save sheet", "save-error": "Unable to save this character sheet.",
|
"saving": "Saving...", "save": "Save sheet", "save-error": "Unable to save this character sheet.",
|
||||||
"photo": "Photo", "upload-photo": "Upload photo", "change-photo": "Change photo", "remove-photo": "Remove photo",
|
"photo": "Photo", "upload-photo": "Upload photo", "change-photo": "Change photo", "remove-photo": "Remove photo",
|
||||||
"uploading-photo": "Uploading...", "photo-error": "Unable to upload this photo.", "ability-scores": "Ability Scores", "proficiency-bonus": "Proficiency Bonus",
|
"uploading-photo": "Uploading...", "photo-error": "Unable to upload this photo.", "ability-scores": "Ability Scores", "proficiency-bonus": "Proficiency Bonus",
|
||||||
"combat": "Combat", "armor-class": "Armor Class", "speed": "Speed", "proficiencies": "Proficiencies",
|
"combat": "Combat", "armor-class": "Armor Class", "speed": "Speed", "initiative": "Initiative",
|
||||||
|
"hit-points": "Hit Points", "max-hit-points": "Maximum hit points", "hit-dice": "Hit Dice", "max-hit-dice": "Maximum hit dice", "proficiencies": "Proficiencies",
|
||||||
"proficiencies-placeholder": "Add saving throws, skills, armor, weapons, tools, and languages...", "empty-proficiencies": "No proficiencies added.",
|
"proficiencies-placeholder": "Add saving throws, skills, armor, weapons, tools, and languages...", "empty-proficiencies": "No proficiencies added.",
|
||||||
"traits": "Traits", "traits-placeholder": "Add features, traits, and other character details...", "empty-traits": "No traits added.",
|
"traits": "Traits", "traits-placeholder": "Add features, traits, and other character details...", "empty-traits": "No traits added.",
|
||||||
"spells": "Spells", "spells-placeholder": "List spells, one per line...", "empty-spells": "No spells added.",
|
"spells": "Spells", "spells-placeholder": "List spells, one per line...", "empty-spells": "No spells added.",
|
||||||
|
|||||||
@@ -108,7 +108,8 @@
|
|||||||
"tabs": { "abilities": "Características", "inventory": "Inventario", "traits": "Rasgos", "spells": "Conjuros" },
|
"tabs": { "abilities": "Características", "inventory": "Inventario", "traits": "Rasgos", "spells": "Conjuros" },
|
||||||
"level": "Nivel", "species": "Especie", "unset-species": "Especie sin definir", "edit": "Editar hoja", "cancel": "Cancelar",
|
"level": "Nivel", "species": "Especie", "unset-species": "Especie sin definir", "edit": "Editar hoja", "cancel": "Cancelar",
|
||||||
"saving": "Guardando...", "save": "Guardar hoja", "save-error": "No se pudo guardar esta hoja de personaje.", "photo": "Foto", "upload-photo": "Subir foto", "change-photo": "Cambiar foto", "remove-photo": "Quitar foto", "uploading-photo": "Subiendo...", "photo-error": "No se pudo subir esta foto.", "ability-scores": "Características", "proficiency-bonus": "Bonificador por competencia",
|
"saving": "Guardando...", "save": "Guardar hoja", "save-error": "No se pudo guardar esta hoja de personaje.", "photo": "Foto", "upload-photo": "Subir foto", "change-photo": "Cambiar foto", "remove-photo": "Quitar foto", "uploading-photo": "Subiendo...", "photo-error": "No se pudo subir esta foto.", "ability-scores": "Características", "proficiency-bonus": "Bonificador por competencia",
|
||||||
"combat": "Combate", "armor-class": "Clase de armadura", "speed": "Velocidad", "proficiencies": "Competencias",
|
"combat": "Combate", "armor-class": "Clase de armadura", "speed": "Velocidad", "initiative": "Iniciativa",
|
||||||
|
"hit-points": "Puntos de golpe", "max-hit-points": "Puntos de golpe máximos", "hit-dice": "Dados de golpe", "max-hit-dice": "Dados de golpe máximos", "proficiencies": "Competencias",
|
||||||
"proficiencies-placeholder": "Añade salvaciones, habilidades, armaduras, armas, herramientas e idiomas...", "empty-proficiencies": "No hay competencias añadidas.",
|
"proficiencies-placeholder": "Añade salvaciones, habilidades, armaduras, armas, herramientas e idiomas...", "empty-proficiencies": "No hay competencias añadidas.",
|
||||||
"traits": "Rasgos", "traits-placeholder": "Añade rasgos, capacidades y otros detalles...", "empty-traits": "No hay rasgos añadidos.",
|
"traits": "Rasgos", "traits-placeholder": "Añade rasgos, capacidades y otros detalles...", "empty-traits": "No hay rasgos añadidos.",
|
||||||
"spells": "Conjuros", "spells-placeholder": "Escribe los conjuros, uno por línea...", "empty-spells": "No hay conjuros añadidos.",
|
"spells": "Conjuros", "spells-placeholder": "Escribe los conjuros, uno por línea...", "empty-spells": "No hay conjuros añadidos.",
|
||||||
|
|||||||
167
tests/character-sheet-portrait-column.test.js
Normal file
167
tests/character-sheet-portrait-column.test.js
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
// Tests for Syndria98/dragonroll#64, the second round of modifications to the character sheet:
|
||||||
|
// * the tab rail hangs off the border of the window instead of standing inside the sheet body,
|
||||||
|
// * the armor class, the speed, the proficiency bonus and the initiative bonus stand under the
|
||||||
|
// portrait, together with the hit points and the hit dice, both drawn as bars.
|
||||||
|
//
|
||||||
|
// The window is a `.vue` file and the repository root installs no dependencies for it, so its
|
||||||
|
// template and styles are read out of the source the way tests/character-sheet-tabs.test.js reads
|
||||||
|
// them. The plain functions the sheet and the route work out their numbers with are lifted out of
|
||||||
|
// those sources and called, the way tests/map-viewer.test.js runs a service it cannot import.
|
||||||
|
//
|
||||||
|
// Run with `npm test` from the repository root, or `node --test tests/`.
|
||||||
|
|
||||||
|
const { test } = require("node:test");
|
||||||
|
const assert = require("node:assert/strict");
|
||||||
|
const fs = require("node:fs");
|
||||||
|
const path = require("node:path");
|
||||||
|
|
||||||
|
const read = (...parts) => fs.readFileSync(path.join(__dirname, "..", ...parts), "utf8");
|
||||||
|
|
||||||
|
const sheetSource = read("frontend", "app", "components", "windows", "CharacterSheetWindow.vue");
|
||||||
|
const script = /<script setup>([\s\S]*?)<\/script>/.exec(sheetSource)?.[1] ?? "";
|
||||||
|
const template = /<template>([\s\S]*)<\/template>/.exec(sheetSource)?.[1] ?? "";
|
||||||
|
const actorModelSource = read("backend", "src", "models", "Actor.js");
|
||||||
|
const actorRouteSource = read("backend", "src", "routes", "actor.js");
|
||||||
|
|
||||||
|
// `fromSource` hands back one top-level declaration as a value. Imports and refs are module scope
|
||||||
|
// the test does not have, so the few names a declaration reads are passed in as arguments. The
|
||||||
|
// declaration runs in this realm, so the objects it builds compare with the ones the test builds.
|
||||||
|
function fromSource(source, pattern, locals = {}) {
|
||||||
|
const declaration = pattern.exec(source)?.[0];
|
||||||
|
assert.ok(declaration, `expected ${pattern} in the source`);
|
||||||
|
const name = /(?:const|function)\s+(\w+)/.exec(declaration)[1];
|
||||||
|
return new Function(...Object.keys(locals), `${declaration}\n;return ${name};`)(...Object.values(locals));
|
||||||
|
}
|
||||||
|
|
||||||
|
const abilityStats = fromSource(script, /const abilityStats = \[[\s\S]*?\];/);
|
||||||
|
const normalizeActor = fromSource(script, /function normalizeActor\(actor\) \{[\s\S]*?\n\}/, { abilityStats });
|
||||||
|
const barPercent = fromSource(script, /function barPercent\(current, max\) \{[\s\S]*?\n\}/);
|
||||||
|
const barPool = fromSource(actorRouteSource, /function barPool\(existing, value\) \{[\s\S]*?\n\}/);
|
||||||
|
|
||||||
|
// The column that opens the abilities tab: the portrait with everything under it.
|
||||||
|
function portraitColumn() {
|
||||||
|
const start = template.indexOf('<div class="character-column">');
|
||||||
|
const end = template.indexOf('<section class="sheet-panel abilities-panel">');
|
||||||
|
assert.ok(start !== -1 && end > start, "expected a character column ahead of the ability scores");
|
||||||
|
return template.slice(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
test("the tab rail hangs off the border of the window, outside the sheet body", () => {
|
||||||
|
const rail = /\.sheet-tabs\s*\{[^}]*\}/.exec(sheetSource)?.[0] ?? "";
|
||||||
|
assert.match(rail, /position:\s*absolute/, "the rail is mounted on the window frame");
|
||||||
|
assert.match(rail, /left:\s*100%/, "it starts at the right border and reaches outwards");
|
||||||
|
assert.ok(
|
||||||
|
template.indexOf('<nav class="sheet-tabs"') < template.indexOf('<div class="sheet-body">'),
|
||||||
|
"the rail is a child of the window, ahead of the body it hangs beside"
|
||||||
|
);
|
||||||
|
const body = /\.sheet-body\s*\{[^}]*\}/.exec(sheetSource)?.[0] ?? "";
|
||||||
|
assert.match(body, /overflow:\s*auto/, "the sheet body scrolls on its own, the rail stays put");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the armor class, the speed and both bonuses stand under the portrait", () => {
|
||||||
|
const column = portraitColumn();
|
||||||
|
assert.ok(column.includes('class="sheet-portrait"'), "the portrait opens the column");
|
||||||
|
assert.ok(column.includes('class="sheet-panel vitals-panel"'), "the readouts follow the image");
|
||||||
|
assert.ok(
|
||||||
|
column.indexOf('class="sheet-portrait"') < column.indexOf("vitals-panel"),
|
||||||
|
"the readouts stand under the image, not above it"
|
||||||
|
);
|
||||||
|
for (const key of ["armor-class", "speed", "proficiency-bonus", "initiative"]) {
|
||||||
|
assert.ok(
|
||||||
|
column.includes(`campaigns.character-sheet.${key}`),
|
||||||
|
`the ${key} belongs under the image`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gone from where they were: the combat panel is nothing but proficiencies left over, and the
|
||||||
|
// ability scores panel keeps the six scores only.
|
||||||
|
assert.doesNotMatch(template, /combat-panel/, "the combat panel went with the combat stats");
|
||||||
|
const abilities = template
|
||||||
|
.slice(template.indexOf('<section class="sheet-panel abilities-panel">'))
|
||||||
|
.split("</section>")[0];
|
||||||
|
assert.doesNotMatch(abilities, /proficiency-bonus/, "the proficiency bonus moved down the column");
|
||||||
|
assert.match(abilities, /campaigns\.character-sheet\.ability-scores/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the hit points and the hit dice stand as bars under the portrait", () => {
|
||||||
|
const column = portraitColumn();
|
||||||
|
assert.match(column, /class="vital-bar hit-points-bar"/);
|
||||||
|
assert.match(column, /class="vital-bar hit-dice-bar"/);
|
||||||
|
for (const pool of ["hitPoints", "hitDice"]) {
|
||||||
|
assert.match(column, new RegExp(`v-model\\.number="form\\.${pool}\\.current"`), `${pool} is editable`);
|
||||||
|
assert.match(column, new RegExp(`v-model\\.number="form\\.${pool}\\.max"`), `${pool} has a maximum to set`);
|
||||||
|
assert.match(
|
||||||
|
column,
|
||||||
|
new RegExp(`\\{\\{ form\\.${pool}\\.current \\}\\} / \\{\\{ form\\.${pool}\\.max \\}\\}`),
|
||||||
|
`${pool} reads current of max outside of editing`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Each bar fills what its own maximum allows, and each is painted its own colour.
|
||||||
|
assert.match(column, /:style="\{ width: `\$\{hitPointsPercent\}%` \}"/);
|
||||||
|
assert.match(column, /:style="\{ width: `\$\{hitDicePercent\}%` \}"/);
|
||||||
|
assert.match(sheetSource, /\.hit-points-bar \.vital-bar-fill\s*\{[^}]*var\(--color-red\)/);
|
||||||
|
assert.match(sheetSource, /\.hit-dice-bar \.vital-bar-fill\s*\{[^}]*var\(--color-link\)/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a bar fills what its maximum allows, no more and no less", () => {
|
||||||
|
assert.equal(barPercent(5, 10), 50);
|
||||||
|
assert.equal(barPercent(12, 10), 100, "healed past the maximum does not overflow the track");
|
||||||
|
assert.equal(barPercent(-3, 10), 0, "nothing left stands empty");
|
||||||
|
assert.equal(barPercent(4, 0), 0, "a maximum of nothing is no bar either");
|
||||||
|
assert.equal(barPercent("", 10), 0, "an input cleared mid-edit is read as nothing");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the initiative bonus is the modifier of dexterity", () => {
|
||||||
|
assert.match(
|
||||||
|
script,
|
||||||
|
/const initiativeBonus = computed\(\(\) => abilityModifier\(form\.value\.abilityScores\.dex\)\)/,
|
||||||
|
"D&D counts initiative as the dexterity modifier while the character carries no extra bonus"
|
||||||
|
);
|
||||||
|
const abilityModifier = fromSource(script, /function abilityModifier\(score\) \{[\s\S]*?\n\}/);
|
||||||
|
assert.equal(abilityModifier(16), "+3");
|
||||||
|
assert.equal(abilityModifier(10), "+0", "the sheet writes a flat modifier with its sign, as the ability cards do");
|
||||||
|
assert.equal(abilityModifier(9), "-1");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("an actor carries its pools, and one without them starts on its level", () => {
|
||||||
|
assert.deepEqual(normalizeActor({ level: 3 }).hitPoints, { current: 10, max: 10 });
|
||||||
|
assert.deepEqual(normalizeActor({ level: 3 }).hitDice, { current: 3, max: 3 }, "one die per level");
|
||||||
|
const wounded = normalizeActor({
|
||||||
|
level: 5,
|
||||||
|
hitPoints: { current: 4, max: 44 },
|
||||||
|
hitDice: { current: 2, max: 5 }
|
||||||
|
});
|
||||||
|
assert.deepEqual(wounded.hitPoints, { current: 4, max: 44 });
|
||||||
|
assert.deepEqual(wounded.hitDice, { current: 2, max: 5 });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the Actor model stores both pools as current of a maximum", () => {
|
||||||
|
for (const pool of ["hitPoints", "hitDice"]) {
|
||||||
|
assert.match(
|
||||||
|
actorModelSource,
|
||||||
|
new RegExp(`${pool}:\\s*\\{\\s*current:\\s*\\{\\s*type:\\s*Number[^}]*\\},\\s*max:\\s*\\{\\s*type:\\s*Number[^}]*\\}`),
|
||||||
|
`${pool} holds a current and a maximum`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the actor update takes both pools and never lets one pass its maximum", () => {
|
||||||
|
assert.match(actorRouteSource, /const \{[^}]*hitPoints[^}]*hitDice[^}]*\} = req\.body;/, "the update reads them off the body");
|
||||||
|
assert.match(actorRouteSource, /if \(hitPoints !== undefined\) actor\.hitPoints = barPool\(actor\.hitPoints, hitPoints\)/);
|
||||||
|
assert.match(actorRouteSource, /if \(hitDice !== undefined\) actor\.hitDice = barPool\(actor\.hitDice, hitDice\)/);
|
||||||
|
|
||||||
|
assert.deepEqual(barPool({ current: 5, max: 20 }, { current: 8, max: 30 }), { current: 8, max: 30 });
|
||||||
|
assert.deepEqual(barPool({ current: 5, max: 20 }, { current: 40 }), { current: 20, max: 20 }, "a current over its maximum stops at the maximum");
|
||||||
|
assert.deepEqual(barPool({ current: 5, max: 20 }, { max: 4 }), { current: 4, max: 4 }, "a maximum lowered below the current pulls it down");
|
||||||
|
assert.deepEqual(barPool({ current: 5, max: 20 }, { current: 12 }), { current: 12, max: 20 }, "half a pair keeps the half it did not send");
|
||||||
|
assert.deepEqual(barPool({ current: 5, max: 20 }, { current: -2, max: 20 }), { current: 0, max: 20 });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("every locale names the readouts that moved under the portrait", () => {
|
||||||
|
for (const locale of ["en", "es", "ca"]) {
|
||||||
|
const sheet = JSON.parse(read("frontend", "i18n", "locales", locale, "campaigns.json"))["character-sheet"];
|
||||||
|
for (const key of ["initiative", "hit-points", "max-hit-points", "hit-dice", "max-hit-dice"]) {
|
||||||
|
assert.ok(sheet[key], `${locale} is missing campaigns.character-sheet.${key}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -37,9 +37,10 @@ test("the tabs sit on the right as a vertical bookmark rail", () => {
|
|||||||
assert.match(template, /v-for="tab in tabs"[\s\S]*?:aria-selected="activeTab === tab\.key"/);
|
assert.match(template, /v-for="tab in tabs"[\s\S]*?:aria-selected="activeTab === tab\.key"/);
|
||||||
const rail = /\.sheet-tabs\s*\{[^}]*\}/.exec(sheetSource)?.[0] ?? "";
|
const rail = /\.sheet-tabs\s*\{[^}]*\}/.exec(sheetSource)?.[0] ?? "";
|
||||||
assert.match(rail, /flex-direction:\s*column/, "the bookmarks stack down the right edge");
|
assert.match(rail, /flex-direction:\s*column/, "the bookmarks stack down the right edge");
|
||||||
// content column and rail sit side by side, the rail hugging the right
|
// #64 moved the rail out of the content: it hangs off the window border itself, so it is not
|
||||||
assert.match(sheetSource, /\.sheet-layout\s*\{[^}]*display:\s*flex[^}]*\}/, "content and rail share a row");
|
// swept along when the sheet scrolls (see tests/character-sheet-portrait-column.test.js).
|
||||||
assert.match(sheetSource, /\.sheet-content\s*\{[^}]*flex:\s*1[^}]*\}/, "the content takes the room, the rail stays slim");
|
assert.match(rail, /position:\s*absolute/, "the rail is mounted on the window frame");
|
||||||
|
assert.match(rail, /left:\s*100%/, "the rail stands outside the window's right border");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Each tab shows only its own panels; the rest are hidden with v-show so an in-progress edit is
|
// Each tab shows only its own panels; the rest are hidden with v-show so an in-progress edit is
|
||||||
@@ -54,7 +55,7 @@ test("every tab shows only its own content and hides the others", () => {
|
|||||||
const abilities = tabBody("abilities");
|
const abilities = tabBody("abilities");
|
||||||
assert.match(abilities, /class="sheet-portrait"/, "the portrait stays with ability scores");
|
assert.match(abilities, /class="sheet-portrait"/, "the portrait stays with ability scores");
|
||||||
assert.match(abilities, /class="sheet-panel abilities-panel"/);
|
assert.match(abilities, /class="sheet-panel abilities-panel"/);
|
||||||
assert.match(abilities, /class="sheet-panel combat-panel"/, "combat rides with the ability scores");
|
assert.match(abilities, /class="sheet-panel proficiencies-panel"/, "the proficiencies ride with the ability scores");
|
||||||
for (const other of ["inventory-panel", "traits-panel", "spells-panel"]) {
|
for (const other of ["inventory-panel", "traits-panel", "spells-panel"]) {
|
||||||
assert.doesNotMatch(abilities, new RegExp(other));
|
assert.doesNotMatch(abilities, new RegExp(other));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user