// 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 strings; std::string key; }; class TextStringParser : public XmlParser { protected: std::vector getRequiredAttributes() { return std::vector{ "lang" }; } std::map getOptionalAttributes() { return std::map(); } int32_t onParse( Xml *node, std::map values, struct LanguageString *out, std::string *error ) { out->lang = values["lang"]; out->text = node->value; return 0; } }; class TextEventParser : public XmlParser { protected: std::vector getRequiredAttributes() { return std::vector{ "character", "emotion" }; } std::map getOptionalAttributes() { return std::map(); } int32_t onParse( Xml *node, std::map 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 *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); } }; }