Traits and items are mixed up #89

Closed
opened 2026-10-15 20:59:45 +00:00 by Syndria98 · 18 comments
Owner

On the character sheet, icons are not loaded and traits and items all are displayed there. Can you fix it?

On the character sheet, icons are not loaded and traits and items all are displayed there. Can you fix it?
Syndria98 added the ai-ready label 2026-10-15 20:59:45 +00:00
Agent added the working label 2026-10-15 20:59:45 +00:00
Collaborator

Let me also check the Discord bot's character display, since the sheet fields are shown there too.

Let me also check the Discord bot's character display, since the sheet fields are shown there too.
Collaborator

The route looks fine. Let me run the existing test suite to see the current state of things.

The route looks fine. Let me run the existing test suite to see the current state of things.
Collaborator

I have a full picture now. Let me check which tests load foundry-link.js so my change doesn't break their require stubs.

I have a full picture now. Let me check which tests load `foundry-link.js` so my change doesn't break their require stubs.
Collaborator

Let me check what the frontend Campaign service holds — whether campaign settings (foundryUrl) are available to windows.

Let me check what the frontend Campaign service holds — whether campaign settings (foundryUrl) are available to windows.
Collaborator

I now have the full picture. The root causes are clear:

  1. backend/src/services/actor-foundry.js builds a character's inventory from every embedded item except class/subclass/background/spell — so Foundry feat items (the character's traits, also rendered into the traits tab) and race items (its species) show up in the inventory list among actual gear. item-foundry.js already knows these types are not gear but never shared that.
  2. Icons: the writers store Foundry image paths as they arrive — the bridge snapshot and older modules send relative paths (icons/...), which the sheet then resolves against /api/public and 404s. The campaign keeps the world address (settings.integrations.foundryUrl) which the icon picker already uses exactly for this.
  3. If I only fix the mapper, the Foundry module would delete the world's trait/species embedded items on the next character apply (they're all marked syncedItem and would no longer be retained by inventory) — so the module must stop claiming world-owned documents.

Let me implement. First, the backend services:

I now have the full picture. The root causes are clear: 1. **`backend/src/services/actor-foundry.js`** builds a character's `inventory` from every embedded item except class/subclass/background/spell — so Foundry `feat` items (the character's *traits*, also rendered into the traits tab) and `race` items (its species) show up in the inventory list among actual gear. `item-foundry.js` already knows these types are not gear but never shared that. 2. Icons: the writers store Foundry image paths as they arrive — the bridge snapshot and older modules send relative paths (`icons/...`), which the sheet then resolves against `/api/public` and 404s. The campaign keeps the world address (`settings.integrations.foundryUrl`) which the icon picker already uses exactly for this. 3. If I only fix the mapper, the Foundry module would *delete* the world's trait/species embedded items on the next character apply (they're all marked `syncedItem` and would no longer be retained by inventory) — so the module must stop claiming world-owned documents. Let me implement. First, the backend services:
Collaborator

Now the writers in foundry-link.js — resolve relative Foundry asset paths against the campaign's world address:

Now the writers in `foundry-link.js` — resolve relative Foundry asset paths against the campaign's world address:
Collaborator

Now the Foundry module side — Dragonroll must stop claiming (and thus deleting) the world's trait and species documents:

Now the Foundry module side — Dragonroll must stop claiming (and thus deleting) the world's trait and species documents:
Collaborator

Now update the two test harnesses that compile foundry-link.js, which must now stub the new foundry-icons dependency:

Now update the two test harnesses that compile `foundry-link.js`, which must now stub the new `foundry-icons` dependency:
Collaborator

Now the new test file for this issue:

Now the new test file for this issue:
Collaborator

Now let me run the full suite and check anything that trips:

Now let me run the full suite and check anything that trips:
Collaborator

The service encodes raw Foundry paths (which hold real spaces, not pre-encoded %20). Fixing the fixture to use a raw path like Foundry actually stores:

The service encodes raw Foundry paths (which hold real spaces, not pre-encoded `%20`). Fixing the fixture to use a raw path like Foundry actually stores:
Collaborator

All 339 tests pass. Let me double-check the docs describe the inventory consistently with the fixed behavior:

All 339 tests pass. Let me double-check the docs describe the inventory consistently with the fixed behavior:
Collaborator

The docs already say the inventory holds only "what it carries" — the fix aligns the code with that. Let me review the complete diff:

The docs already say the inventory holds only "what it carries" — the fix aligns the code with that. Let me review the complete diff:
Collaborator

The diff is solid, but there's one legacy data path I want to close: campaigns that synced before this fix still hold trait rows in their inventory, and the module would now create duplicate loot items in the world named after those traits. Let me make the module treat such a row as standing for the world's own document — neither cloning it nor touching the document:

The diff is solid, but there's one legacy data path I want to close: campaigns that synced before this fix still hold trait rows in their inventory, and the module would now create duplicate `loot` items in the world named after those traits. Let me make the module treat such a row as standing for the world's own document — neither cloning it nor touching the document:
Collaborator

That edit was a mistake — let me check what it did and repair:

That edit was a mistake — let me check what it did and repair:
Collaborator

All 340 tests pass. Final check of the module edit in context:

All 340 tests pass. Final check of the module edit in context:
Collaborator

Done. Here's a summary of the fix for #89.

Root causes

Traits and items mixed up. backend/src/services/actor-foundry.js built a character's inventory from every Foundry embedded item except class/subclass/background/spell — so a synced character's feat items (its traits) and race item (its species) stood as rows in the Inventory tab right beside real gear, even though the sheet already shows traits in the Traits tab and species on the identity line. services/item-foundry.js already knew which Foundry types are not gear, but never shared that with the actor mapper.

Icons not loaded. The sync writers stored Foundry image paths exactly as they arrived. The live module sends absolute URLs, but the bridge snapshot (and older modules) carry Foundry-relative paths like icons/... — the sheet then resolved those against /api/public/… (Dragonroll's upload folder), where nothing of that name exists, so nothing loaded.

Changes

  • backend/src/services/item-foundry.js — export an isFoundryGearType predicate over the existing non-gear type set.
  • backend/src/services/actor-foundry.js — inventory now keeps gear only; feats stay in traits, the race item in species.
  • backend/src/routes/foundry-link.js — saveFoundryActor and saveFoundryItem read relative world image paths (actor portrait, inventory icons, item icon incl. foundryImage) against the campaign's world address (settings.integrations.foundryUrl) via the existing joinFoundryAssetUrl helper, the same way the icon window already loads world icons; absolute URLs and campaigns without a world address travel untouched.
  • dragonroll-foundry/scripts/api.js — the counterpart, without which the fix would have deleted the world's traits: the module no longer marks feat/race/species/status/spellbook/language embedded documents as its own (markActorItemsAsSynced), never deletes them when applying a campaign character (reconcileEmbeddedItems — this also fixes applying a character deleting the world's species item), won't write gear fields onto them, and a trait row left in an older campaign's inventory no longer spawns a loot duplicate named after it. Actor snapshots still send feats, since the traits text is read off them.

Tests

Added tests/character-sheet-traits-items.test.js (10 tests): mapper keeps inventory to gear while feats reach traits; writers resolve relative paths to the world URL (and leave absolute URLs / missing world addresses alone); module keeps trait/species documents, only marks gear as synced, still sends feats in snapshots, and doesn't duplicate old leaked rows. Also added the foundry-icons stub to the two existing harnesses that compile foundry-link.js.

npm test: 340/340 pass (330 before + 10 new). No commits made — leaving that to the automation.

Done. Here's a summary of the fix for #89. ## Root causes **Traits and items mixed up.** `backend/src/services/actor-foundry.js` built a character's inventory from *every* Foundry embedded item except class/subclass/background/spell — so a synced character's **feat items (its traits)** and **race item (its species)** stood as rows in the Inventory tab right beside real gear, even though the sheet already shows traits in the Traits tab and species on the identity line. `services/item-foundry.js` already knew which Foundry types are not gear, but never shared that with the actor mapper. **Icons not loaded.** The sync writers stored Foundry image paths exactly as they arrived. The live module sends absolute URLs, but the bridge snapshot (and older modules) carry Foundry-relative paths like `icons/...` — the sheet then resolved those against `/api/public/…` (Dragonroll's upload folder), where nothing of that name exists, so nothing loaded. ## Changes - `backend/src/services/item-foundry.js` — export an `isFoundryGearType` predicate over the existing non-gear type set. - `backend/src/services/actor-foundry.js` — inventory now keeps gear only; feats stay in `traits`, the race item in `species`. - `backend/src/routes/foundry-link.js` — `saveFoundryActor` and `saveFoundryItem` read relative world image paths (actor portrait, inventory icons, item icon incl. `foundryImage`) against the campaign's world address (`settings.integrations.foundryUrl`) via the existing `joinFoundryAssetUrl` helper, the same way the icon window already loads world icons; absolute URLs and campaigns without a world address travel untouched. - `dragonroll-foundry/scripts/api.js` — the counterpart, without which the fix would have deleted the world's traits: the module no longer marks `feat`/`race`/`species`/`status`/`spellbook`/`language` embedded documents as its own (`markActorItemsAsSynced`), never deletes them when applying a campaign character (`reconcileEmbeddedItems` — this also fixes applying a character deleting the world's species item), won't write gear fields onto them, and a trait row left in an older campaign's inventory no longer spawns a `loot` duplicate named after it. Actor snapshots still send feats, since the traits text is read off them. ## Tests Added `tests/character-sheet-traits-items.test.js` (10 tests): mapper keeps inventory to gear while feats reach `traits`; writers resolve relative paths to the world URL (and leave absolute URLs / missing world addresses alone); module keeps trait/species documents, only marks gear as synced, still sends feats in snapshots, and doesn't duplicate old leaked rows. Also added the `foundry-icons` stub to the two existing harnesses that compile `foundry-link.js`. `npm test`: **340/340 pass** (330 before + 10 new). No commits made — leaving that to the automation.
Collaborator

Implementation is ready for review: #92

Implementation is ready for review: https://git.aranroig.com/Syndria98/dragonroll/pulls/92
Agent added help wanted and removed working labels 2026-10-15 21:36:45 +00:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Syndria98/dragonroll#89