Workes.InventorySystem
3.0.0
dotnet add package Workes.InventorySystem --version 3.0.0
NuGet\Install-Package Workes.InventorySystem -Version 3.0.0
<PackageReference Include="Workes.InventorySystem" Version="3.0.0" />
<PackageVersion Include="Workes.InventorySystem" Version="3.0.0" />
<PackageReference Include="Workes.InventorySystem" />
paket add Workes.InventorySystem --version 3.0.0
#r "nuget: Workes.InventorySystem, 3.0.0"
#:package Workes.InventorySystem@3.0.0
#addin nuget:?package=Workes.InventorySystem&version=3.0.0
#tool nuget:?package=Workes.InventorySystem&version=3.0.0
Workes.InventorySystem
Workes.InventorySystem is a reusable .NET inventory library for games and other applications that need structured item
ownership. It is not tied to one genre, UI, container shape, or persistence format.
The package separates item identity, inventory contents, stacking, capacity, rules, placement, transactions, events, and persistence so each concern can be configured or extended without replacing the rest of the system.
Highlights
- Catalog-registered item definitions with stable IDs, tags, typed attributes, schemas, and ID migrations.
- Configurable stack resolvers, capacity policies, and inventory rules.
- Entry, slot, grid, multi-cell grid, equipment, and sectioned layouts.
- Direct placement, automatic placement, movement, swapping, sorting, and repacking.
- Atomic local and cross-inventory transactions, bulk transformations, and swaps.
- Per-instance metadata with inventory-owned validation and events.
- Structured change events for gameplay, auditing, and incremental UI synchronization.
- Portable, serializer-friendly snapshots with exact restoration, reconciliation, and salvage workflows.
- Extension contracts for definitions, policies, rules, layouts, footprints, sorting, and persistence codecs.
Installation
Install the package from NuGet:
dotnet add package Workes.InventorySystem --version 3.0.0
Or add a package reference:
<PackageReference Include="Workes.InventorySystem" Version="3.0.0" />
The package targets .NET Standard 2.1.
Quick Example
Create a catalog, register the canonical item definitions, freeze the catalog, and use an inventory created by a manager:
using System;
using Workes.InventorySystem.Capacity;
using Workes.InventorySystem.Core;
using Workes.InventorySystem.Layout;
using Workes.InventorySystem.Stacking;
var catalog = new ItemCatalog<string>();
var apple = new ItemDefinition<string>("apple");
var coin = new ItemDefinition<string>("coin");
catalog.Registry.Register(apple);
catalog.Registry.Register(coin);
catalog.Freeze();
var manager = new InventoryManager<string>(
new FixedSizeStackResolver<string>(maxStack: 10),
new UnlimitedCapacityPolicy<string>(),
new EntryLayout<string>(),
catalog);
var inventory = manager.CreateInventory();
inventory.Add("apple", amount: 5);
inventory.Add("coin", amount: 25);
Console.WriteLine(inventory.Count("apple")); // 5
Console.WriteLine(inventory.Find("coin").Count); // 3 stacks: 10, 10, 5
Use throwing methods such as Add(...) when success is expected. Use their Try... counterparts when rejection is a
normal application branch; rejected operations leave the inventory unchanged and report an InventoryFailure with a
stable Kind, stable Code, and human-readable Message.
See the Quick Start for the complete first-use walkthrough.
Mental Model
| Component | Responsibility |
|---|---|
ItemCatalog<TKey> |
Owns the valid item universe and canonical definitions. |
InventoryManager<TKey> |
Combines a catalog with defaults used to create related inventories. |
Inventory<TKey> |
Owns runtime item stacks and coordinates validated mutation. |
| Stack resolver | Determines the maximum size of compatible stacks. |
| Capacity policy | Validates shared limits such as total quantity or weight. |
| Rules | Enforce semantic constraints for one inventory. |
| Layout | Owns placement and presentation without owning the items themselves. |
Two rules prevent many integration mistakes:
- Reuse the exact definition objects registered in the catalog. A detached definition with the same ID is not the canonical definition.
- Treat
Inventory.Itemsas ownership and storage order, not UI order. Query the active layout for visible placement.
Built-In Placement Models
| Layout | Typical use |
|---|---|
EntryLayout<TKey> |
Lists, bags, and collections without stable empty positions. |
SlotLayout<TKey> |
Hotbars and fixed-size containers. |
GridLayout<TKey> |
Single-cell items on a two-dimensional grid. |
MultiCellGridLayout<TKey> |
Rectangular item footprints, anchors, and packing. |
EquipmentLayout<TKey> |
Named positions with definition or tag restrictions. |
SectionedLayout<TKey> |
Multiple named slot groups with independent restrictions. |
Layouts own contexts, placement, sorting, and repacking. Inventory remains responsible for item lifetime, validation,
atomic commit, events, and application-facing layout queries such as GetItemAt(context).
Documentation
Start here:
Focused guides:
- Catalogs And Definitions
- Layouts
- Policies And Rules
- Transactions
- Events And UI Integration
- Failure Handling
- Persistence
- Extending The Inventory System
See the Changelog for release history and migration-sensitive changes.
The repository also contains executable examples covering item setup, layouts, transfers, policies, events, metadata, and other common workflows. Use them when you find the documentation to be lacking examples.
Persistence Boundaries
CaptureSnapshot() returns a non-generic, deeply detached object model suitable for ordinary serializers. The package
owns inventory snapshot semantics, validation, and restoration; your application chooses JSON, MessagePack, another
serializer, and its own file or database workflow.
The package does not own save slots, compression, encryption, application-envelope versioning, or file I/O. Use the portable snapshot APIs for package-owned persistence; the old generic compatibility serializer API was removed in 3.0.
License
Workes.InventorySystem is available under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
3.0.0 makes transactions the central local and cross-inventory operation model; adds reusable item deltas and label-based application plans; standardizes item metadata matching; removes 2.0 compatibility serializer/event aliases; and keeps external transfer builders as obsolete compatibility APIs.