CSEngine
Loading...
Searching...
No Matches
VariableBinder.h
1
//
2
// Created by ounols on 19. 8. 21.
3
//
4
5
#pragma once
6
7
#include <vector>
8
#include "MoreString.h"
9
10
namespace
CSE {
11
12
class
VariableBinder
{
13
protected
:
14
typedef
std::vector<std::string> Arguments;
15
protected
:
16
VariableBinder
() =
default
;
17
18
virtual
~VariableBinder
() =
default
;
19
20
public
:
27
virtual
void
SetValue
(std::string name_str, Arguments value) = 0;
28
29
virtual
std::string PrintValue()
const
= 0;
30
};
31
}
32
33
#define PRINT_START(type) std::string result = std::string("<") + (type) + " type=\"" + GetClassType() + "\" enable=\"" + (isEnable ? "1" : "0") + "\">" + '\n'
34
#define PRINT_END(type) result += std::string("</") + (type) + ">\n"; return result
35
#define PRINT_VALUE(type, variable, ...) {std::stringstream temp;\
36
result += std::string("<value name=\"") + #variable + "\" t=\"" + type + "\">" + appandAll(temp, __VA_ARGS__) + "</value>\n";}
37
#define PRINT_COMP_NAME(name, variable) {std::stringstream temp;\
38
result += std::string("<value name=\"") + #name + "\" t=\"comp\" d=\"" + variable->GetClassType() + "\">" + ConvertSpaceStr(variable->GetHash()) + "</value>\n";}
39
#define PRINT_RES_NAME(name, variable) {std::stringstream temp;\
40
result += std::string("<value name=\"") + #name + "\" t=\"res\" d=\"" + variable->GetClassType() + "\">" + ConvertSpaceStr(variable->GetHash()) + "</value>\n";}
41
42
#define PRINT_COMP(variable) PRINT_COMP_NAME(variable, variable)
43
#define PRINT_RES(variable) PRINT_RES_NAME(variable, variable)
44
45
#define PRINT_VALUE_SPREFAB_REF(variable) {const auto& obj = variable->GetGameObject();\
46
const auto& ref = dynamic_cast<SGameObjectFromSPrefab*>(variable->GetGameObject());\
47
std::stringstream temp;\
48
result += std::string("<value name=\"") + #variable + "\" ref=\"" + \
49
(ref == nullptr ? "0" : "1") + "\" t=\"prefab\">" +\
50
appandAll(temp, (ref == nullptr ? obj->GetID(variable) : ref->GetRefID(variable))) + "</value>\n";\
51
}
52
#define PRINT_VALUE_MAT4(variable) {\
53
mat4 m = variable;\
54
PRINT_VALUE("mat4", variable, m.x.x, ' ', m.x.y, ' ', m.x.z, ' ', m.x.w, ' ',\
55
m.y.x, ' ', m.y.y, ' ', m.y.z, ' ', m.y.w, ' ',\
56
m.z.x, ' ', m.z.y, ' ', m.z.z, ' ', m.z.w, ' ',\
57
m.w.x, ' ', m.w.y, ' ', m.w.z, ' ', m.w.w);}
58
#define PRINT_VALUE_VEC3(variable) {\
59
vec3 v = variable;\
60
PRINT_VALUE("vec3", variable, v.x, ' ', v.y, ' ', v.z);}
61
#define PRINT_VALUE_VEC4(variable) {\
62
vec4 v = variable;\
63
PRINT_VALUE("vec4", variable, v.x, ' ', v.y, ' ', v.z, ' ', v.w);}
64
65
#define PRINT_VALUE_COLOR3(variable) {\
66
vec3 v = variable;\
67
PRINT_VALUE("col3", variable, v.x, ' ', v.y, ' ', v.z);}
68
#define PRINT_VALUE_COLOR4(variable) {\
69
vec4 v = variable;\
70
PRINT_VALUE("col4", variable, v.x, ' ', v.y, ' ', v.z, ' ', v.w);}
71
72
#define SET_VEC3(variable) {vec3 vec = vec3();\
73
vec.Set(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]));\
74
variable = std::move(vec);}
75
#define SET_VEC4(variable) {vec4 vec = vec4();\
76
vec.Set(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]), std::stof(value[3]));\
77
variable = std::move(vec);}
78
#define SET_MAT4(variable) {mat4 mat = mat4();\
79
mat.x.Set(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]), std::stof(value[3]));\
80
mat.y.Set(std::stof(value[4]), std::stof(value[5]), std::stof(value[6]), std::stof(value[7]));\
81
mat.z.Set(std::stof(value[8]), std::stof(value[9]), std::stof(value[10]), std::stof(value[11]));\
82
mat.w.Set(std::stof(value[12]), std::stof(value[13]), std::stof(value[14]), std::stof(value[15]));\
83
variable = std::move(mat);}
84
#define SET_SPREFAB_REF(variable, component) {\
85
const auto& ref = dynamic_cast<SGameObjectFromSPrefab*>(variable->GetGameObject()); \
86
const auto& obj = variable->GetGameObject();\
87
if (ref != nullptr) variable = ref->GetComponentByRefHash<component>(value[0]);\
88
else variable = obj->GetComponentByHash<component>(value[0]);\
89
}
90
CSE::VariableBinder
Definition
VariableBinder.h:12
CSE::VariableBinder::SetValue
virtual void SetValue(std::string name_str, Arguments value)=0
Util
VariableBinder.h
Generated on Wed Oct 8 2025 01:09:56 for CSEngine by
1.12.0