// 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 { protected: std::vector getRequiredAttributes() { return std::vector{ "character" }; } std::map getOptionalAttributes() { return std::map{ { "fade", "in" }, { "ease", "linear" }, { "duration", "1" } }; } int32_t onParse( Xml *node, std::map 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 *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); } }; }