Inventory Data structures
The page describes the different data structures used to load and manage inventory for the game. While developing a game you, most likely, will not have to deal with these data structures directly but knowing what they mean will allow you to configure the inventory system effectively.
Primary Data Structures
An inventory is described by several data structures. These data structures are generic enough to represent inventories used in many different types of games.
InventoryItemType: Describes the type of an inventory item. This data structure contains information such as what assets are used to visually represent this inventory item, its weight, its size and other attributes.
InventoryItemConfig: Contains the type and state information about an inventory item.
InventoryItem: Represents an individual inventory item in the game and contains state information about the item such as its location, whether it has been collected by the player and so on. It contains references to an InventoryItemConfig and an InventoryDecoratorConfig object.
Inventory: Contains the name of the inventory and a list of InventoryItem objects. An object of this type is used to represent the player's inventory or the game level inventory.
ItemDecoratorConfig: Describes how the items of a given type are decorated in the scene. This class provides ways to decorate different types of items differently using decorator objects which implements interfaces like IItemHighlighter.
We will look at these data structures in some more detail below. Understanding these data structures will help you to use them in your game effectively.
InventoryItemType
The InventoryType class contains the following data members:
Property | Description/Example |
---|---|
name | The name of the inventory type i.e. 'Fire Blade' |
categories | All possible category of this item type belongs to i.e. [ 'weapon', 'sword', 'blade' ]. |
description | Description of the item |
pictureAssetInfo | Asset information about the picture i.e. file containing picture of a fire blade |
meshAssetInfo | Asset containing the meshes, animations for this inventory item type |
transform | Initial scaling, rotation and position to be applied to the mesh |
attributes | contains attributes of this type of item e.g. weight, height, maxRounds, power etc. |
You can query the InventoryItemType object using some of its predefined methods:
- isa(categoryName)
- isWeapon()
- isAccessory()
- isWeaponAccessory()
- hasWeight()
- hasSize()
- hasMesh()
- hasAnimations()
- hasAudioClip()
Again many of these attributes are optional- so you inventory item can be pretty simple with a simple picture or may be rich with sounds and animations.
InventoryItemConfig class
This class is used to store configuration data for an inventory item on the scene. It can be serialized and saved to a persistent store and later can be deserialized to recreate the inventory item. So all data in this class should be serializable.
Property | Description/Example |
---|---|
inventoryItemType | A reference to an InventoryItemType object |
transform | scaling, rotation and position of the inventory item's mesh. |
states | contains state information of this item such as acquiredByPlayer, damaged, availableRounds etc. |
InventoryItem class
The InventoryItem class denotes an actual instance of an inventory item of a given type. It provides all functionalities to create and display an inventory item in the scene. It contains the following data members:
Property | Description/Example |
---|---|
config | A reference to an InventoryItemConfig object |
decoratorConfig | A object that helps to decorate the item when displayed on the scene |
Note that, in general, the map InventoryType.attributes should be considered immutable and the map InventoryConfig.states as mutable.
Inventory class
The inventory class is a container of InventoryItem objects. An inventory also has a name. It provides a set of convenient methods to find inventories by type or category.