Progress
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
<root>
|
||||
<prefab name="label" type="SimpleLabel" path="prefabs/SimpleLabel.hpp" />
|
||||
|
||||
<label>
|
||||
Hello World!
|
||||
</label>
|
||||
|
@ -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)
|
||||
tool_truetype(truetype_bizudp ${DIR_GAME_ASSETS}/font/BIZUDPGothic-Bold.ttf truetype_bizudp 2048 2048 120)
|
@ -12,6 +12,9 @@ std::vector<std::string> 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<std::string> lines;
|
||||
// RootGen::generate(&lines, &info, "");
|
||||
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;
|
||||
// }
|
||||
// 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;
|
||||
}
|
@ -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<struct ChildrenInfo> {
|
||||
@ -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;
|
||||
|
31
src/dawntools/tools/uigen/parse/elements/common.hpp
Normal file
31
src/dawntools/tools/uigen/parse/elements/common.hpp
Normal 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
|
||||
};
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/XmlParser.hpp"
|
||||
#include "common.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct LabelInfo {
|
||||
|
@ -41,66 +41,43 @@ namespace Dawn {
|
||||
}
|
||||
};
|
||||
|
||||
// class RootGen : public CodeGen {
|
||||
// public:
|
||||
// static void generate(
|
||||
// std::vector<std::string> *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<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\"");
|
||||
|
||||
// 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<Asset*>";
|
||||
assetsInfo.args = "AssetManager *ass";
|
||||
line(&assetsInfo.body, "return {", "");
|
||||
|
||||
// struct MethodGenInfo getAssets;
|
||||
// getAssets.name = "getRequiredAssets";
|
||||
// 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();", "");
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
@ -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<std::string> VnSceneGen::getRequiredFlags() {
|
||||
return std::vector<std::string>{ "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<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;
|
||||
}
|
||||
|
||||
// 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<std::string> VnSceneGen::getRequiredFlags() {
|
||||
return std::vector<std::string>{ "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<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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
@ -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<std::string> *out,
|
||||
std::string contents,
|
||||
std::string tabs
|
||||
) {
|
||||
out->push_back(tabs + contents);
|
||||
}
|
||||
|
||||
void CodeGen::lines(
|
||||
std::vector<std::string> *out,
|
||||
std::vector<std::string> lines,
|
||||
std::string tabs
|
||||
) {
|
||||
auto itLine = lines.begin();
|
||||
while(itLine != lines.end()) {
|
||||
line(out, *itLine, tabs);
|
||||
++itLine;
|
||||
}
|
||||
}
|
||||
|
||||
void CodeGen::classGen(
|
||||
std::vector<std::string> *out,
|
||||
struct ClassGenInfo info
|
||||
) {
|
||||
std::vector<std::string> 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<std::string> *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<std::string> *out,
|
||||
std::string contents,
|
||||
std::string tabs
|
||||
) {
|
||||
out->push_back(tabs + contents);
|
||||
}
|
||||
|
||||
void CodeGen::lines(
|
||||
std::vector<std::string> *out,
|
||||
std::vector<std::string> lines,
|
||||
std::string tabs
|
||||
) {
|
||||
auto itLine = lines.begin();
|
||||
while(itLine != lines.end()) {
|
||||
line(out, *itLine, tabs);
|
||||
++itLine;
|
||||
}
|
||||
}
|
||||
|
||||
void CodeGen::classGen(
|
||||
std::vector<std::string> *out,
|
||||
struct ClassGenInfo info
|
||||
) {
|
||||
std::vector<std::string> 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<std::string> *out,
|
||||
struct MethodGenInfo info
|
||||
) {
|
||||
line(out, (info.isStatic ? "static " : "") + info.type + " " + info.name + "(" + info.args + ") " + ( info.isOverride ? "override " : "" ) + "{", "");
|
||||
lines(out, info.body, " ");
|
||||
line(out, "}", "");
|
||||
}
|
Reference in New Issue
Block a user