Cafu Engine
CompInventory.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_GAMESYS_COMPONENT_INVENTORY_HPP_INCLUDED
8 #define CAFU_GAMESYS_COMPONENT_INVENTORY_HPP_INCLUDED
9 
10 #include "../CompBase.hpp"
11 
12 
13 namespace cf
14 {
15  namespace GameSys
16  {
17  /// This component keeps an inventory count for an arbitrary set of items.
18  /// An item can be anything that can be described with a string.
19  /// Contrary to other components, an inventory is flexible regarding the "kind" and number
20  /// of items that it keeps the counts for. However, it is focused on being used by script code;
21  /// it is not possible to inspect and edit the contained items in the Map Editor at this time.
23  {
24  public:
25 
26  /// The constructor.
28 
29  /// The copy constructor.
30  /// @param Comp The component to create a copy of.
32 
33  // Base class overrides.
34  ComponentInventoryT* Clone() const;
35  const char* GetName() const { return "Inventory"; }
36 
37 
38  // The TypeSys related declarations for this class.
39  const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
40  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
41  static const cf::TypeSys::TypeInfoT TypeInfo;
42 
43 
44  protected:
45 
46  // The Lua API methods of this class.
47  static int Get(lua_State* LuaState);
48  static int Set(lua_State* LuaState);
49  static int Add(lua_State* LuaState);
50  static int CheckMax(lua_State* LuaState);
51  static int toString(lua_State* LuaState);
52 
53  static const luaL_Reg MethodsList[]; ///< The list of Lua methods for this class.
54  static const char* DocClass;
55  static const cf::TypeSys::MethsDocT DocMethods[];
56  static const cf::TypeSys::VarsDocT DocVars[];
57 
58 
59  private:
60 
61  void DoSerialize(cf::Network::OutStreamT& Stream) const /*override*/;
62  void DoDeserialize(cf::Network::InStreamT& Stream, bool IsIniting) /*override*/;
63 
64  std::map<std::string, uint16_t> m_Items;
65  };
66  }
67 }
68 
69 #endif
This component keeps an inventory count for an arbitrary set of items.
Definition: CompInventory.hpp:22
static const luaL_Reg MethodsList[]
The list of Lua methods for this class.
Definition: CompInventory.hpp:53
ComponentInventoryT()
The constructor.
Definition: CompInventory.cpp:37
This class is used for reading data from a StateT instance (deserialization).
Definition: State.hpp:207
const char * GetName() const
Returns the name of this component.
Definition: CompInventory.hpp:35
This class is used for writing data into a StateT instance (serialization).
Definition: State.hpp:81
ComponentInventoryT * Clone() const
The virtual copy constructor.
Definition: CompInventory.cpp:91
Definition: TypeSys.hpp:52
Definition: TypeSys.hpp:57
This class keeps type information (about an entity class that occurs in the game).
Definition: TypeSys.hpp:79
Definition: TypeSys.hpp:68
This is the base class for the components that an entity is composed/aggregated of.
Definition: CompBase.hpp:54