Cafu Engine
CompBasics.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_ENTITY_BASICS_HPP_INCLUDED
8 #define CAFU_GAMESYS_COMPONENT_ENTITY_BASICS_HPP_INCLUDED
9 
10 #include "CompBase.hpp"
11 
12 
13 namespace cf
14 {
15  namespace GameSys
16  {
17  /// This component adds the basics of the entity (its name and the "is shown?" flag).
18  /// It is one of the components that is "fundamental" to an entity (cf::GameSys::IsFundamental() returns `true`).
19  /// Every entity must have exactly one.
21  {
22  public:
23 
24  /// The constructor.
26 
27  /// The copy constructor.
28  /// @param Comp The component to create a copy of.
30 
31  /// Returns the name of the entity.
32  const std::string& GetEntityName() const { return m_Name.Get(); }
33 
34  /// Sets a new name for the entity.
35  /// Entity names must be valid Lua script identifiers and unique among their siblings, and the method
36  /// modifies the given string as necessary. As a result, GetEntityName() can return a string that is
37  /// different from the string given to a preceeding call to SetEntityName().
38  /// This is equivalent to calling `SetMember("Name", Name);`, but is provided for the more explicit
39  /// documentation of the side-effects.
40  void SetEntityName(const std::string& Name) { m_Name.Set(Name); }
41 
42  /// Returns `true` if the entity is declared as static. Returns `false` if (the primitives of) the entity can move.
43  bool IsStatic() const { return m_Static.Get(); }
44 
45  // Base class overrides.
46  ComponentBasicsT* Clone() const override;
47  const char* GetName() const override { return "Basics"; }
48 
49 
50  // The TypeSys related declarations for this class.
51  const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
52  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
53  static const cf::TypeSys::TypeInfoT TypeInfo;
54 
55 
56  protected:
57 
58  // The Lua API methods of this class.
59  static int toString(lua_State* LuaState);
60 
61  static const luaL_Reg MethodsList[]; ///< The list of Lua methods for this class.
62  static const char* DocClass;
63  static const cf::TypeSys::MethsDocT DocMethods[];
64  static const cf::TypeSys::VarsDocT DocVars[];
65 
66 
67  private:
68 
69  /// A variable of type `std::string`, specifically for entity names.
70  /// Entity names must be valid Lua script identifiers and unique among their siblings.
71  class EntityNameT : public TypeSys::VarT<std::string>
72  {
73  public:
74 
75  EntityNameT(const char* Name, const std::string& Value, const char* Flags[], ComponentBasicsT& CompBasics);
76  EntityNameT(const EntityNameT& Var, ComponentBasicsT& CompBasics);
77 
78  // Base class overrides.
79  void Set(const std::string& v);
80 
81 
82  private:
83 
84  ComponentBasicsT& m_CompBasics; ///< The parent ComponentBasicsT that contains this variable.
85  };
86 
87 
88  EntityNameT m_Name; ///< The name of the entity. Entity names must be valid Lua script identifiers and unique among their siblings.
89  TypeSys::VarT<bool> m_Static; ///< Are the map primitives of this entity fixed and immovable, never moving around in the game world?
90  };
91  }
92 }
93 
94 #endif
bool IsStatic() const
Returns true if the entity is declared as static. Returns false if (the primitives of) the entity can...
Definition: CompBasics.hpp:43
const char * GetName() const override
Returns the name of this component.
Definition: CompBasics.hpp:47
This is a "wrapper" around a normal C++ variable.
Definition: SetCompVar.hpp:15
This component adds the basics of the entity (its name and the "is shown?" flag). ...
Definition: CompBasics.hpp:20
ComponentBasicsT * Clone() const override
The virtual copy constructor.
Definition: CompBasics.cpp:133
const std::string & GetEntityName() const
Returns the name of the entity.
Definition: CompBasics.hpp:32
ComponentBasicsT()
The constructor.
Definition: CompBasics.cpp:113
static const luaL_Reg MethodsList[]
The list of Lua methods for this class.
Definition: CompBasics.hpp:61
void SetEntityName(const std::string &Name)
Sets a new name for the entity.
Definition: CompBasics.hpp:40
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
const T & Get() const
Returns the value of this variable.
Definition: Variables.hpp:182
Definition: TypeSys.hpp:68
This is the base class for the components that an entity is composed/aggregated of.
Definition: CompBase.hpp:54