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:

PropertyDescription/Example
nameThe name of the inventory type i.e. 'Fire Blade'
categoriesAll possible category of this item type belongs to i.e. [ 'weapon', 'sword', 'blade' ].
descriptionDescription of the item
pictureAssetInfoAsset information about the picture i.e. file containing picture of a fire blade
meshAssetInfoAsset containing the meshes, animations for this inventory item type
transformInitial scaling, rotation and position to be applied to the mesh
attributescontains 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.

PropertyDescription/Example
inventoryItemTypeA reference to an InventoryItemType object
transformscaling, rotation and position of the inventory item's mesh.
statescontains 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:

PropertyDescription/Example
configA reference to an InventoryItemConfig object
decoratorConfigA 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.