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,38 @@
# Copyright (c) 2023 Dominic Msters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
project(uigen VERSION 1.0)
add_executable(uigen)
# Sources
target_sources(uigen
PRIVATE
${DAWN_SHARED_SOURCES}
${DAWN_TOOL_SOURCES}
UIGen.cpp
)
# Includes
target_include_directories(uigen
PUBLIC
${DAWN_SHARED_INCLUDES}
${DAWN_TOOL_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}
)
# Definitions
target_compile_definitions(uigen
PUBLIC
${DAWN_SHARED_DEFINITIONS}
DAWN_TOOL_INSTANCE=UIGen
DAWN_TOOL_HEADER="UIGen.hpp"
)
# Libraries
target_link_libraries(uigen
PUBLIC
${DAWN_BUILD_HOST_LIBS}
)

60
archive/uigen/UIGen.cpp Normal file
View File

@ -0,0 +1,60 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UIGen.hpp"
using namespace Dawn;
std::vector<std::string> UIGen::getRequiredFlags() {
return std::vector<std::string>{ "input", "output" };
}
int32_t UIGen::start() {
std::cout << "UI Gen tool is basically unfinished unfortunately" << std::endl;
return 1;
// Open input file.
File file(flags["input"]);
std::string buffer;
if(!file.readString(&buffer)) {
std::cout << "Failed to read " << file.filename << std::endl;
return 1;
}
// Parse XML
Xml xml = Xml::load(buffer);
std::string error;
struct RootInformation info;
auto ret = (RootParser()).parse(&xml, &info, &error);
if(ret != 0) {
std::cout << error << std::endl;
return ret;
}
std::vector<std::string> lines;
RootGen::generate(&lines, &info, "");
// Generate buffer
std::string bufferOut;
auto itLine = lines.begin();
while(itLine != lines.end()) {
bufferOut += *itLine + "\n";
++itLine;
}
// Finished with XML data, now we can write data out.
File fileOut(flags["output"] + ".hpp");
if(!fileOut.mkdirp()) {
std::cout << "Failed to make scene output dir" << std::endl;
return 1;
}
if(!fileOut.writeString(bufferOut)) {
std::cout << "Failed to generate scene " << fileOut.filename << std::endl;
return 1;
}
return 0;
}

20
archive/uigen/UIGen.hpp Normal file
View File

@ -0,0 +1,20 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/DawnTool.hpp"
#include "util/File.hpp"
#include "parse/root.hpp"
#include "util/Language.cpp"
namespace Dawn {
class UIGen : public DawnTool {
protected:
std::vector<std::string> getRequiredFlags() override;
public:
int32_t start();
};
}

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);
}
};
}