-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScriptableObject.h
More file actions
46 lines (43 loc) · 1.32 KB
/
Copy pathScriptableObject.h
File metadata and controls
46 lines (43 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include "Game/Export.h"
#include "Core/SObject.h"
#include "Core/Factory.hpp"
#include "Core/Logger.h"
#include <memory>
#include <string>
#define SRPO(T)\
SCLASS(T)\
struct _SRPO_Registry_##T\
{\
using Factory = sh::core::Factory<sh::game::ScriptableObject, sh::game::ScriptableObject*, std::string>;\
~_SRPO_Registry_##T()\
{\
auto& stype = T::GetStaticType();\
auto& factory = *Factory::GetInstance();\
SH_INFO_FORMAT("UnRegister {}", stype.type.name);\
factory.UnRegister(std::string{ stype.type.name });\
}\
static auto GetStatic() -> _SRPO_Registry_##T*\
{\
auto& stype = T::GetStaticType();\
auto& factory = *Factory::GetInstance();\
if (factory.HasKey(std::string{ stype.type.name }))\
return nullptr;\
factory.Register(std::string{ stype.type.name }, []() {return sh::core::SObject::Create<T>(); });\
static _SRPO_Registry_##T registry{};\
return ®istry;\
}\
};\
inline static _SRPO_Registry_##T* _srpoRegistry = _SRPO_Registry_##T::GetStatic();\
namespace sh::game
{
class ScriptableObject : public core::SObject
{
SCLASS(ScriptableObject)
public:
SH_GAME_API auto Serialize() const -> core::Json override;
SH_GAME_API void Deserialize(const core::Json& json) override;
public:
using Factory = sh::core::Factory<ScriptableObject, ScriptableObject*, std::string>;
};
}//namespace