120 lines
3.9 KiB
C++
120 lines
3.9 KiB
C++
// 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);
|
|
}
|
|
};
|
|
} |