Just breaking stuff

This commit is contained in:
2023-03-14 22:27:46 -07:00
parent 374ae30b88
commit cc7091717c
156 changed files with 1156 additions and 5683 deletions

View File

@ -6,10 +6,8 @@
add_subdirectory(texturegen)
add_subdirectory(tilesetgen)
add_subdirectory(truetypegen)
add_subdirectory(uigen)
add_subdirectory(languagegen)
add_subdirectory(generatedlanguages)
add_subdirectory(sceneitemcomponentregister)
# Settings
set(DAWN_TOOL_GENERATED_LANG_DIR "${DAWN_TEMP_DIR}/languages" CACHE INTERNAL ${DAWN_CACHE_TARGET})
@ -106,38 +104,6 @@ if(DAWN_TARGET_OPENAL)
endfunction()
endif()
# Scene Item Component Tool
function(tool_scenecomponent clazz hfile)
# add_custom_target(${clazz}_scenecomponent
# COMMENT "Registering component ${hfile}::${clazz}"
# DEPENDS ${ARGN}
# )
# set(
# DAWN_SCENE_ITEM_COMPONENT_LIST
# ${DAWN_SCENE_ITEM_COMPONENT_LIST}
# ${clazz}
# ${hfile}
# CACHE INTERNAL ${DAWN_CACHE_TARGET}
# )
# file(CONFIGURE OUTPUT
# "${DAWN_TEMP_DIR}/SceneItemComponents.txt"
# CONTENT "${DAWN_SCENE_ITEM_COMPONENT_LIST}"
# )
# if(NOT TARGET sceneitemcomponentgen_cmd)
# add_custom_target(sceneitemcomponentgen_cmd
# COMMAND sceneitemcomponentgen --input="${DAWN_TEMP_DIR}/SceneItemComponents.txt" --output="${DAWN_GENERATED_DIR}/scene/SceneItemComponentListItems.cpp"
# COMMENT "Generating scene item component ${hfile}::${clazz}"
# DEPENDS sceneitemcomponentgen
# )
# # target_sources(${DAWN_TARGET_NAME}
# # PRIVATE
# # ${DAWN_GENERATED_DIR}/scene/SceneItemComponentListItems.cpp
# # )
# endif()
# add_dependencies(sceneitemcomponentgen ${clazz}_scenecomponent)
# add_dependencies(${DAWN_TARGET_NAME} ${clazz}_scenecomponent sceneitemcomponentgen sceneitemcomponentgen_cmd)
endfunction()
if(DAWN_VISUAL_NOVEL)
add_subdirectory(vnscenegen)

View File

@ -1,36 +0,0 @@
# Copyright (c) 2023 Dominic Msters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
project(sceneitemcomponentgen VERSION 1.0)
add_executable(sceneitemcomponentgen)
# Sources
target_sources(sceneitemcomponentgen
PRIVATE
${DAWN_SHARED_SOURCES}
${DAWN_TOOL_SOURCES}
SceneItemComponentRegister.cpp
)
# Includes
target_include_directories(sceneitemcomponentgen
PUBLIC
${DAWN_SHARED_INCLUDES}
${DAWN_TOOL_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}
)
# Definitions
target_compile_definitions(sceneitemcomponentgen
PUBLIC
DAWN_TOOL_INSTANCE=SceneItemComponentRegister
DAWN_TOOL_HEADER="SceneItemComponentRegister.hpp"
)
# Libraries
target_link_libraries(sceneitemcomponentgen
PUBLIC
${DAWN_BUILD_HOST_LIBS}
)

View File

@ -1,119 +0,0 @@
/**
* Copyright (c) 2023 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "SceneItemComponentRegister.hpp"
using namespace Dawn;
void SceneItemComponentRootGen::generate(
std::vector<std::string> *out,
std::vector<struct SceneItemComponent> *info,
std::string tabs = ""
) {
line(out, "#include \"scene/SceneItemComponentList.hpp\"", tabs);
line(out, "", tabs);
auto it = info->begin();
while(it != info->end()) {
auto c = *it;
line(out, "#include \"" + c.header + "\"", tabs);
++it;
}
line(out, "", tabs);
line(out, "using namespace Dawn;", tabs);
line(out, "", tabs);
line(out, "SceneItemComponentList::SceneItemComponentList() {", tabs);
it = info->begin();
while(it != info->end()) {
auto c = *it;
line(out, "this->append<" + c.clazz + ">();", tabs + " ");
++it;
}
line(out, "}", tabs);
}
std::vector<std::string> SceneItemComponentRegister::getRequiredFlags() {
return std::vector<std::string>{ "input", "output" };
}
int32_t SceneItemComponentRegister::start() {
File fileIn(flags["input"]);
if(!fileIn.exists()) {
std::cout << "Input scene item component file does not exist." << std::endl;
return 1;
}
std::string buffer;
if(!fileIn.readString(&buffer)) {
std::cout << "Failed to read input scene item component file" << std::endl;
return 1;
}
std::vector<struct SceneItemComponent> components;
struct SceneItemComponent sci;
size_t i = 0;
std::string t;
uint8_t state = 0x00;
while(i < buffer.size()) {
char c = buffer[i++];
if(c != ';') {
t.push_back(c);
continue;
}
switch(state) {
case 0x00:
sci.clazz = t;
t.clear();
state = 0x01;
break;
case 0x01:
sci.header = t;
t.clear();
state = 0x00;
components.push_back(sci);
break;
default:
assertUnreachable();
}
}
if(state == 0x01) {
sci.header = t;
components.push_back(sci);
} else {
assertUnreachable();
}
std::vector<std::string> lines;
SceneItemComponentRootGen::generate(&lines, &components, "");
// Generate buffer
std::string bufferOut;
auto itLine = lines.begin();
while(itLine != lines.end()) {
bufferOut += *itLine + "\n";
++itLine;
}
File fileOut(flags["output"]);
if(!fileOut.mkdirp()) {
std::cout << "Failed to create Scene Item Component List Dir" << std::endl;
return 1;
}
if(!fileOut.writeString(bufferOut)) {
std::cout << "Failed to write SceneItemComponentList file" << std::endl;
return 1;
}
return 0;
}

View File

@ -1,33 +0,0 @@
// 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 "util/CodeGen.hpp"
namespace Dawn {
struct SceneItemComponent {
std::string clazz;
std::string header;
};
class SceneItemComponentRootGen : public CodeGen {
public:
static void generate(
std::vector<std::string> *out,
std::vector<struct SceneItemComponent> *info,
std::string tabs
);
};
class SceneItemComponentRegister : public DawnTool {
protected:
std::vector<std::string> getRequiredFlags() override;
public:
int32_t start() override;
};
}

View File

@ -1,38 +0,0 @@
# 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}
)

View File

@ -1,60 +0,0 @@
// 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;
}

View File

@ -1,20 +0,0 @@
// 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

@ -1,67 +0,0 @@
// 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

@ -1,31 +0,0 @@
// 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

@ -1,46 +0,0 @@
// 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

@ -1,83 +0,0 @@
// 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);
}
};
}

View File

@ -1,39 +0,0 @@
# Copyright (c) 2023 Dominic Msters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# VN Scene Generator Tool
project(vnscenegen VERSION 1.1)
add_executable(vnscenegen)
# Sources
target_sources(vnscenegen
PRIVATE
${DAWN_SHARED_SOURCES}
${DAWN_TOOL_SOURCES}
VnSceneGen.cpp
)
# Includes
target_include_directories(vnscenegen
PUBLIC
${DAWN_SHARED_INCLUDES}
${DAWN_TOOL_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}
)
# Definitions
target_compile_definitions(vnscenegen
PUBLIC
${DAWN_SHARED_DEFINITIONS}
DAWN_TOOL_INSTANCE=VnSceneGen
DAWN_TOOL_HEADER="VnSceneGen.hpp"
)
# Libraries
target_link_libraries(vnscenegen
PUBLIC
${DAWN_BUILD_HOST_LIBS}
)

View File

@ -1,60 +0,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;
}

View File

@ -1,20 +0,0 @@
// 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 VnSceneGen : public DawnTool {
protected:
std::vector<std::string> getRequiredFlags() override;
public:
int32_t start();
};
}

View File

@ -1,56 +0,0 @@
// 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 {
struct AssetInformation {
std::string type;
std::string name;
};
class AssetParser : public XmlParser<struct AssetInformation> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>{
"name",
"type"
};
}
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 AssetInformation *out,
std::string *error
) {
out->name = values["name"];
out->type = values["type"];
return 0;
}
std::string convert(struct AssetInformation info) {
std::string out;
return out;
}
};
class AssetGen : public CodeGen {
public:
static void generate(
std::vector<std::string> *out,
struct AssetInformation *info,
std::string tabs
) {
return line(out, "// Asset will be generated here", tabs);
}
};
}

View File

@ -1,77 +0,0 @@
// 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 {
struct CharacterInformation {
std::string clazz;
std::string name;
};
class CharacterParser : public XmlParser<struct CharacterInformation> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>{
"class",
"name"
};
}
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 CharacterInformation *out,
std::string *error
) {
out->clazz = values["class"];
out->name = values["name"];
if(out->clazz.size() == 0) {
*error = "Character class cannot be empty.";
return 1;
}
if(out->name.size() == 0) {
*error = "Character name cannot be empty.";
return 1;
}
return 0;
}
};
class CharacterGen : public CodeGen {
public:
static void generateProperty(
std::vector<std::string> *out,
struct CharacterInformation info,
std::string tabs
) {
line(out, info.clazz + " *" + info.name + ";", tabs);
}
static void generateInitializer(
std::vector<std::string> *out,
struct CharacterInformation info,
std::string tabs
) {
line(out, "this->" + info.name + " = " + info.clazz + "::create(this);", tabs);
}
static void generateAssets(
std::vector<std::string> *out,
struct CharacterInformation info,
std::string tabs
) {
line(out, "vectorAppend(&assets, " + info.clazz + "::getRequiredAssets(man));", "");
}
};
}

View File

@ -1,77 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
// 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 {
struct CharacterFadeEventInfo {
std::string character;
std::string duration;
std::string ease;
std::string fade;
std::string include;
};
class CharacterFadeParser : public XmlParser<struct CharacterFadeEventInfo> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>{
"character"
};
}
std::map<std::string, std::string> getOptionalAttributes() {
return std::map<std::string, std::string>{
{ "fade", "in" },
{ "ease", "linear" },
{ "duration", "1" }
};
}
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct CharacterFadeEventInfo *out,
std::string *error
) {
out->character = values["character"];
out->duration = parseDuration(values["duration"]);
out->ease = parseEase(values["ease"]);
out->fade = values["fade"] == "in" ? "true" : "false";
out->include = "visualnovel/events/characters/VisualNovelFadeCharacterEvent.hpp";
if(out->ease.size() == 0) {
*error = "Invalid ease";
return 1;
}
return 0;
}
};
class CharacterFadeGen : public CodeGen {
public:
static void generate(
std::vector<std::string> *out,
struct CharacterFadeEventInfo *info,
std::string tabs = ""
) {
line(out, "new VisualNovelFadeCharacterEvent(vnManager,", tabs + " ");
line(out, "this->" + info->character + "->vnCharacter,", tabs + " ");
line(out, info->fade + ",", tabs + " ");
line(out, info->ease + ",", tabs + " ");
line(out, info->duration, tabs + " ");
line(out, ")", tabs);
}
};
}

View File

@ -1,48 +0,0 @@
// 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 {
struct PauseEventInfo {
std::string duration;
std::string include;
};
class PauseEventParser : public XmlParser<struct PauseEventInfo> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>{ "duration" };
}
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 PauseEventInfo *out,
std::string *error
) {
out->duration = parseDuration(values["duration"]);
out->include = "visualnovel/events/timing/VisualNovelPauseEvent.hpp";
return 0;
}
};
class PauseEventGen : public CodeGen {
public:
static void generate(
std::vector<std::string> *out,
struct PauseEventInfo *info,
std::string tabs = ""
) {
line(out, "new VisualNovelPauseEvent(vnManager, " + info->duration + ")", tabs);
}
};
}

View File

@ -1,101 +0,0 @@
// 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"
#include "util/Language.hpp"
namespace Dawn {
struct TextEventInfo {
std::string character;
std::string emotion;
std::vector<struct LanguageString> strings;
std::string key;
};
class TextStringParser : public XmlParser<struct LanguageString> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>{ "lang" };
}
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 LanguageString *out,
std::string *error
) {
out->lang = values["lang"];
out->text = node->value;
return 0;
}
};
class TextEventParser : public XmlParser<struct TextEventInfo> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>{
"character",
"emotion"
};
}
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 TextEventInfo *out,
std::string *error
) {
int32_t ret = 0;
out->character = values["character"];
out->emotion = values["emotion"];
if(out->key.size() <= 0) {
*error = "Text Event requries a language key to be defined.";
return 1;
}
auto itChildren = node->children.begin();
while(itChildren != node->children.end()) {
auto c = *itChildren;
if(c->node == "string") {
struct LanguageString str;
ret = (TextStringParser()).parse(c, &str, error);
str.key = out->key;
out->strings.push_back(str);
}
++itChildren;
}
return ret;
}
};
class TextEventGen : public CodeGen {
public:
static void generate(
std::vector<std::string> *out,
struct TextEventInfo *info,
std::string tabs = ""
) {
std::string emo = info->emotion;
emo[0] = toupper(emo[0]);
line(out, "new VisualNovelTextboxEvent(vnManager,", tabs);
line(out, "this->" + info->character + "->vnCharacter, ", tabs + " ");
line(out, "this->" + info->character + "->emotion" + emo + ", ", tabs + " ");
line(out, "\"" + info->key + "\"", tabs + " ");
line(out, ")", tabs);
}
};
}

View File

@ -1,121 +0,0 @@
// 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 "parse/event/textevent.hpp"
#include "parse/event/characterfadeevent.hpp"
#include "parse/event/pauseevent.hpp"
namespace Dawn {
enum EventType {
EVENT_TYPE_TEXT,
EVENT_TYPE_CHARACTER_FADE,
EVENT_TYPE_PAUSE
};
struct EventsInformation {
std::map<int32_t, enum EventType> eventTypes;
std::map<int32_t, struct TextEventInfo> textEvents;
std::map<int32_t, struct CharacterFadeEventInfo> characterFadeEvents;
std::map<int32_t, struct PauseEventInfo> pauseEvents;
std::vector<std::string> includes;
std::vector<struct LanguageString> strings;
std::string key;
};
class EventsParser : public XmlParser<struct EventsInformation> {
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 EventsInformation *out,
std::string *error
) {
int32_t ret = 0;
int32_t i = 0;
int32_t languageKeyNumber = 1;
if(out->key.size() <= 0) {
*error = "Events requries a language key to be defined.";
return 1;
}
auto itChildren = node->children.begin();
while(itChildren != node->children.end()) {
auto c = *itChildren;
if(c->node == "text") {
struct TextEventInfo textEvent;
textEvent.key = out->key + "." + std::to_string(languageKeyNumber++);
ret = (TextEventParser()).parse(c, &textEvent, error);
out->eventTypes[i] = EVENT_TYPE_TEXT;
out->textEvents[i++] = textEvent;
vectorAppend(&out->strings, textEvent.strings);
} else if(c->node == "character-fade") {
struct CharacterFadeEventInfo charFadeEvent;
ret = (CharacterFadeParser()).parse(c, &charFadeEvent, error);
out->eventTypes[i] = EVENT_TYPE_CHARACTER_FADE;
out->characterFadeEvents[i++] = charFadeEvent;
out->includes.push_back(charFadeEvent.include);
} else if(c->node == "pause") {
struct PauseEventInfo pauseEvent;
ret = (PauseEventParser()).parse(c, &pauseEvent, error);
out->eventTypes[i] = EVENT_TYPE_PAUSE;
out->pauseEvents[i++] = pauseEvent;
out->includes.push_back(pauseEvent.include);
}
++itChildren;
}
return ret;
}
};
class EventsGen : public CodeGen {
public:
static void generate(
std::vector<std::string> *out,
struct EventsInformation *info,
std::string tabs
) {
auto itEvents = info->eventTypes.begin();
while(itEvents != info->eventTypes.end()) {
auto e = *itEvents;
line(out, "->then(", tabs);
switch(e.second) {
case EVENT_TYPE_TEXT:
TextEventGen::generate(out, &info->textEvents[e.first], tabs + " ");
break;
case EVENT_TYPE_CHARACTER_FADE:
CharacterFadeGen::generate(out, &info->characterFadeEvents[e.first], tabs + " ");
break;
case EVENT_TYPE_PAUSE:
PauseEventGen::generate(out, &info->pauseEvents[e.first], tabs + " ");
break;
}
line(out, ")", tabs);
++itEvents;
}
}
};
}

View File

@ -1,67 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "parse/include.hpp"
#include "parse/character.hpp"
#include "parse/scene.hpp"
#include "parse/asset.hpp"
namespace Dawn {
struct HeaderInformation {
std::vector<std::string> includes;
std::vector<struct CharacterInformation> characters;
std::vector<struct AssetInformation> assets;
std::map<std::string, std::map<std::string, std::string>> languages;
struct SceneInformation scene;
};
class HeaderParser : public XmlParser<struct HeaderInformation> {
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 HeaderInformation *out,
std::string *error
) {
int32_t ret = 0;
auto itChildren = node->children.begin();
while(itChildren != node->children.end()) {
auto c = *itChildren;
if(c->node == "include") {
ret = (IncludeParser()).parse(c, &out->includes, error);
} else if (c->node == "character") {
struct CharacterInformation character;
ret = (CharacterParser()).parse(c, &character, error);
if(ret != 0) return ret;
out->characters.push_back(character);
} else if(c->node == "asset") {
struct AssetInformation asset;
ret = (AssetParser()).parse(c, &asset, error);
if(ret != 0) return ret;
out->assets.push_back(asset);
} else if(c->node == "scene") {
ret = (SceneParser()).parse(c, &out->scene, error);
}
if(ret != 0) return ret;
++itChildren;
}
return ret;
}
};
}

View File

@ -1,59 +0,0 @@
// 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 {
typedef std::vector<std::string> include_t;
class IncludeParser : public XmlParser<include_t> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>{
"path"
};
}
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,
include_t *out,
std::string *error
) {
if(values["path"].size() == 0) {
*error = "";
return 1;
}
out->push_back(values["path"]);
return 0;
}
};
class IncludeGen : public CodeGen {
public:
static void generate(
std::vector<std::string> *out,
include_t includes,
std::string tabs
) {
std::vector<std::string> generated;
auto it = includes.begin();
while(it != includes.end()) {
if(std::find(generated.begin(), generated.end(), *it) == generated.end()) {
line(out, "#include \"" + *it + "\"", tabs);
generated.push_back(*it);
}
++it;
}
}
};
}

View File

@ -1,120 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "parse/header.hpp"
#include "parse/events.hpp"
namespace Dawn {
struct RootInformation {
struct HeaderInformation header;
struct EventsInformation events;
std::vector<struct LanguageString> strings;
};
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 = 0;
auto itChildren = node->children.begin();
while(itChildren != node->children.end()) {
auto c = *itChildren;
if(c->node == "head") {
ret = (HeaderParser()).parse(c, &out->header, error);
} else if(c->node == "events") {
out->events.key = out->header.scene.name;
ret = (EventsParser()).parse(c, &out->events, error);
vectorAppend(&out->strings, out->events.strings);
}
if(ret != 0) return ret;
++itChildren;
}
out->header.includes.push_back("visualnovel/events/VisualNovelEmptyEvent.hpp");
return ret;
}
};
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";
struct MethodGenInfo vnStage;
vnStage.name = "vnStage";
vnStage.type = "void";
vnStage.isOverride = true;
line(&vnStage.body, info->header.scene.type+ "::vnStage();", "");
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();", "");
struct MethodGenInfo getVNEvent;
getVNEvent.name = "getVNEvent";
getVNEvent.type = "IVisualNovelEvent *";
getVNEvent.isOverride = true;
line(&getVNEvent.body, "auto start = new VisualNovelEmptyEvent(vnManager);", "");
IncludeGen::generate(&c.includes, info->header.includes, "");
IncludeGen::generate(&c.includes, info->events.includes, "");
// 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);
}
};
}

View File

@ -1,40 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
namespace Dawn {
struct SceneInformation {
std::string type;
std::string name;
};
class SceneParser : public XmlParser<struct SceneInformation> {
protected:
std::vector<std::string> getRequiredAttributes() {
return std::vector<std::string>{
"name",
};
}
std::map<std::string, std::string> getOptionalAttributes() {
return std::map<std::string, std::string>{
{ "type", "SimpleVNScene" }
};
}
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct SceneInformation *out,
std::string *error
) {
out->name = values["name"];
out->type = values["type"];
return 0;
}
};
}