4#include "../../MoreComponentFunc.h"
5#include "../../../Manager/GameObjectMgr.h"
6#include "../../Render/SFrameBuffer.h"
7#include "../../Render/SMaterial.h"
8#include "../../Render/STexture.h"
12void XMLParser::parse(std::vector<std::string> values,
void* dst, SType type) {
13 if (type == SType::STRING) dst = (
void*) values[0].c_str();
14 else if (type == SType::BOOL) *
static_cast<bool*
>(dst) = parseBool(values[0].c_str());
15 else if (type == SType::FLOAT) *
static_cast<float*
>(dst) = parseFloat(values[0].c_str());
16 else if (type == SType::INT) *
static_cast<int*
>(dst) = parseInt(values[0].c_str());
19 else if (type == SType::RESOURCE) dst = (
void*) parseResources<SResource>(values[0].c_str());
20 else if (type == SType::MATERIAL) dst = (
void*) parseMaterial(values[0].c_str());
21 else if (type == SType::TEXTURE) {
22 dst = (
void*) parseTexture(values[0].c_str());
23 if (dst ==
nullptr) dst = (
void*) parseFrameBuffer(values[0].c_str());
24 }
else if (type == SType::COMPONENT) dst = (
void*) parseComponent(values[0].c_str());
25 else if (type == SType::GAME_OBJECT) dst = (
void*) parseGameObject(values[0].c_str());
27 else if (type == SType::VEC2) *
static_cast<vec2*
>(dst) = parseVec2(values);
28 else if (type == SType::VEC3) *
static_cast<vec3*
>(dst) = parseVec3(values);
29 else if (type == SType::VEC4) *
static_cast<vec4*
>(dst) = parseVec4(values);
36int XMLParser::parseInt(
const char* value) {
37 return std::stoi(value);
40float XMLParser::parseFloat(
const char* value) {
41 return std::stof(value);
44bool XMLParser::parseBool(
const char* value) {
45 return strncmp(value,
"t", 1);
48vec2 XMLParser::parseVec2(std::vector<std::string> values) {
49 return {std::stof(values[0]), std::stof(values[1])};
52vec3 XMLParser::parseVec3(std::vector<std::string> values) {
53 return {std::stof(values[0]), std::stof(values[1]), std::stof(values[2])};
56vec4 XMLParser::parseVec4(std::vector<std::string> values) {
57 return {std::stof(values[0]), std::stof(values[1]), std::stof(values[2]), std::stof(values[3])};
60STexture* XMLParser::parseTexture(
const char* value) {
61 const auto& asset = CORE->GetCore(
ResMgr)->GetAssetReference(value);
62 if (asset ==
nullptr || asset->type == AssetMgr::FRAMEBUFFER) {
63 const auto value_split = split(value,
'?');
64 if (value_split.size() <= 1)
65 return SResource::Create<STexture>(value);
67 const auto& frameBuffer = SResource::Create<SFrameBuffer>(value_split[0]);
68 return frameBuffer->GetTexture(value);
70 return SResource::Create<STexture>(value);
73SFrameBuffer* XMLParser::parseFrameBuffer(
const char* value) {
74 std::string value_result = value;
75 const auto split_index = value_result.rfind(
'?');
76 if (split_index != std::string::npos)
77 value_result = value_result.substr(0, split_index - 1);
79 const auto& asset = CORE->GetCore(
ResMgr)->GetAssetReference(value_result);
80 if (asset->type != AssetMgr::FRAMEBUFFER) {
83 return SResource::Create<SFrameBuffer>(asset);
86SMaterial* XMLParser::parseMaterial(
const char* value) {
87 return SResource::Create<SMaterial>(value);
90SComponent* XMLParser::parseComponent(
const char* value) {
95SGameObject* XMLParser::parseGameObject(
const char* value) {
100SType XMLParser::GetType(std::string type) {
101 static const std::unordered_map<std::string, SType> typeMap = {
102 {
"str", SType::STRING},
103 {
"bool", SType::BOOL},
104 {
"float", SType::FLOAT},
106 {
"res", SType::RESOURCE},
107 {
"tex", SType::TEXTURE},
108 {
"mat", SType::MATERIAL},
109 {
"comp", SType::COMPONENT},
110 {
"gobj", SType::GAME_OBJECT},
111 {
"vec2", SType::VEC2},
112 {
"vec3", SType::VEC3},
113 {
"vec4", SType::VEC4},
114 {
"mat2", SType::MAT2},
115 {
"mat3", SType::MAT3},
116 {
"mat4", SType::MAT4}
119 auto it = typeMap.find(type);
120 if (it != typeMap.end()) {
123 return SType::UNKNOWN;
127SType XMLParser::GetType(
unsigned int type) {
129 case GL_BOOL:
return SType::BOOL;
130 case GL_FLOAT:
return SType::FLOAT;
131 case GL_INT:
return SType::INT;
132 case GL_SAMPLER_2D:
return SType::TEXTURE;
133 case GL_FLOAT_VEC2:
return SType::VEC2;
134 case GL_FLOAT_VEC3:
return SType::VEC3;
135 case GL_FLOAT_VEC4:
return SType::VEC4;
136 case GL_FLOAT_MAT2:
return SType::MAT2;
137 case GL_FLOAT_MAT3:
return SType::MAT3;
138 case GL_FLOAT_MAT4:
return SType::MAT4;
139 default:
return SType::UNKNOWN;
143std::string XMLParser::ToString(SType type) {
145 case SType::STRING:
return "str";
146 case SType::BOOL:
return "bool";
147 case SType::FLOAT:
return "float";
148 case SType::INT:
return "int";
149 case SType::RESOURCE:
return "res";
150 case SType::TEXTURE:
return "tex";
151 case SType::MATERIAL:
return "mat";
152 case SType::COMPONENT:
return "comp";
153 case SType::GAME_OBJECT:
return "gobj";
154 case SType::VEC2:
return "vec2";
155 case SType::VEC3:
return "vec3";
156 case SType::VEC4:
return "vec4";
157 case SType::MAT2:
return "mat2";
158 case SType::MAT3:
return "mat3";
159 case SType::MAT4:
return "mat4";
160 default:
return "str";