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:
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;\
30result += std::string("<value name=\"") + #variable + "\">" + appandAll(temp, __VA_ARGS__) + "</value>\n";}
31#define PRINT_VALUE_SPREFAB_REF(variable) {const auto& obj = variable->GetGameObject();\
32const auto& ref = dynamic_cast<SGameObjectFromSPrefab*>(variable->GetGameObject());\
33std::stringstream temp;\
34result += std::string("<value name=\"") + #variable + "\" ref=\"" + \
35(ref == nullptr ? "0" : "1") + "\">" +\
36appandAll(temp, (ref == nullptr ? obj->GetID(variable) : ref->GetRefID(variable))) + "</value>\n";\
37 }
38#define PRINT_VALUE_MAT4(variable) {\
39mat4 m = variable;\
40PRINT_VALUE(variable, m.x.x, ' ', m.x.y, ' ', m.x.z, ' ', m.x.w, ' ',\
41m.y.x, ' ', m.y.y, ' ', m.y.z, ' ', m.y.w, ' ',\
42m.z.x, ' ', m.z.y, ' ', m.z.z, ' ', m.z.w, ' ',\
43m.w.x, ' ', m.w.y, ' ', m.w.z, ' ', m.w.w);}
44#define PRINT_VALUE_VEC3(variable) {\
45vec3 v = variable;\
46PRINT_VALUE(variable, v.x, ' ', v.y, ' ', v.z);}
47#define PRINT_VALUE_VEC4(variable) {\
48vec4 v = variable;\
49PRINT_VALUE(variable, v.x, ' ', v.y, ' ', v.z, ' ', v.w);}
50
51#define SET_VEC3(variable) {vec3 vec = vec3();\
52vec.Set(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]));\
53variable = std::move(vec);}
54#define SET_VEC4(variable) {vec4 vec = vec4();\
55vec.Set(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]), std::stof(value[3]));\
56variable = std::move(vec);}
57#define SET_MAT4(variable) {mat4 mat = mat4();\
58mat.x.Set(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]), std::stof(value[3]));\
59mat.y.Set(std::stof(value[4]), std::stof(value[5]), std::stof(value[6]), std::stof(value[7]));\
60mat.z.Set(std::stof(value[8]), std::stof(value[9]), std::stof(value[10]), std::stof(value[11]));\
61mat.w.Set(std::stof(value[12]), std::stof(value[13]), std::stof(value[14]), std::stof(value[15]));\
62variable = std::move(mat);}
63#define SET_SPREFAB_REF(variable, component) {\
64const auto& ref = dynamic_cast<SGameObjectFromSPrefab*>(variable->GetGameObject()); \
65const auto& obj = variable->GetGameObject();\
66if (ref != nullptr) variable = ref->GetComponentByRefHash<component>(value[0]);\
67else variable = obj->GetComponentByHash<component>(value[0]);\
68}
69