Erris-State-System/include/state_system.hpp
2025-04-19 08:49:41 +02:00

71 lines
1.9 KiB
C++

#ifndef STATE_SYSTEM_HPP
#define STATE_SYSTEM_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 UpdateAll() {
GetPool<T>().UpdateAll();
}
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>
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