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

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 (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)
 
- Public Member Functions inherited from CSE::SObject
 SObject (bool isRegister)
 
virtual void SetUndestroyable (bool enable)
 
virtual void Destroy ()
 
std::string GetHash () const
 
virtual void SetHash (std::string &hash)
 
- Public Member Functions inherited from CSE::SISComponent
 SISComponent (const SISComponent &src)=default
 
- Public Member Functions inherited from CSE::VariableBinder
- Public Member Functions inherited from CSE::ReflectionObject
 ReflectionObject (std::string type)
 
void SetClassType (std::string type)
 
const char * GetClassType () const
 
bool IsSameClass (const char *classType) const
 

Additional Inherited Members

- Static Public Member Functions inherited from CSE::ReflectionObject
static ReflectionObjectNewObject (const std::string &name)
 
- Protected Types inherited from CSE::VariableBinder
typedef std::vector< std::string > Arguments
 
- Protected Member Functions inherited from CSE::VariableBinder
- Protected Attributes inherited from CSE::SComponent
SGameObjectgameObject = nullptr
 
bool isEnable = true
 
- Protected Attributes inherited from CSE::SObject
std::string m_hash
 
- Protected Attributes inherited from CSE::ReflectionObject
std::string m_class
 

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 149 of file CustomComponent.cpp.

149 {
150 INIT_COMPONENT_CLONE(CustomComponent, clone);
151
152 if (!m_className.empty()) {
153 clone->SetClassName(m_classID);
154 }
155
156 return clone;
157}

◆ 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 145 of file CustomComponent.cpp.

145 {
146 return gameObject;
147}

◆ GetIsEnable()

bool CustomComponent::GetIsEnable ( ) const
overridevirtual

Reimplemented from CSE::SComponent.

Definition at line 130 of file CustomComponent.cpp.

130 {
131 return isEnable;
132}

◆ 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 if(!m_classInstance->call_safe(m_funcInit)) {
38 m_isError = true;
39 SafeLog::Log(("[" + m_className + " (Init)] " + Sqrat::LastErrorString(Sqrat::DefaultVM::Get()) + '\n').c_str());
40 }
41 } catch (Sqrat::Exception e) {
42 m_isError = true;
43 SafeLog::Log(("[" + m_className + " (Init)] " + Sqrat::LastErrorString(Sqrat::DefaultVM::Get()) + '\n').c_str());
44 }
45
46}

◆ Log()

void CustomComponent::Log ( const char * log)

Definition at line 140 of file CustomComponent.cpp.

140 {
141 SafeLog::Log((std::string(log) + '\n').c_str());
142}

◆ PrintValue()

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

Implements CSE::VariableBinder.

Definition at line 175 of file CustomComponent.cpp.

175 {
176 PRINT_START("component");
177
178 PRINT_VALUE("classId", m_classID, ConvertSpaceStr(m_classID));
179 for(auto& val : m_variables) {
180 std::string value = val.value;
181 if(value.empty()) value = "null";
182 PRINT_VALUE("classVal", __variable__, val.name, ' ', ConvertSpaceStr(value) , ' ', val.type);
183 }
184
185
186 PRINT_END("component");
187}

◆ SetClassName()

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

Definition at line 112 of file CustomComponent.cpp.

112 {
113 auto asset = SResource::Get<SScriptObject>(std::move(name));
114 if (asset == nullptr) return;
115
116 m_classID = asset->GetHash();
117 m_className = asset->GetScriptClassName();
118
119 RegisterScript();
120 CreateClassInstance(asset->GetVariables());
121// Init();
122}

◆ SetIsEnable()

void CustomComponent::SetIsEnable ( bool is_enable)
overridevirtual

Reimplemented from CSE::SComponent.

Definition at line 135 of file CustomComponent.cpp.

135 {
136 isEnable = is_enable;
137}

◆ SetValue()

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

Used to get serialized values. All classes that inherit from VariableBinder will unconditionally call this function first during initialization.

Parameters
name_strName of values
valueSerialized values

Implements CSE::VariableBinder.

Definition at line 159 of file CustomComponent.cpp.

159 {
160 if (name_str == "m_classID") {
161 SetClassName(ConvertSpaceStr(value[0], true));
162 }
163 //variable : 0.name , 1.value, 2. type
164 else if (name_str == "__variable__") {
165 for(auto& val : m_variables) {
166 if(val.name == trim(value[0])) {
167 val.value = trim(value[1]);
168 val.type = trim(value[2]);
169 BindValue(&val, ConvertSpaceStr(value[1], true).c_str());
170 }
171 }
172 }
173}

◆ SGetClassName()

std::string CustomComponent::SGetClassName ( ) const

Definition at line 125 of file CustomComponent.cpp.

125 {
126 return m_className;
127}

◆ Tick()

void CustomComponent::Tick ( float elapsedTime)
overridevirtual

Implements CSE::SISComponent.

Definition at line 49 of file CustomComponent.cpp.

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

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