CSEngine
Loading...
Searching...
No Matches
CSE::CustomComponent Class Reference
Inheritance diagram for CSE::CustomComponent:
CSE::SComponent CSE::SObject CSE::SISComponent CSE::VariableBinder

Public Member Functions

 COMPONENT_DEFINE_CONSTRUCTOR (CustomComponent)
 
void Exterminate () override
 
void Init () override
 
void Tick (float elapsedTime) override
 
SComponentClone (SGameObject *object) override
 
void SetClassName (std::string name)
 
std::string SGetClassName () const
 
bool GetIsEnable () const override
 
void SetIsEnable (bool is_enable) override
 
void Log (const char *log)
 
void SetValue (std::string name_str, Arguments value) override
 
std::string PrintValue () const override
 
SGameObjectGetGameObject () const override
 
Sqrat::Object GetClassInstance () const
 
- Public Member Functions inherited from CSE::SComponent
 SComponent (std::string classType, SGameObject *gameObject)
 
 SComponent (const SComponent &src)
 
void Start () override
 
virtual void CopyReference (SComponent *src, std::map< SGameObject *, SGameObject * > lists_obj, std::map< SComponent *, SComponent * > lists_comp)
 
virtual auto GetComponent () -> SObject *
 
void SetValue (std::string name_str, Arguments value) override
 
std::string PrintValue () const override
 
void SetGameObject (SGameObject *object)
 
std::string GetClassType () const
 
void SetClassType (std::string type)
 
- Public Member Functions inherited from CSE::SObject
 SObject (bool isRegister)
 
virtual void SetUndestroyable (bool enable)
 
virtual void Destroy ()
 
virtual void __FORCE_DESTROY__ ()
 
virtual std::string GenerateMeta ()
 
std::string GetHash () const
 
virtual void SetHash (std::string &hash)
 
- Public Member Functions inherited from CSE::SISComponent
 SISComponent (const SISComponent &src)=default
 

Additional Inherited Members

- Protected Types inherited from CSE::VariableBinder
typedef std::vector< std::string > Arguments
 
- Protected Attributes inherited from CSE::SComponent
SGameObjectgameObject = nullptr
 
bool isEnable = true
 
std::string m_classType
 
- Protected Attributes inherited from CSE::SObject
std::string m_hash
 

Detailed Description

Definition at line 11 of file CustomComponent.h.

Member Function Documentation

◆ Clone()

SComponent * CustomComponent::Clone ( SGameObject object)
overridevirtual

Reimplemented from CSE::SComponent.

Definition at line 132 of file CustomComponent.cpp.

132 {
133 INIT_COMPONENT_CLONE(CustomComponent, clone);
134
135 if (!m_className.empty()) {
136 clone->SetClassName(m_classID);
137 }
138
139 return clone;
140}

◆ Exterminate()

void CustomComponent::Exterminate ( )
overridevirtual

Implements CSE::SObject.

Definition at line 20 of file CustomComponent.cpp.

20 {
21 SAFE_DELETE(m_specialization);
22 SAFE_DELETE(m_classInstance);
23}

◆ GetClassInstance()

Sqrat::Object CSE::CustomComponent::GetClassInstance ( ) const
inline

Definition at line 58 of file CustomComponent.h.

58 {
59 return m_classInstance->get();
60 }

◆ GetGameObject()

SGameObject * CustomComponent::GetGameObject ( ) const
overridevirtual

Reimplemented from CSE::SComponent.

Definition at line 128 of file CustomComponent.cpp.

128 {
129 return gameObject;
130}

◆ GetIsEnable()

bool CustomComponent::GetIsEnable ( ) const
overridevirtual

Reimplemented from CSE::SComponent.

Definition at line 113 of file CustomComponent.cpp.

113 {
114 return isEnable;
115}

◆ Init()

void CustomComponent::Init ( )
overridevirtual

Implements CSE::SISComponent.

Definition at line 26 of file CustomComponent.cpp.

26 {
27
28 if (m_specialization == nullptr) return;
29 if (m_classInstance == nullptr) {
30 CreateClassInstance(std::vector<std::string>());
31 }
32
33
34 if (m_funcInit < 0 || m_isError) return;
35
36 try {
37 m_classInstance->call(m_funcInit);
38 } catch (Sqrat::Exception e) {
39 m_isError = true;
40 SafeLog::Log((Sqrat::LastErrorString(Sqrat::DefaultVM::Get()) + '\n').c_str());
41 }
42
43}

◆ Log()

void CustomComponent::Log ( const char *  log)

Definition at line 123 of file CustomComponent.cpp.

123 {
124 SafeLog::Log((std::string(log) + '\n').c_str());
125}

◆ PrintValue()

std::string CustomComponent::PrintValue ( ) const
overridevirtual

Implements CSE::VariableBinder.

Definition at line 158 of file CustomComponent.cpp.

158 {
159 PRINT_START("component");
160
161 PRINT_VALUE(m_classID, ConvertSpaceStr(m_classID));
162 for(auto& val : m_variables) {
163 std::string value = val.value;
164 if(value.empty()) value = "null";
165 PRINT_VALUE(__variable__, val.name, ' ', ConvertSpaceStr(value) , ' ', val.type);
166 }
167
168
169 PRINT_END("component");
170}

◆ SetClassName()

void CustomComponent::SetClassName ( std::string  name)

Definition at line 95 of file CustomComponent.cpp.

95 {
96 auto asset = SResource::Get<SScriptObject>(std::move(name));
97 if (asset == nullptr) return;
98
99 m_classID = asset->GetHash();
100 m_className = asset->GetScriptClassName();
101
102 RegisterScript();
103 CreateClassInstance(asset->GetVariables());
104// Init();
105}

◆ SetIsEnable()

void CustomComponent::SetIsEnable ( bool  is_enable)
overridevirtual

Reimplemented from CSE::SComponent.

Definition at line 118 of file CustomComponent.cpp.

118 {
119 isEnable = is_enable;
120}

◆ SetValue()

void CustomComponent::SetValue ( std::string  name_str,
VariableBinder::Arguments  value 
)
overridevirtual

Implements CSE::VariableBinder.

Definition at line 142 of file CustomComponent.cpp.

142 {
143 if (name_str == "m_classID") {
144 SetClassName(ConvertSpaceStr(value[0], true));
145 }
146 //variable : 0.name , 1.value, 2. type
147 else if (name_str == "__variable__") {
148 for(auto& val : m_variables) {
149 if(val.name == value[0]) {
150 val.value = value[1];
151 val.type = value[2];
152 BindValue(&val, ConvertSpaceStr(value[1], true).c_str());
153 }
154 }
155 }
156}

◆ SGetClassName()

std::string CustomComponent::SGetClassName ( ) const

Definition at line 108 of file CustomComponent.cpp.

108 {
109 return m_className;
110}

◆ Tick()

void CustomComponent::Tick ( float  elapsedTime)
overridevirtual

Implements CSE::SISComponent.

Definition at line 46 of file CustomComponent.cpp.

46 {
47
48 if (m_specialization == nullptr) return;
49 if (m_classInstance == nullptr) return;
50 if (m_funcTick < 0) return;
51 if (m_isError) return;
52
53 try {
54 m_classInstance->call(m_funcTick, elapsedTime);
55 }
56 catch (Sqrat::Exception e) {
57 m_isError = true;
58 SafeLog::Log((Sqrat::LastErrorString(Sqrat::DefaultVM::Get()) + '\n').c_str());
59 }
60
61}

The documentation for this class was generated from the following files: