Things
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 1m6s

This commit is contained in:
2026-10-13 22:50:51 +02:00
parent 50828af674
commit af76cf1050
18 changed files with 847 additions and 86 deletions

View File

@@ -25,7 +25,7 @@ const isDragOverSidebar = ref(false);
const expandedFolderIds = ref([]);
const expandedEntryIds = ref([]);
const nestedNoteListRef = ref(null);
let actorRefreshInterval;
let entryRefreshInterval;
async function handleSidebarDrop(event) {
if (activeSection.value !== 'notes') return;
@@ -171,17 +171,17 @@ async function fetchCampaignEntries(entityType = activeSection.value, silent = f
if (!silent) entriesError.value = response.data.msg ?? t('campaigns.errors.load');
return;
}
if (entityType === 'actors') {
const previousById = new Map(actors.value.map((actor) => [actor._id, actor]));
actors.value = response.data.actors;
for (const actor of actors.value) {
const previous = previousById.get(actor._id);
if (previous && JSON.stringify(previous) !== JSON.stringify(actor)) {
emitter.emit('campaign-entry-updated', { entityType: 'actor', entry: actor });
}
const kind = entityType === 'actors' ? 'actor' : 'item';
const list = entityType === 'actors' ? actors : items;
const previousById = new Map(list.value.map((entry) => [entry._id, entry]));
list.value = response.data[entityType];
// Tell open windows about Foundry changes landing behind them.
for (const entry of list.value) {
const previous = previousById.get(entry._id);
if (previous && JSON.stringify(previous) !== JSON.stringify(entry)) {
emitter.emit('campaign-entry-updated', { entityType: kind, entry });
}
} else {
items.value = response.data.items;
}
} catch (error) {
if (!silent) entriesError.value = t('campaigns.errors.load');
@@ -213,9 +213,25 @@ function itemSummary(item) {
return `${t(`campaigns.item.categories.${item.category}`)} · ${t(`campaigns.item.rarities.${item.rarity}`)} · ${t('campaigns.item.quantity-short')} ${item.quantity}`;
}
function editItem(entry) {
if (!campaignId.value) return;
CreateWindow('create_campaign_entry', { entityType: 'item', campaign: campaignId.value, entry });
}
function showEntryMenu(entry, entityType) {
const collection = entityType === 'actor' ? 'actor' : 'item';
ShowContextMenu([{
const menuItems = [];
// Characters are edited in their sheet; items get the entry window in edit mode.
if (entityType !== 'actor') {
menuItems.push({
name: t('campaigns.actions.edit'),
icon: '/icons/iconoir/regular/edit.svg',
action: () => { HideContextMenu(); editItem(entry); }
});
}
menuItems.push({
name: t('campaigns.actions.delete'),
icon: '/icons/iconoir/regular/trash.svg',
action: async () => {
@@ -227,7 +243,8 @@ function showEntryMenu(entry, entityType) {
}
} catch (error) {} finally { HideContextMenu(); }
}
}]);
});
ShowContextMenu(menuItems);
}
function toggleEntryDetails(entryId) {
@@ -289,13 +306,16 @@ onMounted(() => {
if (campaignId.value) {
fetchCampaignNotes();
}
actorRefreshInterval = setInterval(() => {
if (activeSection.value === 'actors' && campaignId.value) fetchCampaignEntries('actors', true);
entryRefreshInterval = setInterval(() => {
// Synced Foundry entries land in the background for both lists.
if ((activeSection.value === 'actors' || activeSection.value === 'items') && campaignId.value) {
fetchCampaignEntries(activeSection.value, true);
}
}, 5000);
});
onBeforeUnmount(() => {
clearInterval(actorRefreshInterval);
clearInterval(entryRefreshInterval);
emitter.off('note-created', handleNoteCreated);
emitter.off('note-renamed', handleNoteRenamed);
emitter.off('delete-note', handleNoteDeleted);
@@ -412,7 +432,10 @@ onBeforeUnmount(() => {
<div v-else-if="entriesError" class="sidebar-state error">{{ entriesError }}</div>
<div v-else-if="items.length === 0" class="sidebar-state">{{ t('campaigns.states.empty-items') }}</div>
<div v-for="item in items" :key="item._id" class="entity-entry" role="button" tabindex="0" :aria-expanded="expandedEntryIds.includes(item._id)" @click="toggleEntryDetails(item._id)" @keydown.enter="toggleEntryDetails(item._id)" @keydown.space.prevent="toggleEntryDetails(item._id)" @contextmenu.prevent="showEntryMenu(item, 'item')">
<span class="entity-entry-name">{{ item.name }}</span>
<span class="entity-entry-name-row">
<span class="entity-entry-name">{{ item.name }}</span>
<span v-if="item.foundryItemId" class="entity-entry-sync">{{ t('campaigns.synced') }}</span>
</span>
<span class="entity-entry-meta">{{ itemSummary(item) }}</span>
<template v-if="expandedEntryIds.includes(item._id)">
<span v-if="item.weight !== undefined" class="entity-entry-description">{{ item.weight }} lb</span>
@@ -567,7 +590,14 @@ onBeforeUnmount(() => {
}
.entity-entry:hover { border-color: var(--color-border); background: var(--color-background-soft); }
.entity-entry:focus-visible { outline: 1px solid var(--color-link); }
.entity-entry-name-row { display: flex; align-items: baseline; gap: 6px; }
.entity-entry-name { font-weight: bold; }
.entity-entry-sync {
font-size: 10px;
letter-spacing: 0.04em;
text-transform: uppercase;
opacity: 0.6;
}
.entity-entry-meta, .entity-entry-description { font-size: 12px; opacity: 0.72; }
.entity-entry-description { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }

View File

@@ -11,13 +11,27 @@ const id = data.id;
const handle = ref(null);
const wrapper = ref(null);
const saving = ref(false);
const form = ref({
name: '', type: 'character', species: '', className: '', level: '', background: '', challengeRating: '',
category: 'adventuring-gear', rarity: 'common', quantity: 1, weight: '', properties: '', description: ''
});
// The window edits items when the sidebar passes one in; actors have their sheet.
const editing = data.entry || null;
const isActor = data.entityType === 'actor';
const endpoint = isActor ? '/actor/create' : '/item/create';
const endpoint = isActor ? '/actor/create' : (editing ? '/item/update' : '/item/create');
function initialForm() {
if (!editing) {
return {
name: '', type: 'character', species: '', className: '', level: '', background: '', challengeRating: '',
category: 'adventuring-gear', rarity: 'common', quantity: 1, weight: '', properties: '', description: ''
};
}
return {
name: editing.name ?? '', type: 'character', species: '', className: '', level: '', background: '', challengeRating: '',
category: editing.category ?? 'adventuring-gear', rarity: editing.rarity ?? 'common',
quantity: editing.quantity ?? 1, weight: editing.weight ?? '', properties: editing.properties ?? '',
description: editing.description ?? ''
};
}
const form = ref(initialForm());
onMounted(() => {
SetupHandle(id, handle);
@@ -31,7 +45,9 @@ async function saveEntry() {
if (!form.value.name.trim() || saving.value) return;
saving.value = true;
try {
const payload = { name: form.value.name.trim(), campaign: data.campaign };
const payload = isActor
? { name: form.value.name.trim(), campaign: data.campaign }
: { name: form.value.name.trim(), ...(editing ? { id: editing._id } : { campaign: data.campaign }) };
if (!isActor) {
for (const field of ['category', 'rarity', 'quantity', 'weight', 'properties', 'description']) {
payload[field] = form.value[field];
@@ -39,7 +55,7 @@ async function saveEntry() {
}
const response = await Server().post(endpoint, payload);
if (response.data.status === 'ok') {
emitter.emit('campaign-entry-created', { entityType: data.entityType, entry: response.data[isActor ? 'actor' : 'item'] });
emitter.emit(editing ? 'campaign-entry-updated' : 'campaign-entry-created', { entityType: data.entityType, entry: response.data[isActor ? 'actor' : 'item'] });
ClearWindow({ id });
}
} catch (error) {
@@ -54,7 +70,8 @@ async function saveEntry() {
<div class="window-wrapper" :id="'window-wrapper-' + id" ref="wrapper">
<WindowHandle :window="id" ref="handle" />
<div class="body">
<h3>{{ $t(isActor ? 'campaigns.actor.new' : 'campaigns.item.new') }}</h3>
<h3>{{ $t(editing ? 'campaigns.item.edit' : (isActor ? 'campaigns.actor.new' : 'campaigns.item.new')) }}</h3>
<p v-if="!isActor && editing?.foundryItemId" class="sync-note">{{ $t('campaigns.item.foundry-sync-note') }}</p>
<form @submit.prevent="saveEntry">
<label class="form-field">
<span>{{ $t('campaigns.fields.name') }}</span>
@@ -109,7 +126,7 @@ async function saveEntry() {
</label>
<div class="form-actions">
<button class="btn-primary sound-click" type="submit" :disabled="saving">
{{ saving ? $t('campaigns.actions.saving') : $t('campaigns.actions.submit') }}
{{ saving ? $t('campaigns.actions.saving') : $t(editing ? 'campaigns.actions.save' : 'campaigns.actions.submit') }}
</button>
</div>
</form>
@@ -121,6 +138,7 @@ async function saveEntry() {
.window-wrapper { display: flex; align-items: center; flex-direction: column; }
.body { width: 100%; padding: 10px 18px 16px; overflow-y: auto; }
h3 { margin: 0 0 12px; font-family: MrEavesRemake; }
.sync-note { margin: -8px 0 12px; font-size: 12px; opacity: 0.72; }
form { display: flex; flex-direction: column; gap: 10px; }
.form-field { min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

View File

@@ -27,10 +27,11 @@
}
},
"sidebar-label": "Campanya",
"synced": "Sincronitzat",
"sections": { "notes": "Notes", "actors": "Actors i personatges", "items": "Objectes" },
"actions": {
"new-note": "Nota nova", "new-folder": "Carpeta nova", "refresh": "Actualitza",
"create": "Crea {section}", "submit": "Crea", "delete": "Suprimeix", "saving": "Desant...",
"create": "Crea {section}", "submit": "Crea", "edit": "Edita", "save": "Desa", "delete": "Suprimeix", "saving": "Desant...",
"collapse-sidebar": "Redueix la barra lateral", "expand-sidebar": "Expandeix la barra lateral"
},
"states": {
@@ -47,7 +48,8 @@
"types": { "character": "Personatge", "npc": "PNJ", "creature": "Criatura" }
},
"item": {
"new": "Objecte nou", "category": "Categoria", "rarity": "Raresa", "quantity": "Quantitat",
"new": "Objecte nou", "edit": "Edita l'objecte", "foundry-sync-note": "Els canvis en aquest objecte també s'apliquen al món del Foundry vinculat.",
"category": "Categoria", "rarity": "Raresa", "quantity": "Quantitat",
"quantity-short": "Quant.", "weight": "Pes (lb)", "properties": "Propietats", "properties-placeholder": "Per exemple, versàtil, subtil",
"categories": {
"weapon": "Arma", "armor": "Armadura", "shield": "Escut", "adventuring-gear": "Equip d'aventura",

View File

@@ -1,6 +1,8 @@
{
"errors": {
"link-expired": "El codi d'enllaç de Foundry no és vàlid, ha caducat o ja s'ha utilitzat.",
"world-already-linked": "Aquest món de Foundry ja està enllaçat amb una altra campanya."
"world-already-linked": "Aquest món de Foundry ja està enllaçat amb una altra campanya.",
"actor-already-synced": "Un altre actor d'aquesta campanya ja està sincronitzat amb aquell actor del Foundry.",
"item-already-synced": "Un altre objecte d'aquesta campanya ja està sincronitzat amb aquell objecte del Foundry."
}
}

View File

@@ -31,10 +31,11 @@
}
},
"sidebar-label": "Campaign",
"synced": "Synced",
"sections": { "notes": "Notes", "actors": "Actors & Characters", "items": "Items" },
"actions": {
"new-note": "New note", "new-folder": "New folder", "refresh": "Refresh",
"create": "Create {section}", "submit": "Create", "delete": "Delete", "saving": "Saving...",
"create": "Create {section}", "submit": "Create", "edit": "Edit", "save": "Save", "delete": "Delete", "saving": "Saving...",
"collapse-sidebar": "Collapse sidebar", "expand-sidebar": "Expand sidebar"
},
"states": {
@@ -51,7 +52,8 @@
"types": { "character": "Character", "npc": "NPC", "creature": "Creature" }
},
"item": {
"new": "New item", "category": "Category", "rarity": "Rarity", "quantity": "Quantity",
"new": "New item", "edit": "Edit item", "foundry-sync-note": "Changes to this item are also applied in the linked Foundry world.",
"category": "Category", "rarity": "Rarity", "quantity": "Quantity",
"quantity-short": "Qty", "weight": "Weight (lb)", "properties": "Properties", "properties-placeholder": "For example, versatile, finesse",
"categories": {
"weapon": "Weapon", "armor": "Armor", "shield": "Shield", "adventuring-gear": "Adventuring gear",

View File

@@ -1,6 +1,8 @@
{
"errors": {
"link-expired": "This Foundry pairing code is invalid, expired, or already used.",
"world-already-linked": "This Foundry world is already linked to another campaign."
"world-already-linked": "This Foundry world is already linked to another campaign.",
"actor-already-synced": "Another actor in this campaign is already synced with that Foundry actor.",
"item-already-synced": "Another item in this campaign is already synced with that Foundry item."
}
}

View File

@@ -27,10 +27,11 @@
}
},
"sidebar-label": "Campaña",
"synced": "Sincronizado",
"sections": { "notes": "Notas", "actors": "Actores y personajes", "items": "Objetos" },
"actions": {
"new-note": "Nueva nota", "new-folder": "Nueva carpeta", "refresh": "Actualizar",
"create": "Crear {section}", "submit": "Crear", "delete": "Eliminar", "saving": "Guardando...",
"create": "Crear {section}", "submit": "Crear", "edit": "Editar", "save": "Guardar", "delete": "Eliminar", "saving": "Guardando...",
"collapse-sidebar": "Contraer barra lateral", "expand-sidebar": "Expandir barra lateral"
},
"states": {
@@ -47,7 +48,8 @@
"types": { "character": "Personaje", "npc": "PNJ", "creature": "Criatura" }
},
"item": {
"new": "Nuevo objeto", "category": "Categoría", "rarity": "Rareza", "quantity": "Cantidad",
"new": "Nuevo objeto", "edit": "Editar objeto", "foundry-sync-note": "Los cambios en este objeto también se aplican al mundo de Foundry vinculado.",
"category": "Categoría", "rarity": "Rareza", "quantity": "Cantidad",
"quantity-short": "Cant.", "weight": "Peso (lb)", "properties": "Propiedades", "properties-placeholder": "Por ejemplo, versátil, sutil",
"categories": {
"weapon": "Arma", "armor": "Armadura", "shield": "Escudo", "adventuring-gear": "Equipo de aventura",

View File

@@ -1,6 +1,8 @@
{
"errors": {
"link-expired": "El código de vinculación de Foundry no es válido, ha caducado o ya se ha usado.",
"world-already-linked": "Este mundo de Foundry ya está vinculado a otra campaña."
"world-already-linked": "Este mundo de Foundry ya está vinculado a otra campaña.",
"actor-already-synced": "Otro actor de esta campaña ya está sincronizado con ese actor de Foundry.",
"item-already-synced": "Otro objeto de esta campaña ya está sincronizado con ese objeto de Foundry."
}
}