Just breaking stuff

This commit is contained in:
2023-03-14 22:27:46 -07:00
parent 795e69237c
commit 09cb20271b
156 changed files with 4218 additions and 4389 deletions

View File

@ -0,0 +1,67 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "label.hpp"
namespace Dawn {
struct ChildInfo;
struct ChildrenInfo {
std::vector<struct ChildInfo> children;
};
struct ChildInfo {
enum ChildType type;
struct ChildrenInfo children;
std::string ref;
bool_t hasRef = false;
struct LabelInfo label;
};
class ChildrenParser : public XmlParser<struct ChildrenInfo> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>();
}
std::map<std::string, std::string> getOptionalAttributes() {
return std::map<std::string, std::string>();
}
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct ChildrenInfo *out,
std::string *error
) {
// Parse children of self.
int32_t ret = 0;
auto itChildren = node->children.begin();
while(itChildren != node->children.end()) {
auto c = *itChildren;
struct ChildInfo child;
if(c->node == "label") {
child.type = CHILD_TYPE_LABEL;
ret = (LabelParser()).parse(c, &child.label, error);
} else {
*error = "Unrecognized UI Element " + c->node;
return 1;
}
if(ret != 0) return ret;
// Now Parse children of children
ret = (ChildrenParser()).parse(c, &child.children, error);
if(ret != 0) return ret;
++itChildren;
}
return ret;
}
};
}

View File

@ -0,0 +1,31 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
#include "util/CodeGen.hpp"
namespace Dawn {
enum AlignType {
UI_COMPONENT_ALIGN_START,
UI_COMPONENT_ALIGN_MIDDLE,
UI_COMPONENT_ALIGN_END,
UI_COMPONENT_ALIGN_STRETCH
};
struct Alignment {
float_t x0 = 0;
float_t y0 = 0;
float_t x1 = 0;
float_t y1 = 0;
enum AlignType xAlign = UI_COMPONENT_ALIGN_START;
enum AlignType yAlign = UI_COMPONENT_ALIGN_START;
};
enum ChildType {
CHILD_TYPE_LABEL
};
}

View File

@ -0,0 +1,46 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "common.hpp"
namespace Dawn {
struct LabelInfo {
std::string text = "";
std::string fontSize = "";
};
class LabelParser : public XmlParser<struct LabelInfo> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>();
}
std::map<std::string, std::string> getOptionalAttributes() {
return {
{ "fontSize", "" }
};
}
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct LabelInfo *out,
std::string *error
) {
int32_t ret = 0;
if(values["fontSize"].size() > 0) {
out->fontSize = values["fontSize"];
}
if(node->value.size() > 0) {
out->text = node->value;
}
return ret;
}
};
}

View File

@ -0,0 +1,83 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "parse/elements/children.hpp"
namespace Dawn {
struct RootInformation {
std::vector<std::string> includes;
struct ChildrenInfo children;
};
class RootParser : public XmlParser<struct RootInformation> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>();
}
std::map<std::string, std::string> getOptionalAttributes() {
return std::map<std::string, std::string>();
}
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct RootInformation *out,
std::string *error
) {
int32_t ret;
if(node->node != "root") {
*error = "Root node is of an invalid type";
return 1;
}
ret = (ChildrenParser()).parse(node, &out->children, error);
if(ret != 0) return ret;
return ret;
}
};
class RootGen : public CodeGen {
public:
static void generate(
std::vector<std::string> *out,
struct RootInformation *info,
std::string tabs = ""
) {
struct ClassGenInfo clazz;
clazz.clazz = "SimpleTestUI";
clazz.extend = "SceneItemPrefab<" + clazz.clazz + ">";
clazz.constructorArgs = "Scene *s, sceneitemid_t i";
clazz.extendArgs = "s, i";
clazz.includes.push_back("#include \"prefab/SceneItemPrefab.hpp\"");
// Assets
struct MethodGenInfo assetsInfo;
assetsInfo.name = "prefabAssets";
assetsInfo.isStatic = true;
assetsInfo.type = "std::vector<Asset*>";
assetsInfo.args = "AssetManager *ass";
line(&assetsInfo.body, "return {", "");
line(&assetsInfo.body, "};", "");
methodGen(&clazz.publicCode, assetsInfo);
line(&clazz.publicCode, "", "");
// Init
struct MethodGenInfo prefabInfo;
prefabInfo.name = "prefabInit";
prefabInfo.args = "AssetManager *ass";
prefabInfo.isOverride = true;
methodGen(&clazz.publicCode, prefabInfo);
classGen(out, clazz);
}
};
}