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
:
21
virtual
void
SetValue(std::string name_str, Arguments value) = 0;
22
23
virtual
std::string PrintValue()
const
= 0;
24
};
25
}
26
27
#define PRINT_START(type) std::string result = std::string("<") + (type) + " type=\"" + m_classType + "\" enable=\"" + (isEnable ? "1" : "0") + "\">" + '\n'
28
#define PRINT_END(type) result += std::string("</") + (type) + ">\n"; return result
29
#define PRINT_VALUE(variable, ...) {std::stringstream temp;\
30
result += std::string("<value name=\"") + #variable + "\">" + appandAll(temp, __VA_ARGS__) + "</value>\n";}
31
#define PRINT_VALUE_SPREFAB_REF(variable) {const auto& obj = variable->GetGameObject();\
32
const auto& ref = dynamic_cast<SGameObjectFromSPrefab*>(variable->GetGameObject());\
33
std::stringstream temp;\
34
result += std::string("<value name=\"") + #variable + "\" ref=\"" + \
35
(ref == nullptr ? "0" : "1") + "\">" +\
36
appandAll(temp, (ref == nullptr ? obj->GetID(variable) : ref->GetRefID(variable))) + "</value>\n";\
37
}
38
#define PRINT_VALUE_MAT4(variable) {\
39
mat4 m = variable;\
40
PRINT_VALUE(variable, m.x.x, ' ', m.x.y, ' ', m.x.z, ' ', m.x.w, ' ',\
41
m.y.x, ' ', m.y.y, ' ', m.y.z, ' ', m.y.w, ' ',\
42
m.z.x, ' ', m.z.y, ' ', m.z.z, ' ', m.z.w, ' ',\
43
m.w.x, ' ', m.w.y, ' ', m.w.z, ' ', m.w.w);}
44
#define PRINT_VALUE_VEC3(variable) {\
45
vec3 v = variable;\
46
PRINT_VALUE(variable, v.x, ' ', v.y, ' ', v.z);}
47
#define PRINT_VALUE_VEC4(variable) {\
48
vec4 v = variable;\
49
PRINT_VALUE(variable, v.x, ' ', v.y, ' ', v.z, ' ', v.w);}
50
51
#define SET_VEC3(variable) {vec3 vec = vec3();\
52
vec.Set(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]));\
53
variable = std::move(vec);}
54
#define SET_VEC4(variable) {vec4 vec = vec4();\
55
vec.Set(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]), std::stof(value[3]));\
56
variable = std::move(vec);}
57
#define SET_MAT4(variable) {mat4 mat = mat4();\
58
mat.x.Set(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]), std::stof(value[3]));\
59
mat.y.Set(std::stof(value[4]), std::stof(value[5]), std::stof(value[6]), std::stof(value[7]));\
60
mat.z.Set(std::stof(value[8]), std::stof(value[9]), std::stof(value[10]), std::stof(value[11]));\
61
mat.w.Set(std::stof(value[12]), std::stof(value[13]), std::stof(value[14]), std::stof(value[15]));\
62
variable = std::move(mat);}
63
#define SET_SPREFAB_REF(variable, component) {\
64
const auto& ref = dynamic_cast<SGameObjectFromSPrefab*>(variable->GetGameObject()); \
65
const auto& obj = variable->GetGameObject();\
66
if (ref != nullptr) variable = ref->GetComponentByRefHash<component>(value[0]);\
67
else variable = obj->GetComponentByHash<component>(value[0]);\
68
}
69
CSE::VariableBinder
Definition
VariableBinder.h:12
Util
VariableBinder.h
Generated on Fri Nov 22 2024 01:09:32 for CSEngine by
1.9.8