Traits and items are mixed up #89
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
On the character sheet, icons are not loaded and traits and items all are displayed there. Can you fix it?
Let me also check the Discord bot's character display, since the sheet fields are shown there too.
The route looks fine. Let me run the existing test suite to see the current state of things.
I have a full picture now. Let me check which tests load
foundry-link.jsso my change doesn't break their require stubs.Let me check what the frontend Campaign service holds — whether campaign settings (foundryUrl) are available to windows.
I now have the full picture. The root causes are clear:
backend/src/services/actor-foundry.jsbuilds a character'sinventoryfrom every embedded item except class/subclass/background/spell — so Foundryfeatitems (the character's traits, also rendered into the traits tab) andraceitems (its species) show up in the inventory list among actual gear.item-foundry.jsalready knows these types are not gear but never shared that.icons/...), which the sheet then resolves against/api/publicand 404s. The campaign keeps the world address (settings.integrations.foundryUrl) which the icon picker already uses exactly for this.syncedItemand would no longer be retained by inventory) — so the module must stop claiming world-owned documents.Let me implement. First, the backend services:
Now the writers in
foundry-link.js— resolve relative Foundry asset paths against the campaign's world address:Now the Foundry module side — Dragonroll must stop claiming (and thus deleting) the world's trait and species documents:
Now update the two test harnesses that compile
foundry-link.js, which must now stub the newfoundry-iconsdependency:Now the new test file for this issue:
Now let me run the full suite and check anything that trips:
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:All 339 tests pass. Let me double-check the docs describe the inventory consistently with the fixed behavior:
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 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
lootitems 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:That edit was a mistake — let me check what it did and repair:
All 340 tests pass. Final check of the module edit in context:
Done. Here's a summary of the fix for #89.
Root causes
Traits and items mixed up.
backend/src/services/actor-foundry.jsbuilt 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.jsalready 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 anisFoundryGearTypepredicate over the existing non-gear type set.backend/src/services/actor-foundry.js— inventory now keeps gear only; feats stay intraits, the race item inspecies.backend/src/routes/foundry-link.js—saveFoundryActorandsaveFoundryItemread relative world image paths (actor portrait, inventory icons, item icon incl.foundryImage) against the campaign's world address (settings.integrations.foundryUrl) via the existingjoinFoundryAssetUrlhelper, 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 marksfeat/race/species/status/spellbook/languageembedded 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 alootduplicate 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 reachtraits; 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 thefoundry-iconsstub to the two existing harnesses that compilefoundry-link.js.npm test: 340/340 pass (330 before + 10 new). No commits made — leaving that to the automation.Implementation is ready for review: #92