CSEngine
Loading...
Searching...
No Matches
CustomComponent.h
1#pragma once
2
3#include "SComponent.h"
4#include "sqext.h"
5
6#include <map>
7#include <utility>
8
9namespace CSE {
10
11 class CustomComponent : public SComponent {
12
13 private:
14 struct VARIABLE {
15
16 VARIABLE(std::string name, const char* type, std::string value) {
17 this->name = std::move(name);
18 this->type = type;
19 this->value = std::move(value);
20 }
21
22 std::string name;
23 std::string type;
24 std::string value;
25 };
26 public:
27 COMPONENT_DEFINE_CONSTRUCTOR(CustomComponent);
28
29 ~CustomComponent() override;
30
31
32 void Exterminate() override;
33
34 void Init() override;
35
36 void Tick(float elapsedTime) override;
37
38 SComponent* Clone(SGameObject* object) override;
39
40 void SetClassName(std::string name);
41
42 std::string SGetClassName() const;
43
44
45 bool GetIsEnable() const override;
46
47 void SetIsEnable(bool is_enable) override;
48
49 void Log(const char* log);
50
51 void SetValue(std::string name_str, Arguments value) override;
52
53 std::string PrintValue() const override;
54
55 SGameObject* GetGameObject() const override;
56
57
58 Sqrat::Object GetClassInstance() const {
59 return m_classInstance->get();
60 }
61//
62// auto GetComponent() -> CustomComponent* override {
63// return this;
64// }
65
66 private:
67 void RegisterScript();
68 void CreateClassInstance(const std::vector<std::string>& variables);
69
70 void BindValue(VARIABLE* variable, const char* value) const;
71
72 private:
73 mutable sqext::SQIClass* m_specialization = nullptr;
74 mutable sqext::SQIClassInstance* m_classInstance = nullptr;
75 int m_funcSetCSEngine = 0;
76 int m_funcInit = 1;
77 int m_funcTick = 2;
78 int m_funcExterminate = 3;
79 std::vector<VARIABLE> m_variables;
80
81 std::string m_className;
82 std::string m_classID;
83
84 bool m_isError = false;
85 };
86}