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
10namespace CSE {
11
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;\
36result += std::string("<value name=\"") + #variable + "\" t=\"" + type + "\">" + appandAll(temp, __VA_ARGS__) + "</value>\n";}
37#define PRINT_COMP_NAME(name, variable) {std::stringstream temp;\
38result += 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;\
40result += 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();\
46const auto& ref = dynamic_cast<SGameObjectFromSPrefab*>(variable->GetGameObject());\
47std::stringstream temp;\
48result += std::string("<value name=\"") + #variable + "\" ref=\"" + \
49(ref == nullptr ? "0" : "1") + "\" t=\"prefab\">" +\
50appandAll(temp, (ref == nullptr ? obj->GetID(variable) : ref->GetRefID(variable))) + "</value>\n";\
51 }
52#define PRINT_VALUE_MAT4(variable) {\
53mat4 m = variable;\
54PRINT_VALUE("mat4", variable, m.x.x, ' ', m.x.y, ' ', m.x.z, ' ', m.x.w, ' ',\
55m.y.x, ' ', m.y.y, ' ', m.y.z, ' ', m.y.w, ' ',\
56m.z.x, ' ', m.z.y, ' ', m.z.z, ' ', m.z.w, ' ',\
57m.w.x, ' ', m.w.y, ' ', m.w.z, ' ', m.w.w);}
58#define PRINT_VALUE_VEC3(variable) {\
59vec3 v = variable;\
60PRINT_VALUE("vec3", variable, v.x, ' ', v.y, ' ', v.z);}
61#define PRINT_VALUE_VEC4(variable) {\
62vec4 v = variable;\
63PRINT_VALUE("vec4", variable, v.x, ' ', v.y, ' ', v.z, ' ', v.w);}
64
65#define PRINT_VALUE_COLOR3(variable) {\
66vec3 v = variable;\
67PRINT_VALUE("col3", variable, v.x, ' ', v.y, ' ', v.z);}
68#define PRINT_VALUE_COLOR4(variable) {\
69vec4 v = variable;\
70PRINT_VALUE("col4", variable, v.x, ' ', v.y, ' ', v.z, ' ', v.w);}
71
72#define SET_VEC3(variable) {vec3 vec = vec3();\
73vec.Set(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]));\
74variable = std::move(vec);}
75#define SET_VEC4(variable) {vec4 vec = vec4();\
76vec.Set(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]), std::stof(value[3]));\
77variable = std::move(vec);}
78#define SET_MAT4(variable) {mat4 mat = mat4();\
79mat.x.Set(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]), std::stof(value[3]));\
80mat.y.Set(std::stof(value[4]), std::stof(value[5]), std::stof(value[6]), std::stof(value[7]));\
81mat.z.Set(std::stof(value[8]), std::stof(value[9]), std::stof(value[10]), std::stof(value[11]));\
82mat.w.Set(std::stof(value[12]), std::stof(value[13]), std::stof(value[14]), std::stof(value[15]));\
83variable = std::move(mat);}
84#define SET_SPREFAB_REF(variable, component) {\
85const auto& ref = dynamic_cast<SGameObjectFromSPrefab*>(variable->GetGameObject()); \
86const auto& obj = variable->GetGameObject();\
87if (ref != nullptr) variable = ref->GetComponentByRefHash<component>(value[0]);\
88else variable = obj->GetComponentByHash<component>(value[0]);\
89}
90
virtual void SetValue(std::string name_str, Arguments value)=0