Files
dragonroll/frontend/app/components/windows/CharacterSheetWindow.vue
Gitea OpenCode Agent f0ffa2f72b
All checks were successful
Test / test (push) Successful in 2s
Fix issue #83: Add more things to the character sheet
2026-10-15 20:40:05 +00:00

682 lines
43 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup>
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
import { SetupHandle, SetSize, ResetPosition, ClearWindow, Top } from '@/services/Windows';
import WindowHandle from './partials/WindowHandle.vue';
import Server, { getBaseUrl } from '~/services/Server';
import { emitter } from '~/services/Emitter';
import { useI18n } from 'vue-i18n';
const props = defineProps(['data']);
const id = props.data.id;
const actorId = props.data.actor?._id;
const handle = ref(null);
const wrapper = ref(null);
const editing = ref(false);
const saving = ref(false);
const error = ref('');
const original = ref(null);
const photoInput = ref(null);
const uploadingPhoto = ref(false);
const { t } = useI18n();
const abilityStats = [
{ key: 'str', label: 'STR' }, { key: 'dex', label: 'DEX' }, { key: 'con', label: 'CON' },
{ key: 'int', label: 'INT' }, { key: 'wis', label: 'WIS' }, { key: 'cha', label: 'CHA' }
];
// Les habilitats del 5e. Cada una té un cercle que s'encén quan el personatge hi és
// proficient, i la modificadora que tira és la de la característica que mana.
const skillList = [
{ key: 'acrobatics', ability: 'dex' }, { key: 'animalHandling', ability: 'wis' },
{ key: 'arcana', ability: 'int' }, { key: 'athletics', ability: 'str' },
{ key: 'deception', ability: 'cha' }, { key: 'history', ability: 'int' },
{ key: 'insight', ability: 'wis' }, { key: 'intimidation', ability: 'cha' },
{ key: 'investigation', ability: 'int' }, { key: 'medicine', ability: 'wis' },
{ key: 'nature', ability: 'int' }, { key: 'perception', ability: 'wis' },
{ key: 'performance', ability: 'cha' }, { key: 'persuasion', ability: 'cha' },
{ key: 'religion', ability: 'int' }, { key: 'sleightOfHand', ability: 'dex' },
{ key: 'stealth', ability: 'dex' }, { key: 'survival', ability: 'wis' }
];
// Les cinc monedes que un personatge porta al damunt.
const currencyUnits = ['pp', 'gp', 'ep', 'sp', 'cp'];
// Les pestanyes del lateral dret reparteixen la fitxa: característiques i combat,
// inventari, trets i conjurs. Són pestanyes de marcadors, no una pàgina nova.
const tabs = [
{ key: 'abilities', label: 'campaigns.character-sheet.tabs.abilities' },
{ key: 'inventory', label: 'campaigns.character-sheet.tabs.inventory' },
{ key: 'traits', label: 'campaigns.character-sheet.tabs.traits' },
{ key: 'spells', label: 'campaigns.character-sheet.tabs.spells' }
];
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;
// Les eines i els idiomes viatgen com a llista i el formulari els edita com un quadre
// de text: un nom per línia. Les comes també separen, que és com s'escriuen en una frase.
function proficiencyText(value) {
const names = Array.isArray(value) ? value : String(value ?? '').split(/[\n,]/);
return [...new Set(names.map((name) => String(name).trim()).filter(Boolean))].join('\n');
}
function proficiencyList(text) {
return [...new Set(String(text ?? '').split(/[\n,]/).map((name) => String(name).trim()).filter(Boolean))];
}
function normalizeActor(actor) {
return {
name: actor?.name ?? '',
species: actor?.species ?? '',
className: actor?.className ?? '',
subclass: actor?.subclass ?? '',
level: Number(actor?.level ?? 1),
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 ?? '',
// El que el personatge sap fer i el que porta: les habilitats i les tirades de
// salvació són cercles que s'encenen, les eines i els idiomes són noms que el
// formulari edita com un text d'una línia per nom, i la moneda són cinc xifres.
skills: Object.fromEntries(skillList.map(({ key }) => [key, Boolean(actor?.skills?.[key])])),
savingThrows: Object.fromEntries(abilityStats.map(({ key }) => [key, Boolean(actor?.savingThrows?.[key])])),
tools: proficiencyText(actor?.tools),
languages: proficiencyText(actor?.languages),
currency: Object.fromEntries(currencyUnits.map((unit) => [unit, Number(actor?.currency?.[unit] ?? 0) || 0])),
inventory: (actor?.inventory ?? []).map((item) => ({
name: item.name ?? '', quantity: Number(item.quantity ?? 1), weight: Number(item.weight ?? 0),
icon: item.icon ?? ''
})),
traits: actor?.traits ?? '',
spells: actor?.spells ?? '',
image: actor?.image ?? ''
};
}
const form = ref(normalizeActor(props.data.actor));
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 - railRoom)),
height: Math.max(360, Math.min(700, window.innerHeight - 32))
});
ResetPosition(id, 'center');
});
onBeforeUnmount(() => ClearWindow({ type: 'character_sheet' }));
function handleActorSync({ entityType, entry }) {
if (entityType !== 'actor' || entry?._id !== actorId || editing.value) return;
form.value = normalizeActor(entry);
original.value = normalizeActor(entry);
}
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));
// `bonus` és el bonificador de proficiència, per a les habilitats i les tirades de
// salvació del personatge que hi està entrenat.
function abilityModifier(score, bonus = 0) {
const modifier = Math.floor((Number(score) - 10) / 2) + (Number(bonus) || 0);
return modifier >= 0 ? `+${modifier}` : String(modifier);
}
function skillModifier(skill) {
return abilityModifier(form.value.abilityScores[skill.ability], form.value.skills[skill.key] ? proficiencyBonus.value : 0);
}
function savingThrowModifier(stat) {
return abilityModifier(form.value.abilityScores[stat.key], form.value.savingThrows[stat.key] ? proficiencyBonus.value : 0);
}
// El cercle d'una habilitat o d'una salvació: s'encén i s'apaga, i es desa amb tota la
// fitxa, com la resta del que s'edita.
function toggleProficiency(group, key) {
form.value[group][key] = !form.value[group][key];
}
// Una imatge pot ser una adreça sencera (la que Foundry dona a un objecte, per
// exemple) o un fitxer pujat aquí, que es serveix per `/api/public`.
function resolveImage(image) {
if (!image) return '';
return /^(https?:|data:|\/\/)/i.test(image)
? image
: `${getBaseUrl()}/public/${image}`;
}
const imageUrl = computed(() => resolveImage(form.value.image));
function pickPhoto() {
photoInput.value?.click();
}
async function onPhotoSelected(event) {
const file = event.target.files?.[0];
event.target.value = '';
if (!file || uploadingPhoto.value) return;
uploadingPhoto.value = true;
error.value = '';
try {
const formData = new FormData();
formData.append('image', file);
const response = await Server().post(`/actor/upload-image?actor=${actorId}`, formData, {
headers: { "Content-Type": "multipart/form-data" }
});
if (response.data.status !== 'ok') {
error.value = t('campaigns.character-sheet.photo-error');
return;
}
// La foto es desa immediatament: manté original intacte perquè cancel·lar no la perdi
form.value.image = response.data.actor?.image ?? form.value.image;
original.value.image = form.value.image;
emitter.emit('campaign-entry-updated', { entityType: 'actor', entry: response.data.actor });
} catch (requestError) {
error.value = t('campaigns.character-sheet.photo-error');
} finally {
uploadingPhoto.value = false;
}
}
function removePhoto() {
form.value.image = '';
}
function startEditing() {
editing.value = true;
error.value = '';
}
function cancelEditing() {
form.value = normalizeActor(original.value);
editing.value = false;
error.value = '';
}
function addInventoryItem() {
form.value.inventory.push({ name: '', quantity: 1, weight: 0 });
}
function removeInventoryItem(index) {
form.value.inventory.splice(index, 1);
}
async function saveSheet() {
if (!form.value.name.trim() || saving.value) return;
saving.value = true;
error.value = '';
try {
const payload = {
id: actorId,
...form.value,
// Les eines i els idiomes van a l'API com a llista, que és com està desats.
tools: proficiencyList(form.value.tools),
languages: proficiencyList(form.value.languages),
inventory: form.value.inventory.filter((item) => item.name.trim())
};
const response = await Server().post('/actor/update', payload);
if (response.data.status !== 'ok') {
error.value = t('campaigns.character-sheet.save-error');
return;
}
original.value = normalizeActor(response.data.actor);
form.value = normalizeActor(response.data.actor);
editing.value = false;
emitter.emit('campaign-entry-updated', { entityType: 'actor', entry: response.data.actor });
} catch (requestError) {
error.value = t('campaigns.character-sheet.save-error');
} finally {
saving.value = false;
}
}
</script>
<template>
<div class="window-wrapper sheet-window" :id="'window-wrapper-' + id" ref="wrapper">
<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">
<header class="sheet-hero">
<div class="character-mark" aria-hidden="true">{{ form.name.slice(0, 1).toUpperCase() }}</div>
<div class="character-identity">
<input v-if="editing" v-model="form.name" class="character-name-input" required :aria-label="$t('campaigns.character-sheet.name')">
<h1 v-else>{{ form.name }}</h1>
<div class="identity-fields">
<label v-if="editing" class="identity-field">
<span>{{ $t('campaigns.character-sheet.class') }}</span><input v-model="form.className">
</label>
<span v-else class="identity-tag">{{ form.className || $t('campaigns.character-sheet.unset-class') }}</span>
<label v-if="editing" class="identity-field">
<span>{{ $t('campaigns.character-sheet.subclass') }}</span><input v-model="form.subclass">
</label>
<span v-else-if="form.subclass" class="identity-tag">{{ form.subclass }}</span>
<label v-if="editing" class="identity-field level-field">
<span>{{ $t('campaigns.character-sheet.level') }}</span><input v-model.number="form.level" type="number" min="1" max="20">
</label>
<span v-else class="identity-tag">{{ $t('campaigns.character-sheet.level') }} {{ form.level }}</span>
<label v-if="editing" class="identity-field">
<span>{{ $t('campaigns.character-sheet.species') }}</span><input v-model="form.species">
</label>
<span v-else class="identity-tag">{{ form.species || $t('campaigns.character-sheet.unset-species') }}</span>
</div>
</div>
<div class="sheet-actions">
<button v-if="!editing" class="sheet-button" type="button" @click="startEditing">{{ $t('campaigns.character-sheet.edit') }}</button>
<template v-else>
<button class="sheet-button secondary" type="button" @click="cancelEditing">{{ $t('campaigns.character-sheet.cancel') }}</button>
<button class="sheet-button primary" type="button" :disabled="saving" @click="saveSheet">
{{ saving ? $t('campaigns.character-sheet.saving') : $t('campaigns.character-sheet.save') }}
</button>
</template>
</div>
</header>
<div v-if="error" class="sheet-error">{{ error }}</div>
<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 }">
<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">
{{ uploadingPhoto ? $t('campaigns.character-sheet.uploading-photo') : $t('campaigns.character-sheet.upload-photo') }}
</button>
<div v-if="editing && form.image" class="portrait-controls">
<button type="button" :disabled="uploadingPhoto" @click="pickPhoto">
{{ uploadingPhoto ? $t('campaigns.character-sheet.uploading-photo') : $t('campaigns.character-sheet.change-photo') }}
</button>
<button type="button" :disabled="uploadingPhoto" :aria-label="$t('campaigns.character-sheet.remove-photo')" @click="removePhoto">×</button>
</div>
<input ref="photoInput" class="photo-input" type="file" accept="image/*" @change="onPhotoSelected">
</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">
<h2>{{ $t('campaigns.character-sheet.ability-scores') }}</h2>
<div class="ability-grid">
<div v-for="stat in abilityStats" :key="stat.key" class="ability-card">
<span class="ability-label">{{ stat.label }}</span>
<input v-if="editing" v-model.number="form.abilityScores[stat.key]" type="number" min="1" max="30" :aria-label="stat.label">
<strong v-else class="ability-score">{{ form.abilityScores[stat.key] }}</strong>
<span class="ability-modifier">{{ abilityModifier(form.abilityScores[stat.key]) }}</span>
</div>
</div>
<!-- Les tirades de salvació van just a sota de les característiques, que
són les que les manen: el cercle diu si el personatge hi està entrenat. -->
<h3>{{ $t('campaigns.character-sheet.saving-throws') }}</h3>
<div class="saving-throw-grid">
<button
v-for="stat in abilityStats"
:key="stat.key"
class="proficiency-row"
type="button"
role="switch"
:aria-checked="form.savingThrows[stat.key]"
:disabled="!editing"
@click="toggleProficiency('savingThrows', stat.key)"
>
<span class="proficiency-dot" :class="{ proficient: form.savingThrows[stat.key] }" aria-hidden="true" />
<span class="proficiency-name">{{ $t(`campaigns.character-sheet.abilities.${stat.key}`) }}</span>
<span class="proficiency-modifier">{{ savingThrowModifier(stat) }}</span>
</button>
</div>
</section>
<section class="sheet-panel skills-panel">
<h2>{{ $t('campaigns.character-sheet.skills') }}</h2>
<div class="skill-grid">
<button
v-for="skill in skillList"
:key="skill.key"
class="proficiency-row"
type="button"
role="switch"
:aria-checked="form.skills[skill.key]"
:disabled="!editing"
@click="toggleProficiency('skills', skill.key)"
>
<span class="proficiency-dot" :class="{ proficient: form.skills[skill.key] }" aria-hidden="true" />
<span class="proficiency-name">{{ $t(`campaigns.character-sheet.skill-names.${skill.key}`) }}</span>
<span class="proficiency-ability">{{ skill.ability.toUpperCase() }}</span>
<span class="proficiency-modifier">{{ skillModifier(skill) }}</span>
</button>
</div>
</section>
<section class="sheet-panel proficiencies-panel">
<h2>{{ $t('campaigns.character-sheet.proficiencies') }}</h2>
<textarea v-if="editing" v-model="form.proficiencies" rows="7" :placeholder="$t('campaigns.character-sheet.proficiencies-placeholder')" />
<p v-else class="sheet-copy">{{ form.proficiencies || $t('campaigns.character-sheet.empty-proficiencies') }}</p>
<!-- Les eines i els idiomes tenen llista pròpia; el text de dalt guarda
el que no en té, com les armadures i les armes. -->
<div class="proficiency-lists">
<div class="proficiency-list">
<h3>{{ $t('campaigns.character-sheet.tools') }}</h3>
<textarea v-if="editing" v-model="form.tools" rows="4" :placeholder="$t('campaigns.character-sheet.tools-placeholder')" />
<p v-else class="sheet-copy">{{ form.tools || $t('campaigns.character-sheet.empty-tools') }}</p>
</div>
<div class="proficiency-list">
<h3>{{ $t('campaigns.character-sheet.languages') }}</h3>
<textarea v-if="editing" v-model="form.languages" rows="4" :placeholder="$t('campaigns.character-sheet.languages-placeholder')" />
<p v-else class="sheet-copy">{{ form.languages || $t('campaigns.character-sheet.empty-languages') }}</p>
</div>
</div>
</section>
</main>
<main v-show="activeTab === 'inventory'" class="sheet-tab-body">
<section class="sheet-panel inventory-panel">
<div class="panel-title-row">
<h2>{{ $t('campaigns.character-sheet.inventory') }}</h2>
<button v-if="editing" class="sheet-button secondary compact" type="button" @click="addInventoryItem">{{ $t('campaigns.character-sheet.add-item') }}</button>
</div>
<div class="weight-summary">
<span>{{ $t('campaigns.character-sheet.carried-weight') }}</span>
<strong>{{ carriedWeight.toFixed(1) }} / {{ carryingCapacity }} lb</strong>
</div>
<div class="weight-track"><div class="weight-fill" :style="{ width: `${carryPercent}%` }" /></div>
<!-- La moneda que el personatge porta a sobre, en les cinc monedes del joc. -->
<h3>{{ $t('campaigns.character-sheet.currency') }}</h3>
<div class="currency-row">
<label v-for="unit in currencyUnits" :key="unit" class="currency-field">
<span>{{ $t(`campaigns.character-sheet.currency-units.${unit}`) }}</span>
<input v-if="editing" v-model.number="form.currency[unit]" type="number" min="0" :aria-label="$t(`campaigns.character-sheet.currency-units.${unit}`)">
<strong v-else>{{ form.currency[unit] }}</strong>
</label>
</div>
<div class="inventory-table-wrap">
<table class="inventory-table">
<thead><tr>
<th><span class="sr-only">{{ $t('campaigns.character-sheet.item-icon') }}</span></th>
<th class="item-name-cell">{{ $t('campaigns.character-sheet.item-name') }}</th>
<th>{{ $t('campaigns.character-sheet.quantity') }}</th>
<th>{{ $t('campaigns.character-sheet.weight-each') }}</th>
<th>{{ $t('campaigns.character-sheet.total-weight') }}</th>
<th v-if="editing"><span class="sr-only">{{ $t('campaigns.character-sheet.actions') }}</span></th>
</tr></thead>
<tbody>
<tr v-for="(item, index) in form.inventory" :key="index">
<td class="item-icon-cell">
<img v-if="item.icon" :src="resolveImage(item.icon)" :alt="$t('campaigns.character-sheet.item-icon')">
<span v-else class="item-icon-blank" aria-hidden="true" />
</td>
<td class="item-name-cell"><input v-if="editing" v-model="item.name" :aria-label="$t('campaigns.character-sheet.item-name')"><span v-else>{{ item.name }}</span></td>
<td><input v-if="editing" v-model.number="item.quantity" type="number" min="1" :aria-label="$t('campaigns.character-sheet.quantity')"><span v-else>{{ item.quantity }}</span></td>
<td><input v-if="editing" v-model.number="item.weight" type="number" min="0" step="0.1" :aria-label="$t('campaigns.character-sheet.weight-each')"><span v-else>{{ Number(item.weight).toFixed(1) }} lb</span></td>
<td>{{ ((Number(item.quantity) || 0) * (Number(item.weight) || 0)).toFixed(1) }} lb</td>
<td v-if="editing"><button class="remove-item" type="button" @click="removeInventoryItem(index)">×</button></td>
</tr>
<tr v-if="form.inventory.length === 0"><td :colspan="editing ? 6 : 5" class="empty-inventory">{{ $t('campaigns.character-sheet.empty-inventory') }}</td></tr>
</tbody>
</table>
</div>
</section>
</main>
<main v-show="activeTab === 'traits'" class="sheet-tab-body">
<section class="sheet-panel traits-panel">
<h2>{{ $t('campaigns.character-sheet.traits') }}</h2>
<textarea v-if="editing" v-model="form.traits" rows="12" :placeholder="$t('campaigns.character-sheet.traits-placeholder')" />
<p v-else class="sheet-copy">{{ form.traits || $t('campaigns.character-sheet.empty-traits') }}</p>
</section>
</main>
<main v-show="activeTab === 'spells'" class="sheet-tab-body">
<section class="sheet-panel spells-panel">
<h2>{{ $t('campaigns.character-sheet.spells') }}</h2>
<textarea v-if="editing" v-model="form.spells" rows="12" :placeholder="$t('campaigns.character-sheet.spells-placeholder')" />
<p v-else class="sheet-copy">{{ form.spells || $t('campaigns.character-sheet.empty-spells') }}</p>
</section>
</main>
</div>
</div>
</template>
<style scoped>
.sheet-window { min-width: 0; min-height: 0; }
.sheet-body { width: 100%; min-height: 0; flex: 1; overflow: auto; padding: 16px; box-sizing: border-box; }
.sheet-hero { display: flex; align-items: center; gap: 14px; padding: 4px 2px 16px; margin-bottom: 12px; border-bottom: 1px solid var(--color-border); }
.character-mark { width: 56px; height: 56px; flex: 0 0 56px; display: grid; place-items: center; border-radius: 12px; background: var(--color-background-soft); color: var(--color-link); border: 1px solid var(--color-border); font: 28px MrEavesRemake; }
.character-identity { flex: 1; min-width: 0; }
.character-identity h1 { margin: 0 0 7px; font: 28px MrEavesRemake; overflow-wrap: anywhere; }
.character-name-input { width: min(100%, 440px); font-size: 24px !important; font-family: MrEavesRemake !important; }
.identity-fields { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.identity-tag { padding: 4px 9px; border: 1px solid var(--color-border); border-radius: 999px; background: var(--color-background-soft); font-size: 12px; opacity: .9; }
.identity-field { display: flex; align-items: center; gap: 5px; font-size: 11px; opacity: .8; }
.identity-field input { width: 106px; }
.identity-field.level-field input { width: 58px; }
.sheet-actions { display: flex; align-items: center; gap: 7px; }
.sheet-button { border: 1px solid var(--color-border); border-radius: 7px; padding: 7px 12px; background: var(--color-background-soft); color: var(--color-text); cursor: pointer; white-space: nowrap; }
.sheet-button:hover { background: var(--color-button-hover); }
.sheet-button.primary { background: var(--color-link); color: var(--color-background); border-color: var(--color-link); }
.sheet-button:disabled { opacity: .55; cursor: wait; }
.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 auto; gap: 11px; align-items: start; }
.sheet-tab-body { display: block; }
/* 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 {
text-align: left;
padding: 9px 14px 9px 11px;
border: 1px solid var(--color-border);
border-left: 0;
border-radius: 0 9px 9px 0;
background: var(--color-background-soft);
color: var(--color-text);
font: 13px MrEavesRemake;
letter-spacing: .02em;
white-space: nowrap;
cursor: pointer;
transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.sheet-tab:hover { background: var(--color-button-hover); }
.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 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-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 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-controls { position: absolute; inset: auto 0 0 0; display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 6px 7px; background: var(--color-background-soft); border-top: 1px solid var(--color-border); }
.portrait-controls button { border: 1px solid var(--color-border); border-radius: 6px; padding: 4px 9px; background: var(--color-background-light); color: var(--color-text); font-size: 11px; cursor: pointer; }
.portrait-controls button:last-child { flex: 0 0 auto; padding: 3px 8px; font-size: 15px; line-height: 1; }
.portrait-controls button:hover { background: var(--color-button-hover); }
.portrait-controls button:disabled { opacity: .55; cursor: wait; }
.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; }
.skills-panel { grid-column: 2 / -1; grid-row: 2; }
.proficiencies-panel { grid-column: 2 / -1; grid-row: 3; }
.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-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; opacity: .75; }
.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-card input { width: 55px; text-align: center; font-size: 21px; }
/* Les habilitats i les tirades de salvació: el cercle diu si el personatge hi està
entrenat, al costat la característica que mana i la modificadora que tira. */
.saving-throw-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.skill-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
.proficiency-row { display: flex; align-items: center; gap: 6px; min-width: 0; padding: 5px 7px; border: 1px solid var(--color-border); border-radius: 7px; background: var(--color-background-soft); color: var(--color-text); font: inherit; font-size: 12px; text-align: left; cursor: pointer; }
.proficiency-row:hover:not(:disabled) { border-color: var(--color-link); }
.proficiency-row:disabled { cursor: default; }
.proficiency-dot { width: 14px; height: 14px; flex: 0 0 14px; border: 2px solid var(--color-border); border-radius: 50%; }
.proficiency-dot.proficient { border-color: var(--color-link); background: var(--color-link); box-shadow: inset 0 0 0 2px var(--color-background-soft); }
.proficiency-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.proficiency-ability { font-size: 10px; letter-spacing: .06em; opacity: .6; }
.proficiency-modifier { font-size: 11px; opacity: .8; }
.proficiency-lists { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.vitals-panel { display: flex; flex-direction: column; gap: 11px; }
.vital-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.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; }
.vital-stat > span { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; opacity: .72; }
.vital-stat > strong { font: 25px MrEavesRemake; }
.vital-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 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; }
input, textarea { box-sizing: border-box; max-width: 100%; padding: 6px 7px; border: 1px solid var(--color-border); border-radius: 6px; background: var(--color-background-soft); color: var(--color-text); font: inherit; }
input:focus, textarea:focus { outline: none; border-color: var(--color-link); }
textarea { resize: vertical; width: 100%; min-height: 88px; font-size: 12px; }
.traits-panel, .spells-panel { min-height: 175px; }
.panel-title-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.panel-title-row h2 { flex: 1; }
.weight-summary { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 1px 0 7px; font-size: 12px; }
.weight-summary strong { white-space: nowrap; }
.weight-track { height: 5px; margin-bottom: 10px; overflow: hidden; border-radius: 999px; background: var(--color-background-soft); }
.weight-fill { height: 100%; border-radius: inherit; background: var(--color-link); transition: width .2s ease; }
.inventory-table-wrap { overflow-x: auto; }
/* La moneda que el personatge porta a sobre, en les cinc del joc. */
.currency-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; margin-bottom: 11px; }
.currency-field { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 4px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-background-soft); text-align: center; }
.currency-field > span { font-size: 10px; letter-spacing: .05em; opacity: .72; }
.currency-field > strong { font: 15px MrEavesRemake; }
.currency-field input { width: 58px; text-align: center; }
.inventory-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.inventory-table th { padding: 6px 7px; text-align: left; font-weight: 600; opacity: .7; }
.inventory-table td { padding: 5px 7px; border-top: 1px solid var(--color-border); }
.inventory-table td input { width: 100%; min-width: 54px; }
.inventory-table td.item-name-cell input { min-width: 100px; }
/* La icona de cada objecte obre la filera; el nom continua alineat a l'esquerra i la
quantitat i els pesos van al centre. */
.inventory-table .item-icon-cell { width: 40px; padding-right: 0; }
.item-icon-cell img { display: block; width: 26px; height: 26px; object-fit: contain; border-radius: 5px; }
.item-icon-blank { display: block; width: 26px; height: 26px; border: 1px dashed var(--color-border); border-radius: 5px; opacity: .35; }
.inventory-table th:not(:first-child):not(.item-name-cell), .inventory-table td:not(:first-child):not(.item-name-cell) { text-align: center; }
.empty-inventory { text-align: center !important; opacity: .65; }
.remove-item { width: 24px; height: 24px; border: 0; border-radius: 5px; background: transparent; color: var(--color-text); font-size: 20px; cursor: pointer; }
.remove-item:hover { background: var(--color-button-hover); }
.sheet-error { padding: 7px 10px; margin-bottom: 10px; border-radius: 6px; color: var(--color-red); background: var(--color-background-soft); 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; }
@media (max-width: 760px) {
.sheet-grid { grid-template-columns: 1fr; grid-template-rows: none; }
.character-column, .abilities-panel, .skills-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) {
.sheet-body { padding: 10px; }
.sheet-hero { align-items: flex-start; flex-wrap: wrap; }
.sheet-actions { margin-left: auto; }
.ability-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.skill-grid, .saving-throw-grid, .proficiency-lists { grid-template-columns: 1fr; }
.currency-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
</style>