Erris-State-System/include/state_system.hpp
Erris 7f441153ab Implemented the transition system
Transitions being a way to allow for automatic state change and allow
for a way to allow or forbbid a transition between two states
2025-04-21 10:41:58 +02:00

77 lines
2.0 KiB
C++

#ifndef STATE_SYSTEM_HPP
#define STATE_SYSTEM_HPP
#include "state.hpp"
#include "state_machine.hpp"
#include "state-machine_pool.hpp"
class StateSystem {
public:
template <typename T>
void RegisterEntity(const std::string &id, T &object) {
GetPool<T>().RegisterEntity(id, object);
}
template <typename T>
void UnregisterEntity(const std::string &id) {
GetPool<T>().UnregisterEntity(id);
}
template <typename T>
void ChangeState(const std::string &id, const std::string &stateId) {
GetPool<T>().ChangeState(id, stateId);
}
template <typename T>
void RevertState(const std::string &id) {
GetPool<T>().RevertState(id);
}
template <typename T>
void RegisterState(const std::string &id, std::shared_ptr<State<T>> state) {
if (state)
GetPool<T>().RegisterState(id, std::move(state));
}
template <typename T>
void AddTransition(Transition<T> &transition) {
GetPool<T>().AddTransition(transition);
}
template <typename T>
void UpdateAll() {
GetPool<T>().UpdateAll();
}
template <typename T>
json Serialize() const {
StateMachinePool<T> &pool = GetPool<T>();
return pool.Serialize();
}
template <typename T>
void Deserialize(const json& j, std::function<T &(const std::string&)> getEntity) {
GetPool<T>().Deserialize(j, getEntity);
}
template <typename T>
void SetStrictTransitions(bool enabled) {
GetPool<T>().SetStrictTransitions(enabled);
}
template <typename T>
void SetAutoTransitions(bool enabled) {
GetPool<T>().SetAutoTransitions(enabled);
}
private:
template <typename T>
StateMachinePool<T> &GetPool() const {
static StateMachinePool<T> pool;
return pool;
}
};
#endif // STATE_SYSTEM_HPP