Brunot
Loading...
Searching...
No Matches
ActionList.h
Go to the documentation of this file.
1
10// ____ __ __ __
11// /\__ _\/\ \ /\ \/\ \
12// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
13// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
14// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
15// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
16// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
17
18
19
20#pragma once
21#include "Framework/Component.h"
22
23#include "Actions/Action.h"
24
29class ActionList : public Component
30{
31public:
32 ActionList();
33 ActionList(const ActionList&);
34 auto operator=(const ActionList&) -> ActionList&;
35 ~ActionList() override = default;
36 ActionList(ActionList&& other) noexcept = default;
37 auto operator=(ActionList&& other) noexcept -> ActionList& = default;
38
39 auto operator[](int index) const -> Action&;
40
41 auto parentTo(GameObject* newParent) -> bool override;
42 auto clone() const -> std::unique_ptr<GameObject> override;
43 auto componentShowMenu() -> void override; // for debug ImGUI
44 auto onUpdate(float dt) -> void override;
45 auto endWindow() -> void override; // for debug ImGUI
46 auto onRender() -> void override;
47 auto load(const Stream& stream) -> void override;
48 auto save(Stream& stream) const -> void override;
49
50 friend auto to_json(json& j, const ActionList& a) -> void;
51 friend auto from_json(const json& j, ActionList& a) -> void;
52
53
54
55 auto pushBack(const std::unique_ptr<Action>& newAction) -> void;
56 auto pushFront(const std::unique_ptr<Action>& newAction) -> void;
57
58 auto clear() -> void;
59
60 template <typename ActionType>
61 auto pushBack(const ActionType& newAction) -> void
62 {
63 allActions.emplace_back(std::make_unique<ActionType>(newAction));
64 allActions.back()->setOwner(this->getEntityParent());
65 }
66
67 template <typename ActionType>
68 auto pushFront(const ActionType& newAction) -> void
69 {
70 allActions.insert(allActions.begin(),std::make_unique<ActionType>(newAction));
71 allActions.front()->setOwner(this->getEntityParent());
72 }
73
74
75
76
77
78private:
79 std::vector<std::unique_ptr<Action>> allActions;
80
81 // Lambda for checking if an action has finished
82 inline static auto HasActionExpired = [](const auto& item)
83 {
84 return item->shouldRemove();
85 };
86};
A class that changes a variable over a set duration.
sys::Json Stream
Definition AudioObject.h:20
The base class for components, holding all of their shared All components should inherit from this.
nlohmann::json json
Definition Json.cpp:19
friend auto to_json(json &j, const ActionList &a) -> void
Definition ActionList.cpp:147
auto parentTo(GameObject *newParent) -> bool override
Sets the GameObject as a child of another GameObject.
Definition ActionList.cpp:60
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition ActionList.cpp:137
auto onRender() -> void override
called every frame after update has been called for every object.
Definition ActionList.cpp:133
std::vector< std::unique_ptr< Action > > allActions
Definition ActionList.h:79
auto componentShowMenu() -> void override
Definition ActionList.cpp:77
auto pushBack(const std::unique_ptr< Action > &newAction) -> void
Definition ActionList.cpp:159
ActionList()
Definition ActionList.cpp:24
auto onUpdate(float dt) -> void override
called once every frame.
Definition ActionList.cpp:113
auto operator=(const ActionList &) -> ActionList &
Definition ActionList.cpp:39
auto clear() -> void
Definition ActionList.cpp:171
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition ActionList.cpp:142
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition ActionList.cpp:129
auto operator=(ActionList &&other) noexcept -> ActionList &=default
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition ActionList.cpp:72
ActionList(ActionList &&other) noexcept=default
friend auto from_json(const json &j, ActionList &a) -> void
Definition ActionList.cpp:154
auto operator[](int index) const -> Action &
Definition ActionList.cpp:50
auto pushFront(const ActionType &newAction) -> void
Definition ActionList.h:68
static auto HasActionExpired
Definition ActionList.h:82
~ActionList() override=default
auto pushFront(const std::unique_ptr< Action > &newAction) -> void
Definition ActionList.cpp:165
Definition Action.h:131
Component(ComponentTypeEnum type, const char *typeName)
Definition Component.cpp:72
auto getEntityParent() const -> Entity *
gets the parent as an Entity.
Definition Component.cpp:106
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23