From 20575f17b4d02fe910a7593b0ed3eddc6509e222 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 13 Mar 2023 08:41:32 -0700 Subject: [PATCH] Progress --- assets/games/tictactoe/test.xml | 2 + src/dawntictactoe/CMakeLists.txt | 3 +- src/dawntools/tools/uigen/UIGen.cpp | 33 ++-- .../tools/uigen/parse/elements/children.hpp | 9 +- .../tools/uigen/parse/elements/common.hpp | 31 ++++ .../tools/uigen/parse/elements/label.hpp | 2 +- src/dawntools/tools/uigen/parse/root.hpp | 89 ++++------- src/dawntools/tools/vnscenegen/VnSceneGen.cpp | 118 +++++++------- src/dawntools/util/CodeGen.cpp | 148 +++++++++--------- 9 files changed, 223 insertions(+), 212 deletions(-) create mode 100644 src/dawntools/tools/uigen/parse/elements/common.hpp diff --git a/assets/games/tictactoe/test.xml b/assets/games/tictactoe/test.xml index e34d4901..50e5ea98 100644 --- a/assets/games/tictactoe/test.xml +++ b/assets/games/tictactoe/test.xml @@ -1,4 +1,6 @@ + + diff --git a/src/dawntictactoe/CMakeLists.txt b/src/dawntictactoe/CMakeLists.txt index 1635654a..387a9541 100644 --- a/src/dawntictactoe/CMakeLists.txt +++ b/src/dawntictactoe/CMakeLists.txt @@ -25,5 +25,4 @@ set(DIR_GAME_ASSETS games/tictactoe) tool_language(locale_en ${DIR_GAME_ASSETS}/locale/en.xml) tool_tileset(tileset_xo texture_xo ${DIR_GAME_ASSETS}/xo.png 1 4) -tool_truetype(truetype_bizudp ${DIR_GAME_ASSETS}/font/BIZUDPGothic-Bold.ttf truetype_bizudp 2048 2048 120) -tool_ui(ui_test ${DIR_GAME_ASSETS}/test.xml ui_test) \ No newline at end of file +tool_truetype(truetype_bizudp ${DIR_GAME_ASSETS}/font/BIZUDPGothic-Bold.ttf truetype_bizudp 2048 2048 120) \ No newline at end of file diff --git a/src/dawntools/tools/uigen/UIGen.cpp b/src/dawntools/tools/uigen/UIGen.cpp index 989e9c31..2d1550a1 100644 --- a/src/dawntools/tools/uigen/UIGen.cpp +++ b/src/dawntools/tools/uigen/UIGen.cpp @@ -12,6 +12,9 @@ std::vector UIGen::getRequiredFlags() { } 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; @@ -31,27 +34,27 @@ int32_t UIGen::start() { return ret; } - // std::vector lines; - // RootGen::generate(&lines, &info, ""); + std::vector lines; + RootGen::generate(&lines, &info, ""); - // // Generate buffer - // std::string bufferOut; - // auto itLine = lines.begin(); - // while(itLine != lines.end()) { - // bufferOut += *itLine + "\n"; - // ++itLine; - // } + // 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. + // Finished with XML data, now we can write data out. File fileOut(flags["output"] + ".hpp"); if(!fileOut.mkdirp()) { - std::cout << "Failed to make ui output dir" << std::endl; + 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; } - // if(!fileOut.writeString(bufferOut)) { - // std::cout << "Failed to generate scene " << fileOut.filename << std::endl; - // return 1; - // } return 0; } \ No newline at end of file diff --git a/src/dawntools/tools/uigen/parse/elements/children.hpp b/src/dawntools/tools/uigen/parse/elements/children.hpp index 4bfe42ba..f2a0a416 100644 --- a/src/dawntools/tools/uigen/parse/elements/children.hpp +++ b/src/dawntools/tools/uigen/parse/elements/children.hpp @@ -7,10 +7,6 @@ #include "label.hpp" namespace Dawn { - enum ChildType { - CHILD_TYPE_LABEL - }; - struct ChildInfo; struct ChildrenInfo { @@ -19,8 +15,10 @@ namespace Dawn { struct ChildInfo { enum ChildType type; - struct LabelInfo label; struct ChildrenInfo children; + std::string ref; + bool_t hasRef = false; + struct LabelInfo label; }; class ChildrenParser : public XmlParser { @@ -48,6 +46,7 @@ namespace Dawn { if(c->node == "label") { child.type = CHILD_TYPE_LABEL; + ret = (LabelParser()).parse(c, &child.label, error); } else { *error = "Unrecognized UI Element " + c->node; diff --git a/src/dawntools/tools/uigen/parse/elements/common.hpp b/src/dawntools/tools/uigen/parse/elements/common.hpp new file mode 100644 index 00000000..1a19c240 --- /dev/null +++ b/src/dawntools/tools/uigen/parse/elements/common.hpp @@ -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 + }; +} \ No newline at end of file diff --git a/src/dawntools/tools/uigen/parse/elements/label.hpp b/src/dawntools/tools/uigen/parse/elements/label.hpp index f82e0f31..00b87f34 100644 --- a/src/dawntools/tools/uigen/parse/elements/label.hpp +++ b/src/dawntools/tools/uigen/parse/elements/label.hpp @@ -4,7 +4,7 @@ // https://opensource.org/licenses/MIT #pragma once -#include "util/XmlParser.hpp" +#include "common.hpp" namespace Dawn { struct LabelInfo { diff --git a/src/dawntools/tools/uigen/parse/root.hpp b/src/dawntools/tools/uigen/parse/root.hpp index 35701c72..02ecec65 100644 --- a/src/dawntools/tools/uigen/parse/root.hpp +++ b/src/dawntools/tools/uigen/parse/root.hpp @@ -41,66 +41,43 @@ namespace Dawn { } }; - // class RootGen : public CodeGen { - // public: - // static void generate( - // std::vector *out, - // struct RootInformation *info, - // std::string tabs = "" - // ) { - // struct ClassGenInfo c; - // c.clazz = info->header.scene.name; - // c.extend = info->header.scene.type; - // c.constructorArgs = "DawnGame *game"; - // c.extendArgs = "game"; + class RootGen : public CodeGen { + public: + static void generate( + std::vector *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\""); - // struct MethodGenInfo vnStage; - // vnStage.name = "vnStage"; - // vnStage.type = "void"; - // vnStage.isOverride = true; - // line(&vnStage.body, info->header.scene.type+ "::vnStage();", ""); + // Assets + struct MethodGenInfo assetsInfo; + assetsInfo.name = "prefabAssets"; + assetsInfo.isStatic = true; + assetsInfo.type = "std::vector"; + assetsInfo.args = "AssetManager *ass"; + line(&assetsInfo.body, "return {", ""); - // struct MethodGenInfo getAssets; - // getAssets.name = "getRequiredAssets"; - // getAssets.type = "std::vector"; - // getAssets.isOverride = true; - // line(&getAssets.body, "auto man = &this->game->assetManager;", ""); - // line(&getAssets.body, "auto assets = " + info->header.scene.type + "::getRequiredAssets();", ""); + line(&assetsInfo.body, "};", ""); + methodGen(&clazz.publicCode, assetsInfo); - // struct MethodGenInfo getVNEvent; - // getVNEvent.name = "getVNEvent"; - // getVNEvent.type = "IVisualNovelEvent *"; - // getVNEvent.isOverride = true; - // line(&getVNEvent.body, "auto start = new VisualNovelEmptyEvent(vnManager);", ""); + line(&clazz.publicCode, "", ""); - // IncludeGen::generate(&c.includes, info->header.includes, ""); - // IncludeGen::generate(&c.includes, info->events.includes, ""); + // Init + struct MethodGenInfo prefabInfo; + prefabInfo.name = "prefabInit"; + prefabInfo.args = "AssetManager *ass"; + prefabInfo.isOverride = true; + + methodGen(&clazz.publicCode, prefabInfo); - // // Characters - // auto itChar = info->header.characters.begin(); - // while(itChar != info->header.characters.end()) { - // CharacterGen::generateProperty(&c.publicProperties, *itChar, ""); - // CharacterGen::generateInitializer(&vnStage.body, *itChar, ""); - // CharacterGen::generateAssets(&getAssets.body, *itChar, ""); - // ++itChar; - // } - // // Events - // if(info->events.eventTypes.size() > 0) { - // line(&getVNEvent.body, "start", ""); - // EventsGen::generate(&getVNEvent.body, &info->events, " "); - // line(&getVNEvent.body, ";", ""); - // } - - // // Wrap up methods - // line(&getAssets.body, "return assets;", ""); - // line(&getVNEvent.body, "return start;", ""); - - // methodGen(&c.publicCode, vnStage); - // line(&c.publicCode, "", ""); - // methodGen(&c.publicCode, getAssets); - // methodGen(&c.publicCode, getVNEvent); - // classGen(out, c); - // } - // }; + classGen(out, clazz); + } + }; } \ No newline at end of file diff --git a/src/dawntools/tools/vnscenegen/VnSceneGen.cpp b/src/dawntools/tools/vnscenegen/VnSceneGen.cpp index ffb5eebc..74c993e0 100644 --- a/src/dawntools/tools/vnscenegen/VnSceneGen.cpp +++ b/src/dawntools/tools/vnscenegen/VnSceneGen.cpp @@ -1,60 +1,60 @@ -// Copyright (c) 2023 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "VnSceneGen.hpp" - -using namespace Dawn; - -std::vector VnSceneGen::getRequiredFlags() { - return std::vector{ "input", "output", "language-out" }; -} - -int32_t VnSceneGen::start() { - // Open input file. - File file(flags["input"]); - std::string buffer; - if(!file.readString(&buffer)) { - std::cout << "Failed to read scene " << 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 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; - } - - // Now dump out the language strings to be picked up later. - ret = languageSaveStrings(flags["language-out"], info.strings); - if(ret != 0) return ret; - - return 0; +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "VnSceneGen.hpp" + +using namespace Dawn; + +std::vector VnSceneGen::getRequiredFlags() { + return std::vector{ "input", "output", "language-out" }; +} + +int32_t VnSceneGen::start() { + // Open input file. + File file(flags["input"]); + std::string buffer; + if(!file.readString(&buffer)) { + std::cout << "Failed to read scene " << 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 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; + } + + // Now dump out the language strings to be picked up later. + ret = languageSaveStrings(flags["language-out"], info.strings); + if(ret != 0) return ret; + + return 0; } \ No newline at end of file diff --git a/src/dawntools/util/CodeGen.cpp b/src/dawntools/util/CodeGen.cpp index 2f5d5bac..1e98c9d8 100644 --- a/src/dawntools/util/CodeGen.cpp +++ b/src/dawntools/util/CodeGen.cpp @@ -1,75 +1,75 @@ -// Copyright (c) 2023 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "CodeGen.hpp" - -using namespace Dawn; - -void CodeGen::line( - std::vector *out, - std::string contents, - std::string tabs -) { - out->push_back(tabs + contents); -} - -void CodeGen::lines( - std::vector *out, - std::vector lines, - std::string tabs -) { - auto itLine = lines.begin(); - while(itLine != lines.end()) { - line(out, *itLine, tabs); - ++itLine; - } -} - -void CodeGen::classGen( - std::vector *out, - struct ClassGenInfo info -) { - std::vector buffer; - - line(out, "#pragma once", ""); - line(out, "", ""); - if(info.includes.size() > 0) { - lines(out, info.includes, ""); - line(out, "", ""); - } - line(out, "namespace Dawn {", ""); - line(out, "class " + info.clazz + (info.extend.size() == 0 ? "{" : " : public " + info.extend + " {" ), " "); - if(info.protectedCode.size() > 0) { - line(out, "protected:", " "); - lines(out, info.protectedProperties, " "); - line(out, "", " "); - lines(out, info.protectedCode, " "); - } - - if(info.publicCode.size() > 0 || info.constructorArgs.size() > 0 || info.constructorCode.size() > 0) { - line(out, "public:", " "); - lines(out, info.publicProperties, " "); - line(out, "", " "); - line(out, info.clazz + "(" + info.constructorArgs + ")" + (info.extend.size() > 0 ? " : " + info.extend + "(" + info.extendArgs + ")" : "") + " {", " "); - lines(out, info.constructorCode, " "); - line(out, "}", " "); - if(info.publicCode.size() > 0) { - line(out, "", " "); - lines(out, info.publicCode, " "); - } - } - line(out, "};", " "); - line(out, "}", ""); -} - - -void CodeGen::methodGen( - std::vector *out, - struct MethodGenInfo info -) { - line(out, info.type + " " + info.name + "(" + info.args + ") " + ( info.isOverride ? "override" : "" ) + "{", ""); - lines(out, info.body, " "); - line(out, "}", ""); +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "CodeGen.hpp" + +using namespace Dawn; + +void CodeGen::line( + std::vector *out, + std::string contents, + std::string tabs +) { + out->push_back(tabs + contents); +} + +void CodeGen::lines( + std::vector *out, + std::vector lines, + std::string tabs +) { + auto itLine = lines.begin(); + while(itLine != lines.end()) { + line(out, *itLine, tabs); + ++itLine; + } +} + +void CodeGen::classGen( + std::vector *out, + struct ClassGenInfo info +) { + std::vector buffer; + + line(out, "#pragma once", ""); + line(out, "", ""); + if(info.includes.size() > 0) { + lines(out, info.includes, ""); + line(out, "", ""); + } + line(out, "namespace Dawn {", ""); + line(out, "class " + info.clazz + (info.extend.size() == 0 ? "{" : " : public " + info.extend + " {" ), " "); + if(info.protectedCode.size() > 0) { + line(out, "protected:", " "); + lines(out, info.protectedProperties, " "); + line(out, "", " "); + lines(out, info.protectedCode, " "); + } + + if(info.publicCode.size() > 0 || info.constructorArgs.size() > 0 || info.constructorCode.size() > 0) { + line(out, "public:", " "); + lines(out, info.publicProperties, " "); + line(out, "", " "); + line(out, info.clazz + "(" + info.constructorArgs + ")" + (info.extend.size() > 0 ? " : " + info.extend + "(" + info.extendArgs + ")" : "") + " {", " "); + lines(out, info.constructorCode, " "); + line(out, "}", " "); + if(info.publicCode.size() > 0) { + line(out, "", " "); + lines(out, info.publicCode, " "); + } + } + line(out, "};", " "); + line(out, "}", ""); +} + + +void CodeGen::methodGen( + std::vector *out, + struct MethodGenInfo info +) { + line(out, (info.isStatic ? "static " : "") + info.type + " " + info.name + "(" + info.args + ") " + ( info.isOverride ? "override " : "" ) + "{", ""); + lines(out, info.body, " "); + line(out, "}", ""); } \ No newline at end of file