[FEAT] Slot-based Inventory container support#39
Conversation
|
I had a quick look at the failing CI run and it seems to be a real TypeScript strictness issue rather than a CI misconfiguration. The errors on src/utils/parser.ts (TS2532 and TS2322) point to the new parseInventorySlot logic, specifically inside the isSlotMultiplier branch where parts, sub and sub are used as if they were always present. I’ll take a deeper look at the overall slot‑based inventory design and tests over the weekend before merging, but I wanted to flag this TS issue first so we can get CI green again and merge. Regards, |
|
Fixed — added a type guard in the isSlotMultiplier loop to make sure the sub[] variables are not undefined in runtime. I have passed your CI build command, and tests are still green. CI should be green now. |

Closes #38
Summary
Add proper support for slot-based and container-based inventory, so items inside named slots are tracked as individual entries and reflected correctly in the Resources & Inventory dashboard.
Implementation
Two optional fields are added to
ParsedItem:slotParent?: string— the name of the container this item belongs to, if anyisContainer: boolean— whether this entry is a container rather than a regular itemAll slot logic is isolated in two new private methods —
parseInventorySlotandupsertSlotContainer— so it is easy to locate, review, and extend independently of the rest ofparseInventory.When the parser encounters a tag whose name matches the pattern
Word N(e.g.Slot 1,Backpack 2,Hand1), it treats it as a container and extracts its contents:Regular items and deltas work exactly as before:
Container mutation syntax is also supported:
Properties on slot items are also supported:
The unicode arrow
→is normalized to->before processing quantities. Section 1.2 of the Resource Tracking Add-On manual uses it in examples such as[Inv:Torch|3→2]— whether intentional or a typo, users will copy and paste from the manual and should not be penalized for it.Changes
src/utils/parser.ts—ParsedItemextended withslotParentandisContainer;parseInventorySlotandupsertSlotContaineradded; unicode arrow normalization in quantitiessrc/ui/resource-view.ts— inventory grid now classifies items into containers, children, and loose items; containers render as labeled sections with their items inside;renderItemCardextracted as a private methodstyles.css— added.ll-slot-section,.ll-slot-header,.ll-slot-name,.ll-slot-emptytests/parser.test.ts— 20 new tests covering slot containers, sub-items, deltas, mutations, and propertiesCurrent Limitations
Item name uniqueness
The inventory map uses the item name as its key. If two containers hold items with the same name, only the first entry is kept:
The manual already addresses this by recommending unique item names —
Sword (main)vsSword (off)— or using slot notation where the slot ID provides the disambiguation naturally. No changes to the data model are needed for this case; it is a player-side naming convention.Additional Context
I also found this in the manual's Q&A section:
This PR follows exactly that second approach — tracking containers and contents separately, with the slot name as the linking key. The descriptive nesting pattern (
contains: ...) is left untouched and treated as freeform properties, as intended.[Inv:Quiver|1|Arrow×15]and[Inv:Adventuring Kit|1|contains: rope, pitons, torch×2, rations×3]are intentionally out of scope. They represent a different pattern (item-as-container) that requires a design decision from the author. Should the notation evolve to something like[Inv:Quiver 1|Arrow×15], it would be handled naturally by this implementation without further changes.It is my understanding that this follows the spirit of the Lonelog Addon Guidelines:
Screenshots