diff --git a/AGENTS.md b/AGENTS.md index 79200fd4..904f1610 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -28,6 +28,7 @@ CI (`.gitea/workflows/deploy.yml`) builds two Docker images on every push to `ma dragonroll/ ├── backend/ Express API (CommonJS, entry: src/index.js) ├── frontend/ Nuxt 4 app (entry: app/app.vue) +├── obsidian-plugin/ Plain JavaScript Obsidian plugin for campaign note import/push ├── docker-compose.yml nginx :3000 -> frontend :3000, /api -> backend :5000 ├── nginx.conf reverse proxy rules for the compose stack ├── ecosystem.config.js PM2 config (stale: runs `npm start`, which does not exist — see §9) @@ -189,7 +190,8 @@ Fetch the file from `/api/public/`. `GET /api/campaign/list` → `{status:'ok',campaigns}` `GET /api/campaign/retrieve/:id` → `{status:'ok',campaign}` (401 when no `req.user.id`) -`GET /api/note/list?campaign=` → `{status:'ok', folders, notes}` — notes with `folder: null` (roots) +`GET /api/note/list?campaign=` → `{status:'ok', folders, notes}` — notes with `folder: null` (roots); +folder entries include `parentFolder` so clients can rebuild nested folder paths `GET /api/note/subfolder/list?campaign=&folder=` → `{status:'ok', subfolders, notes}` `POST /api/note/create` — `{title*,content,campaign*,folder?}` (folder validated against campaign) `POST /api/note/update` — `{id*, title?, content?, folder?, color?}` — partial, ownership checked @@ -290,7 +292,7 @@ frontend/ │ │ VersionRender │ ├── layouts/ IconButton, Dropdown, Tabs, ColorPicker (reusable UI atoms) │ └── viewer/ TopBar, statusbar/{StatusBar,FetchStatus}, topbar/{TopSearchBar,SearchResult}, - │ content/{Content,NoteContainer,Note}, widgets/{TableWidget,TestWidget, + │ content/{Content,NoteContainer,Note}, map/MapViewerPane, widgets/{TableWidget,TestWidget, │ inline/RollWidgetInline,display/RollWidgetDisplay} ├── composables/ useTheme.ts (theme+accent singletons, localStorage, data-* attrs), │ useEmitter.ts (BROKEN, see §9) @@ -304,7 +306,10 @@ There is no `app/pages/`. `app/app.vue` renders a fixed shell of managers. "Scre - **Windows** — floating, draggable/resizable overlays (login, main menu, settings…), or - **Content** — the campaign workspace (`TopBar` + `ContentSidebar` + note column + `StatusBar`), - shown when `Campaign` state is non-null. + shown when `Campaign` state is non-null. The note column shows the open notes, or the map anchored + on it (`AnchorMap` / `ActivePane` in `services/Content.js`); the sidebar's notes and maps buttons + switch between the two while both keep their state, and `viewer/map/MapViewerPane.vue` renders the + map there and inside the `map_viewer` window (a detached anchored map). Boot sequence (`app.vue` → `start()`): @@ -367,7 +372,7 @@ Plain modules with module-scope `ref()`s imported directly. No DI, no Pinia. Sin | `Server.js` | axios instance (fallback baseURL `http://localhost:5000/api`), `initApi(baseURL)` called by `plugins/api.ts`, request interceptor adding `Authorization: Bearer `, `getBaseUrl()`. Default export is a factory: call `Server()` then `.get/.post`. | | `User.js` | `UserStatus` ref, `GetUser()` (decodes JWT, auto-logout on `exp`), `SetUser(token)`, `LoadUser`, `LogoutUser`, `IsAdmin`, `HasAdmin()`, `GetUserSetting(key)` / `SetUserSetting(key,value)` (server-backed, in `User.settings`) | | `Campaign.js` | `useCampaignService()` → `Campaign` (`useState('campaign')`), `SetCampaign(data)` (also writes `localStorage.selectedCampaignId`), `RestoreCampaign()` | -| `Content.js` | `ShowContent` ref (drives the campaign workspace). `SetShowContent` is exported but unused — `ContentManager.vue` sets it from a `watch(Campaign)` and never turns it back off | +| `Content.js` | `ShowContent` ref (drives the campaign workspace: `ContentManager.vue` turns it on from a `watch(Campaign)`, `TopBar` off when leaving a campaign) and the anchored map: `ActivePane` (`'notes'`\|`'map'`), `AnchoredMap`, `SetActivePane`, `AnchorMap`, `ClearAnchoredMap` | | `Emitter.js` | `export const emitter = mitt()` — the app-wide event bus | | `Toaster.js` | `DisplayToast(color, text, duration)` → emits `toast`; `ToastManager.vue` renders it | | `Tooltip.js` | `SetupTooltip()`, `AddTooltip(el, text, {max_width})` (stores on `el._dr_tooltip`), polled visibility via `elementsFromPoint` | @@ -477,6 +482,23 @@ script; `WindowDefinitions` stores raw keys (`title: 'windows.login'`) and `Wind configured (`nuxt.config.ts`, `langDir: 'locales/'`, `vueI18n: './i18n.config.ts'`) but its locale files (`locales/en.json` etc.) are empty `{}` — the custom plugin is what components actually consume. +### 5.9 Obsidian plugin + +`obsidian-plugin/` is a plain JavaScript community plugin; copy `main.js` and `manifest.json` into +`/.obsidian/plugins/dragonroll-sync/` (details in its README). It signs in through +`POST /api/user/login`, saves the 48-hour JWT token in plugin data, and does not save the password. +The user selects a campaign from `GET /api/campaign/list`. + +- **Import or refresh campaign notes** reads `/api/note/list` plus `/api/note/subfolder/list` and + creates/updates Markdown files under `Dragonroll//`, preserving Dragonroll's folder tree. +- **Push active note to Dragonroll** creates a root campaign note or updates the note linked in its + frontmatter. +- `dragonrollId`, `dragonrollCampaign`, and `dragonrollTitle` frontmatter properties link imported + notes. They are omitted from content sent to Dragonroll. Per-note signatures detect local edits; + imports preserve modified local files, and push is explicit. + +The plugin uses Obsidian's `requestUrl` helper, so the request path does not depend on browser CORS. + ## 6. Conventions - **Backend**: CommonJS `require`/`module.exports`; files in `services/` are shared infra, `routes/` diff --git a/README.md b/README.md index cfac0933..a765cba5 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Dragonroll is an open source connector for role-playing games. - Play music during physical campaings - Plan different encounters - Manage different items and spells +- Import and edit campaign notes in Obsidian with the [Dragonroll Sync plugin](obsidian-plugin/README.md) - And so much more! ## Installation 🛠️ @@ -55,7 +56,6 @@ if you want to start the development environments - Dragonroll <-> Foundry integration - Dragonroll <-> Discord Bot integration -- Dragonroll <-> Obsidian integration What to sync: diff --git a/backend/src/routes/note.js b/backend/src/routes/note.js index 5bfd6e4b..8d11792e 100644 --- a/backend/src/routes/note.js +++ b/backend/src/routes/note.js @@ -19,7 +19,7 @@ router.get('/list', async (req, res) => { if (!hasAccess) return res.json({ status: 'error', msg: 'unauthorized' }); const folders = await Folder.find({ campaign }) - .select('_id name date color') + .select('_id name parentFolder date color') .sort({ date: -1 }) .lean(); diff --git a/frontend/app/components/partials/ContentSidebar.vue b/frontend/app/components/partials/ContentSidebar.vue index f163f7fe..281ce0b9 100644 --- a/frontend/app/components/partials/ContentSidebar.vue +++ b/frontend/app/components/partials/ContentSidebar.vue @@ -3,6 +3,7 @@ import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue' import { useI18n } from 'vue-i18n'; import { useCampaignService } from '~/services/Campaign.js'; +import { AnchorMap, AnchoredMap, ClearAnchoredMap, SetActivePane } from '~/services/Content.js'; import { emitter } from '~/services/Emitter'; import Server from '~/services/Server'; import { ClearWindow, CreateWindow, GetFirstWindowId } from '~/services/Windows'; @@ -207,6 +208,9 @@ async function fetchCampaignEntries(entityType = activeSection.value, silent = f function selectSection(section) { activeSection.value = section; if (isEntrySection(section)) fetchCampaignEntries(section); + // The content area follows the sidebar: maps shows the anchored map, everything else the + // notes that are currently open. + SetActivePane(section === 'maps' && AnchoredMap.value ? 'map' : 'notes'); } function createEntry(entityType) { @@ -272,6 +276,7 @@ function showEntryMenu(entry, entityType) { const response = await Server().post(`/${entityType}/delete`, { id: entry._id }); if (response.data.status === 'ok' && list) { list.value = list.value.filter((current) => current._id !== entry._id); + if (entityType === 'map' && isAnchoredMap(entry)) ClearAnchoredMap(); } } catch (error) {} finally { HideContextMenu(); } } @@ -294,13 +299,17 @@ async function openCharacterSheet(actor) { CreateWindow('character_sheet', { actor }); } -async function openMapViewer(map) { - const existingWindowId = GetFirstWindowId('map_viewer'); - if (existingWindowId !== undefined) { - ClearWindow({ id: existingWindowId }); - await nextTick(); - } - CreateWindow('map_viewer', { map, campaign: campaignId.value }); +// Maps are anchored on the note container instead of opening a window: the notes that were open +// stay open, and the sidebar's notes/maps buttons switch between the two. +function openMapViewer(map) { + if (!map) return; + const floatingViewer = GetFirstWindowId('map_viewer'); + if (floatingViewer !== undefined) ClearWindow({ id: floatingViewer }); + AnchorMap(map); +} + +function isAnchoredMap(map) { + return AnchoredMap.value?._id === map._id; } function createNote() { @@ -324,6 +333,7 @@ watch(campaignId, (newVal) => { actors.value = []; items.value = []; maps.value = []; + ClearAnchoredMap(); fetchCampaignNotes(); if (isEntrySection(activeSection.value)) fetchCampaignEntries(activeSection.value); } else { @@ -334,6 +344,7 @@ watch(campaignId, (newVal) => { maps.value = []; notesError.value = ''; entriesError.value = ''; + ClearAnchoredMap(); } }); @@ -502,8 +513,11 @@ onBeforeUnmount(() => { -
- {{ map.name }} +
+ + {{ map.name }} + {{ t('campaigns.map.anchored') }} + {{ t('campaigns.map.no-image') }}
@@ -654,6 +668,8 @@ onBeforeUnmount(() => { } .entity-entry:hover { border-color: var(--color-border); background: var(--color-background-soft); } .entity-entry:focus-visible { outline: 1px solid var(--color-link); } +/* The map currently anchored on the note container. */ +.entity-entry.anchored { border-color: var(--color-link); background: var(--color-background-soft); } .entity-entry-name-row { display: flex; align-items: baseline; gap: 6px; } .entity-entry-name { font-weight: bold; } .entity-entry-sync { diff --git a/frontend/app/components/viewer/content/Content.vue b/frontend/app/components/viewer/content/Content.vue index 1de52c96..6e201d89 100644 --- a/frontend/app/components/viewer/content/Content.vue +++ b/frontend/app/components/viewer/content/Content.vue @@ -1,13 +1,30 @@ @@ -21,4 +38,14 @@ import NoteContainer from './NoteContainer.vue'; align-items: center; } - \ No newline at end of file +/* Hidden with v-show so the open notes stay mounted while the anchored map is displayed. */ +.anchored-map { + width: 100%; + height: 100%; + min-width: 0; + flex-grow: 1; + display: flex; + flex-direction: column; +} + + diff --git a/frontend/app/components/viewer/content/NoteContainer.vue b/frontend/app/components/viewer/content/NoteContainer.vue index 9ce4cb5e..dfdc261f 100644 --- a/frontend/app/components/viewer/content/NoteContainer.vue +++ b/frontend/app/components/viewer/content/NoteContainer.vue @@ -2,6 +2,7 @@ import { onMounted, onUnmounted, ref } from 'vue'; import Note from './Note.vue'; import { emitter } from '~/services/Emitter'; +import { SetActivePane } from '~/services/Content.js'; let noteData = ref([]); @@ -34,6 +35,9 @@ function pushNote(note){ } function handlePushNote(note) { + // A note opened from the sidebar or the search palette always comes to the front, even when + // the content area is showing an anchored map. + SetActivePane('notes'); pushNote(note); } diff --git a/frontend/app/components/viewer/map/MapViewerPane.vue b/frontend/app/components/viewer/map/MapViewerPane.vue new file mode 100644 index 00000000..f18cea8c --- /dev/null +++ b/frontend/app/components/viewer/map/MapViewerPane.vue @@ -0,0 +1,233 @@ + + + + + diff --git a/frontend/app/components/windows/CreateMapWindow.vue b/frontend/app/components/windows/CreateMapWindow.vue index e847096b..0f9002c2 100644 --- a/frontend/app/components/windows/CreateMapWindow.vue +++ b/frontend/app/components/windows/CreateMapWindow.vue @@ -129,7 +129,8 @@ async function saveMap() {