Brunot
Loading...
Searching...
No Matches
Component.h
Go to the documentation of this file.
1
12// ____ __ __ __
13// /\__ _\/\ \ /\ \/\ \
14// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
15// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
16// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
17// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
18// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
19
20
21#pragma once
22#include "GameObject.h"
23
24#define I_DONT_NEED_COMPONENT_INCLUDES
26#undef I_DONT_NEED_COMPONENT_INCLUDES
27
28
29class Entity;
30
31class Component : public GameObject
32{
33public:
38 enum ComponentTypeEnum : unsigned short
39 {
40 // cErrorType and cNewComponentStub are included here so that they compile in stubs,
41 // but aren't in FOR_ALL_COMPONENTS b/c they aren't real components, and we don't want to iterate over them
42 // most of the time when using FOR_ALL_COMPONENTS
43
46#define DECLARE_ENUMS(name, id, ...) c##name = id,
48#undef DECLARE_ENUMS
49 };
50
51
52 auto getType() const -> ComponentTypeEnum
53 {
54 return type;
55 }
56
57 [[nodiscard]] auto getKey() const -> Key override;
58
59 friend auto to_json(json& j, const Component& obj) -> void;
60
61 auto showMenu() -> void override;
62
63 virtual auto componentShowMenu() -> void
64 {
65 };
66
72 auto getEntityParent() const -> Entity*;
73
79 auto pop() const -> std::unique_ptr<Component>;
80
81protected:
82 // Put as protected so Components that inherit can call this constructor
84
91 auto getComponentJson() const -> json;
92
98 auto getChildren() const -> std::shared_ptr<std::vector<GameObject*>> override;
99
100private:
102};
103
104// Component Namespace
105namespace cmpnt
106{
107
108
109struct Sorter
110{
111 auto operator()(const Component* left, const Component* right) const -> bool
112 {
113 return left->getType() < right->getType();
114 }
115};
116
117}
auto to_json(json &j, const AudioObject &a) -> void
Definition AudioObject.cpp:376
#define DECLARE_ENUMS(name, id,...)
Definition Component.h:46
A modernized X macro that lets you do something for every component that exists in the engine.
#define FOR_ALL_COMPONENTS(DO)
a macro to do something for every component in the engine
Definition FOR_ALL_COMPONENTS.h:33
the base class for the engine, most things inherit from this.
nlohmann::json json
Definition Json.cpp:19
Definition Component.h:32
virtual auto componentShowMenu() -> void
Definition Component.h:63
auto getType() const -> ComponentTypeEnum
Definition Component.h:52
auto getComponentJson() const -> json
Definition Component.cpp:94
ComponentTypeEnum type
Definition Component.h:101
auto getChildren() const -> std::shared_ptr< std::vector< GameObject * > > override
override for component to return a vector of no children
Definition Component.cpp:101
auto showMenu() -> void override
Called before update each frame, for calling ImGui editor code relevant to the gameObject.
Definition Component.cpp:30
ComponentTypeEnum
This enum lists out every type of component we have.
Definition Component.h:39
@ cNewComponentStub
Definition Component.h:45
@ cErrorType
Definition Component.h:44
Component(ComponentTypeEnum type, const char *typeName)
Definition Component.cpp:72
auto pop() const -> std::unique_ptr< Component >
Removes the Component from its Entity parent, and gives ownership to the caller.
Definition Component.cpp:111
auto getEntityParent() const -> Entity *
gets the parent as an Entity.
Definition Component.cpp:106
auto getKey() const -> Key override
Generates a unique Key that corresponds to the GameObject.
Definition Component.cpp:25
Definition Entity.h:41
the base class for the engine, most things inherit from this.
Definition GameObject.h:83
std::string typeName
the typeName of a GameObject.
Definition GameObject.h:562
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:24
Definition Component.cpp:81
Definition Component.h:110
auto operator()(const Component *left, const Component *right) const -> bool
Definition Component.h:111