ItemID
Lightweight value type that uniquely identifies an item by combining a type ID and variant ID. Provides value equality, implicit conversions, and serves as the primary key for item lookups in the ItemDatabase.
Definition
Namespace: Paragon.Townskeep.ItemSystem Assembly: Townskeep.dll
[Serializable]
public struct ItemID : IEquatable<ItemID>Implements: IEquatable<ItemID>
Remarks
ItemID encodes two dimensions of item identity:
TypeID — identifies the item type (e.g., "Iron Sword" = 1, "Health Potion" = 2). This maps to the factory's hash code /
ItemData.ItemID.VariantID — identifies a specific variant within the type (e.g., variant 0 = base, variant 1 = enchanted). Defaults to
0.
The struct supports implicit conversions to/from int (TypeID only) and (int, int) tuples (TypeID + VariantID), making it ergonomic for both simple lookups and variant-aware code.
Quick Lookup
Create from type only
ItemID id = 5; or new ItemID(5)
Create with variant
new ItemID(5, 2) or ItemID id = (5, 2);
Get invalid sentinel
ItemID.Invalid (TypeID=-1, VariantID=-1)
Check equality
id1 == id2
Get type as int
int type = itemId; (implicit)
Decompose to tuple
(int type, int variant) = itemId; (implicit)
Display
itemId.ToString() → "(5:2)"
Fields
TypeID
The item type identifier. Readonly.
VariantID
The variant identifier within the item type. Readonly. Defaults to 0.
Methods
Constructor
typeID
int
The item type identifier
variantID
int
The variant identifier (default: 0)
Equals
Value equality comparing both TypeID and VariantID.
GetHashCode
Combines TypeID and VariantID via HashCode.Combine.
ToString
Returns "(TypeID:VariantID)" format.
Example: new ItemID(3, 1).ToString() → "(3:1)"
Statics
Invalid
Sentinel value representing an invalid or unset item ID. Both TypeID and VariantID are -1.
Operators
Equality
Compares both TypeID and VariantID.
Implicit Conversions
ItemID
(int, int)
(TypeID, VariantID)
ItemID
int
TypeID only
(int, int)
ItemID
(TypeID, VariantID)
int
ItemID
TypeID, VariantID defaults to 0
Common Pitfalls
Implicit int conversion loses VariantID int type = itemId; only extracts TypeID. The VariantID is silently discarded. If you need both, use the tuple conversion: (int type, int variant) = itemId;
Invalid uses -1, not 0 ItemID.Invalid uses -1 for both fields. A default-constructed ItemID (via default(ItemID)) has TypeID=0, VariantID=0, which is a valid ID — not the same as Invalid.
Examples
Looking Up an Item
Comparing Items
See Also
ItemData — data record containing the raw
ItemIDandVariantIDfieldsItemDatabase — registry using ItemID for factory lookups
ItemFactory — factory that produces items
Last updated