// 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 { protected: std::vector getRequiredAttributes() { return std::vector{ "class", "name" }; } std::map getOptionalAttributes() { return std::map(); } int32_t onParse( Xml *node, std::map 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 *out, struct CharacterInformation info, std::string tabs ) { line(out, info.clazz + " *" + info.name + ";", tabs); } static void generateInitializer( std::vector *out, struct CharacterInformation info, std::string tabs ) { line(out, "this->" + info.name + " = " + info.clazz + "::create(this);", tabs); } static void generateAssets( std::vector *out, struct CharacterInformation info, std::string tabs ) { line(out, "vectorAppend(&assets, " + info.clazz + "::getRequiredAssets(man));", ""); } }; }