This commit is contained in:
2023-03-13 08:41:32 -07:00
parent f6a368eed5
commit 20575f17b4
9 changed files with 223 additions and 212 deletions

View File

@ -1,4 +1,6 @@
<root> <root>
<prefab name="label" type="SimpleLabel" path="prefabs/SimpleLabel.hpp" />
<label> <label>
Hello World! Hello World!
</label> </label>

View File

@ -25,5 +25,4 @@ set(DIR_GAME_ASSETS games/tictactoe)
tool_language(locale_en ${DIR_GAME_ASSETS}/locale/en.xml) tool_language(locale_en ${DIR_GAME_ASSETS}/locale/en.xml)
tool_tileset(tileset_xo texture_xo ${DIR_GAME_ASSETS}/xo.png 1 4) 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_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)

View File

@ -12,6 +12,9 @@ std::vector<std::string> UIGen::getRequiredFlags() {
} }
int32_t UIGen::start() { int32_t UIGen::start() {
std::cout << "UI Gen tool is basically unfinished unfortunately" << std::endl;
return 1;
// Open input file. // Open input file.
File file(flags["input"]); File file(flags["input"]);
std::string buffer; std::string buffer;
@ -31,27 +34,27 @@ int32_t UIGen::start() {
return ret; return ret;
} }
// std::vector<std::string> lines; std::vector<std::string> lines;
// RootGen::generate(&lines, &info, ""); RootGen::generate(&lines, &info, "");
// // Generate buffer // Generate buffer
// std::string bufferOut; std::string bufferOut;
// auto itLine = lines.begin(); auto itLine = lines.begin();
// while(itLine != lines.end()) { while(itLine != lines.end()) {
// bufferOut += *itLine + "\n"; bufferOut += *itLine + "\n";
// ++itLine; ++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"); File fileOut(flags["output"] + ".hpp");
if(!fileOut.mkdirp()) { 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; return 1;
} }
// if(!fileOut.writeString(bufferOut)) {
// std::cout << "Failed to generate scene " << fileOut.filename << std::endl;
// return 1;
// }
return 0; return 0;
} }

View File

@ -7,10 +7,6 @@
#include "label.hpp" #include "label.hpp"
namespace Dawn { namespace Dawn {
enum ChildType {
CHILD_TYPE_LABEL
};
struct ChildInfo; struct ChildInfo;
struct ChildrenInfo { struct ChildrenInfo {
@ -19,8 +15,10 @@ namespace Dawn {
struct ChildInfo { struct ChildInfo {
enum ChildType type; enum ChildType type;
struct LabelInfo label;
struct ChildrenInfo children; struct ChildrenInfo children;
std::string ref;
bool_t hasRef = false;
struct LabelInfo label;
}; };
class ChildrenParser : public XmlParser<struct ChildrenInfo> { class ChildrenParser : public XmlParser<struct ChildrenInfo> {
@ -48,6 +46,7 @@ namespace Dawn {
if(c->node == "label") { if(c->node == "label") {
child.type = CHILD_TYPE_LABEL; child.type = CHILD_TYPE_LABEL;
ret = (LabelParser()).parse(c, &child.label, error); ret = (LabelParser()).parse(c, &child.label, error);
} else { } else {
*error = "Unrecognized UI Element " + c->node; *error = "Unrecognized UI Element " + c->node;

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

@ -4,7 +4,7 @@
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "util/XmlParser.hpp" #include "common.hpp"
namespace Dawn { namespace Dawn {
struct LabelInfo { struct LabelInfo {

View File

@ -41,66 +41,43 @@ namespace Dawn {
} }
}; };
// class RootGen : public CodeGen { class RootGen : public CodeGen {
// public: public:
// static void generate( static void generate(
// std::vector<std::string> *out, std::vector<std::string> *out,
// struct RootInformation *info, struct RootInformation *info,
// std::string tabs = "" std::string tabs = ""
// ) { ) {
// struct ClassGenInfo c; struct ClassGenInfo clazz;
// c.clazz = info->header.scene.name; clazz.clazz = "SimpleTestUI";
// c.extend = info->header.scene.type; clazz.extend = "SceneItemPrefab<" + clazz.clazz + ">";
// c.constructorArgs = "DawnGame *game"; clazz.constructorArgs = "Scene *s, sceneitemid_t i";
// c.extendArgs = "game"; clazz.extendArgs = "s, i";
clazz.includes.push_back("#include \"prefab/SceneItemPrefab.hpp\"");
// struct MethodGenInfo vnStage; // Assets
// vnStage.name = "vnStage"; struct MethodGenInfo assetsInfo;
// vnStage.type = "void"; assetsInfo.name = "prefabAssets";
// vnStage.isOverride = true; assetsInfo.isStatic = true;
// line(&vnStage.body, info->header.scene.type+ "::vnStage();", ""); assetsInfo.type = "std::vector<Asset*>";
assetsInfo.args = "AssetManager *ass";
line(&assetsInfo.body, "return {", "");
// struct MethodGenInfo getAssets; line(&assetsInfo.body, "};", "");
// getAssets.name = "getRequiredAssets"; methodGen(&clazz.publicCode, assetsInfo);
// getAssets.type = "std::vector<Asset*>";
// getAssets.isOverride = true;
// line(&getAssets.body, "auto man = &this->game->assetManager;", "");
// line(&getAssets.body, "auto assets = " + info->header.scene.type + "::getRequiredAssets();", "");
// struct MethodGenInfo getVNEvent; line(&clazz.publicCode, "", "");
// getVNEvent.name = "getVNEvent";
// getVNEvent.type = "IVisualNovelEvent *";
// getVNEvent.isOverride = true;
// line(&getVNEvent.body, "auto start = new VisualNovelEmptyEvent(vnManager);", "");
// IncludeGen::generate(&c.includes, info->header.includes, ""); // Init
// IncludeGen::generate(&c.includes, info->events.includes, ""); 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 classGen(out, clazz);
// 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);
// }
// };
} }

View File

@ -1,60 +1,60 @@
// Copyright (c) 2023 Dominic Masters // Copyright (c) 2023 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#include "VnSceneGen.hpp" #include "VnSceneGen.hpp"
using namespace Dawn; using namespace Dawn;
std::vector<std::string> VnSceneGen::getRequiredFlags() { std::vector<std::string> VnSceneGen::getRequiredFlags() {
return std::vector<std::string>{ "input", "output", "language-out" }; return std::vector<std::string>{ "input", "output", "language-out" };
} }
int32_t VnSceneGen::start() { int32_t VnSceneGen::start() {
// Open input file. // Open input file.
File file(flags["input"]); File file(flags["input"]);
std::string buffer; std::string buffer;
if(!file.readString(&buffer)) { if(!file.readString(&buffer)) {
std::cout << "Failed to read scene " << file.filename << std::endl; std::cout << "Failed to read scene " << file.filename << std::endl;
return 1; return 1;
} }
// Parse XML // Parse XML
Xml xml = Xml::load(buffer); Xml xml = Xml::load(buffer);
std::string error; std::string error;
struct RootInformation info; struct RootInformation info;
auto ret = (RootParser()).parse(&xml, &info, &error); auto ret = (RootParser()).parse(&xml, &info, &error);
if(ret != 0) { if(ret != 0) {
std::cout << error << std::endl; std::cout << error << std::endl;
return ret; return ret;
} }
std::vector<std::string> lines; std::vector<std::string> lines;
RootGen::generate(&lines, &info, ""); RootGen::generate(&lines, &info, "");
// Generate buffer // Generate buffer
std::string bufferOut; std::string bufferOut;
auto itLine = lines.begin(); auto itLine = lines.begin();
while(itLine != lines.end()) { while(itLine != lines.end()) {
bufferOut += *itLine + "\n"; bufferOut += *itLine + "\n";
++itLine; ++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"); File fileOut(flags["output"] + ".hpp");
if(!fileOut.mkdirp()) { if(!fileOut.mkdirp()) {
std::cout << "Failed to make scene output dir" << std::endl; std::cout << "Failed to make scene output dir" << std::endl;
return 1; return 1;
} }
if(!fileOut.writeString(bufferOut)) { if(!fileOut.writeString(bufferOut)) {
std::cout << "Failed to generate scene " << fileOut.filename << std::endl; std::cout << "Failed to generate scene " << fileOut.filename << std::endl;
return 1; return 1;
} }
// Now dump out the language strings to be picked up later. // Now dump out the language strings to be picked up later.
ret = languageSaveStrings(flags["language-out"], info.strings); ret = languageSaveStrings(flags["language-out"], info.strings);
if(ret != 0) return ret; if(ret != 0) return ret;
return 0; return 0;
} }

View File

@ -1,75 +1,75 @@
// Copyright (c) 2023 Dominic Masters // Copyright (c) 2023 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#include "CodeGen.hpp" #include "CodeGen.hpp"
using namespace Dawn; using namespace Dawn;
void CodeGen::line( void CodeGen::line(
std::vector<std::string> *out, std::vector<std::string> *out,
std::string contents, std::string contents,
std::string tabs std::string tabs
) { ) {
out->push_back(tabs + contents); out->push_back(tabs + contents);
} }
void CodeGen::lines( void CodeGen::lines(
std::vector<std::string> *out, std::vector<std::string> *out,
std::vector<std::string> lines, std::vector<std::string> lines,
std::string tabs std::string tabs
) { ) {
auto itLine = lines.begin(); auto itLine = lines.begin();
while(itLine != lines.end()) { while(itLine != lines.end()) {
line(out, *itLine, tabs); line(out, *itLine, tabs);
++itLine; ++itLine;
} }
} }
void CodeGen::classGen( void CodeGen::classGen(
std::vector<std::string> *out, std::vector<std::string> *out,
struct ClassGenInfo info struct ClassGenInfo info
) { ) {
std::vector<std::string> buffer; std::vector<std::string> buffer;
line(out, "#pragma once", ""); line(out, "#pragma once", "");
line(out, "", ""); line(out, "", "");
if(info.includes.size() > 0) { if(info.includes.size() > 0) {
lines(out, info.includes, ""); lines(out, info.includes, "");
line(out, "", ""); line(out, "", "");
} }
line(out, "namespace Dawn {", ""); line(out, "namespace Dawn {", "");
line(out, "class " + info.clazz + (info.extend.size() == 0 ? "{" : " : public " + info.extend + " {" ), " "); line(out, "class " + info.clazz + (info.extend.size() == 0 ? "{" : " : public " + info.extend + " {" ), " ");
if(info.protectedCode.size() > 0) { if(info.protectedCode.size() > 0) {
line(out, "protected:", " "); line(out, "protected:", " ");
lines(out, info.protectedProperties, " "); lines(out, info.protectedProperties, " ");
line(out, "", " "); line(out, "", " ");
lines(out, info.protectedCode, " "); lines(out, info.protectedCode, " ");
} }
if(info.publicCode.size() > 0 || info.constructorArgs.size() > 0 || info.constructorCode.size() > 0) { if(info.publicCode.size() > 0 || info.constructorArgs.size() > 0 || info.constructorCode.size() > 0) {
line(out, "public:", " "); line(out, "public:", " ");
lines(out, info.publicProperties, " "); lines(out, info.publicProperties, " ");
line(out, "", " "); line(out, "", " ");
line(out, info.clazz + "(" + info.constructorArgs + ")" + (info.extend.size() > 0 ? " : " + info.extend + "(" + info.extendArgs + ")" : "") + " {", " "); line(out, info.clazz + "(" + info.constructorArgs + ")" + (info.extend.size() > 0 ? " : " + info.extend + "(" + info.extendArgs + ")" : "") + " {", " ");
lines(out, info.constructorCode, " "); lines(out, info.constructorCode, " ");
line(out, "}", " "); line(out, "}", " ");
if(info.publicCode.size() > 0) { if(info.publicCode.size() > 0) {
line(out, "", " "); line(out, "", " ");
lines(out, info.publicCode, " "); lines(out, info.publicCode, " ");
} }
} }
line(out, "};", " "); line(out, "};", " ");
line(out, "}", ""); line(out, "}", "");
} }
void CodeGen::methodGen( void CodeGen::methodGen(
std::vector<std::string> *out, std::vector<std::string> *out,
struct MethodGenInfo info struct MethodGenInfo info
) { ) {
line(out, info.type + " " + info.name + "(" + info.args + ") " + ( info.isOverride ? "override" : "" ) + "{", ""); line(out, (info.isStatic ? "static " : "") + info.type + " " + info.name + "(" + info.args + ") " + ( info.isOverride ? "override " : "" ) + "{", "");
lines(out, info.body, " "); lines(out, info.body, " ");
line(out, "}", ""); line(out, "}", "");
} }