Brunot
Loading...
Searching...
No Matches
ActionList.h
Go to the documentation of this file.
1// File: ActionList.h
2// Description: The system that manages all existing actions
3// Author(s): Ori Balashov (ori.balashov@digipen.edu)
4// 2025 / 11 / 07
5// (C) Digipen 2025
6// ____ __ __ __
7// /\__ _\/\ \ /\ \/\ \
8// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
9// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
10// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
11// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
12// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
13
14#pragma once
15
17#include "Framework/Action.h"
18#include "Framework/Entity.h"
19#include "Framework/System.h"
20#include "Utility/Any_Action.h"
21
22using actions_vector = std::vector<std::shared_ptr<th::AnyAction>>;
23
24
25namespace sys
26{
27class ActionList : public System
28{
29public:
30#pragma region static_functions
31
35 static auto getEnum() -> Type
36 {
37 return Type::ActionList;
38 }
39
40#pragma endregion
41
42 ActionList();
43 ~ActionList() override = default;
44 ActionList(const ActionList& other);
45 ActionList(ActionList&& other) noexcept = default;
46 auto operator=(const ActionList& other) -> ActionList&;
47 auto operator=(ActionList&& other) noexcept -> ActionList& = default;
48
49
50#pragma region overridden_functions
51
52 auto clone() const -> std::unique_ptr<GameObject> override;
53 auto onUpdate(float dt) -> void override;
54 auto onRender() -> void override;
55 auto load(Stream& stream) -> void override;
56 auto save(Stream& stream) const -> void override;
57 auto endWindow() -> void override; // for debug ImGUI
58
59
60#pragma endregion
61
62#pragma region ActionList_Functions
63
74 template <typename T>
75 auto addAction(T startValue, T endGoal, float duration, GameObject* owner,
76 const std::function<void(GameObject*, const T&)>& actionFunction,
77 const std::function<float(float, float)>& easingFunction = ac::LinearEase) -> void
78 {
80 auto action = Action<T>(startValue, endGoal, duration, owner, actionFunction, easingFunction);
81 auto any = new th::AnyAction(action);
82 std::shared_ptr<th::AnyAction> result(any);
83 if (owner)
84 {
85 auto ownerEnt = dynamic_cast<Entity*>(owner);
86 if (auto proxy = ownerEnt->GetComponent<ActionProxy>(Component::cActionProxy))
87 {
88 proxy->add(result);
89 }
90 else
91 {
92 auto newPtr = std::make_unique<ActionProxy>();
93 ownerEnt->addComponent(std::move(newPtr));
94 }
95 }
96 currentActions.push_back(std::move(result));
97 }
98
99 // Variadic constructor for actions
100 template <typename... parameter>
101 auto addAction(parameter... actionInfo, GameObject* owner) -> void
102 {
103 auto action = Action(actionInfo);
104 auto any = new th::AnyAction(action);
105 std::shared_ptr<th::AnyAction> result(any);
106 if (owner)
107 {
108 auto ownerEnt = dynamic_cast<Entity*>(owner);
109 if (auto proxy = ownerEnt->GetComponent<ActionProxy>(Component::cActionProxy))
110 {
111 proxy->add(result);
112 }
113 else
114 {
115 auto newPtr = std::make_unique<ActionProxy>();
116 ownerEnt->addComponent(std::move(newPtr));
117 }
118 }
119 currentActions.push_back(std::move(result));
120 }
121
122
123 // Adds an already existing action to the action list
124 auto addAction(const std::shared_ptr<th::AnyAction>& action) -> void;
125
126#pragma endregion
127
128private:
129#pragma region member_variables
131#pragma endregion
132
133#pragma region helper_functions
134
135 // Lambda for checking if an action has finished
136 inline static auto HasActionExpired = [](const auto& item)
137 {
138 return item->shouldRemove();
139 };
140
141#pragma endregion
142
143#pragma region static_variables
144
145#pragma endregion
146
147
148};
149}
std::vector< std::shared_ptr< th::AnyAction > > actions_vector
Definition ActionList.h:22
static FMOD_RESULT result
Definition AudioObject.cpp:27
sys::Json Stream
Definition AudioObject.h:20
The class containing all entity elements.
Definition ActionProxy.h:19
Definition Action.h:35
@ cActionProxy
Definition Component.h:62
friend Entity
Definition GameObject.h:84
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23
Type
Definition System.h:20
@ ActionList
Definition System.h:33
System(const std::string &typeName, Type systemType)
Definition System.cpp:75
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition ActionList.cpp:89
auto operator=(const ActionList &other) -> ActionList &
Definition ActionList.cpp:37
auto addAction(parameter... actionInfo, GameObject *owner) -> void
Definition ActionList.h:101
auto operator=(ActionList &&other) noexcept -> ActionList &=default
auto onUpdate(float dt) -> void override
called once every frame.
Definition ActionList.cpp:59
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition ActionList.cpp:84
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition ActionList.cpp:79
static auto getEnum() -> Type
function required by all systems
Definition ActionList.h:35
ActionList()
Definition ActionList.cpp:22
static auto HasActionExpired
Definition ActionList.h:136
actions_vector currentActions
Definition ActionList.h:130
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition ActionList.cpp:54
~ActionList() override=default
auto onRender() -> void override
called every frame after update has been called for every object.
Definition ActionList.cpp:70
auto addAction(T startValue, T endGoal, float duration, GameObject *owner, const std::function< void(GameObject *, const T &)> &actionFunction, const std::function< float(float, float)> &easingFunction=ac::LinearEase) -> void
Definition ActionList.h:75
ActionList(ActionList &&other) noexcept=default
static const std::function LinearEase
Definition Action.h:26
the type of elements in a basic_json container
Definition GameObject.h:32
boost::type_erasure::any< boost::type_erasure::ActionConcept<>, boost::type_erasure::_self > AnyAction
Definition Any_Action.h:56