From c07d88e55b60ae5d74557196301e5168f6d812e6 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Tue, 21 Mar 2023 20:51:41 -0400 Subject: [PATCH 01/12] Redoing Color to a CompoundCustomClass and other changes to the base xml parser --- xml_converter/doc/position/position.md | 6 +- xml_converter/doc/rotation/euler_rotation.md | 3 +- xml_converter/doc/texture/color.md | 32 ++++++- xml_converter/doc/trigger/reset_length.md | 4 +- xml_converter/doc/trigger/reset_offset.md | 12 +++ xml_converter/generators/code_generator.py | 45 +++++++--- .../cpp_templates/class_template.cpp | 44 ++++----- .../cpp_templates/compoundvalue.cpp | 4 +- xml_converter/proto/waypoint.proto | 3 +- xml_converter/src/attribute/color.cpp | 89 +++++++++++++++---- xml_converter/src/attribute/color.hpp | 8 +- xml_converter/src/icon_gen.cpp | 49 ++++++++-- xml_converter/src/icon_gen.hpp | 8 ++ xml_converter/src/trail_gen.cpp | 12 +++ xml_converter/src/trail_gen.hpp | 6 ++ xml_converter/src/xml_converter.cpp | 4 +- 16 files changed, 251 insertions(+), 78 deletions(-) create mode 100644 xml_converter/doc/trigger/reset_offset.md diff --git a/xml_converter/doc/position/position.md b/xml_converter/doc/position/position.md index 719d8d44..a6898767 100644 --- a/xml_converter/doc/position/position.md +++ b/xml_converter/doc/position/position.md @@ -5,8 +5,10 @@ applies_to: ["Icon"] xml_fields: ["Position"] compatability: [TacO, Burrito, BlishHUD] protobuf_field: position +xml_parent_export: "" +xml_child_export: ["X Position", "Y Position", "Z Position"] components: - + - name: X Position type: Float32 xml_fields: [XPos, PositionX] @@ -26,8 +28,6 @@ components: xml_fields: [ZPos, PositionZ] protobuf_field: "z" compatability: [TacO, Burrito, BlishHUD] - -xml_export: "Children" --- An XYZ location of a point in the game world. diff --git a/xml_converter/doc/rotation/euler_rotation.md b/xml_converter/doc/rotation/euler_rotation.md index 90ea3ff1..71e56289 100644 --- a/xml_converter/doc/rotation/euler_rotation.md +++ b/xml_converter/doc/rotation/euler_rotation.md @@ -5,6 +5,8 @@ applies_to: ["Icon"] xml_fields: ["Rotate"] compatability: [TacO, Burrito, BlishHUD] protobuf_field: euler_rotation +xml_parent_export: "'X Rotation', 'Y Rotation', 'Z Rotation'" +xml_child_export: [] components: - name: X Rotation type: Float32 @@ -26,7 +28,6 @@ components: protobuf_field: "z" compatability: [TacO, Burrito, BlishHUD] -xml_export: "Parent" --- Euler X Y Z rotation. diff --git a/xml_converter/doc/texture/color.md b/xml_converter/doc/texture/color.md index 8dd31278..d1b69e1d 100644 --- a/xml_converter/doc/texture/color.md +++ b/xml_converter/doc/texture/color.md @@ -1,11 +1,41 @@ --- name: Color -type: Custom +type: CompoundCustomClass class: Color applies_to: [Icon, Trail] xml_fields: [Color, BHColor] protobuf_field: rgba_color compatability: [TacO, BlishHUD, Burrito] +xml_parent_export: "{Red},{Green},{Blue}" +xml_child_export: ["Alpha"] + +components: + + - name: Red # fake, to make thing "square" + type: Float32 + xml_fields: [Red] + protobuf_field: rgba_color + compatability: [TacO, Burrito, BlishHUD] + + - name: Green + type: Float32 + xml_fields: [Green] + protobuf_field: rgba_color + compatability: [TacO, Burrito, BlishHUD] + + - name: Blue + type: Float32 + xml_fields: [Blue] + protobuf_field: rgba_color + compatability: [TacO, Burrito, BlishHUD] + + - name: Alpha + type: Float32 + xml_fields: [Alpha] + protobuf_field: rgba_color + compatability: [TacO, Burrito, BlishHUD] + + --- A multiplier color to tint the raw albedo texture of a marker of trail texture. (Unclear) Solid white will result in no change, solid black will result in a black texture. diff --git a/xml_converter/doc/trigger/reset_length.md b/xml_converter/doc/trigger/reset_length.md index 30bb9bb7..64a6279a 100644 --- a/xml_converter/doc/trigger/reset_length.md +++ b/xml_converter/doc/trigger/reset_length.md @@ -2,8 +2,8 @@ name: Reset Length type: Float32 applies_to: [Icon] -xml_fields: [ResetLength] -protobuf_field: trigger.reset_length +xml_fields: [ResetOffset] +protobuf_field: trigger.reset_offset compatability: [TacO, BlishHUD, Burrito] --- When using behavior 4 (reappear after timer) this value defines, in seconds, the duration until the marker is reset after being activated. diff --git a/xml_converter/doc/trigger/reset_offset.md b/xml_converter/doc/trigger/reset_offset.md new file mode 100644 index 00000000..38e75bee --- /dev/null +++ b/xml_converter/doc/trigger/reset_offset.md @@ -0,0 +1,12 @@ +--- +name: Reset Offset +type: Float32 +applies_to: [Icon] +xml_fields: [ResetLength] +protobuf_field: trigger.reset_length +compatability: [] +--- +When using behavior 5 ('Reappear on map reset') this value defines, in seconds, when the first map cycle of the day begins after the daily reset. +Notes +===== +Behavior 5 is Not implemented by TacO or BlishHUD \ No newline at end of file diff --git a/xml_converter/generators/code_generator.py b/xml_converter/generators/code_generator.py index 8359d919..d512637d 100644 --- a/xml_converter/generators/code_generator.py +++ b/xml_converter/generators/code_generator.py @@ -15,7 +15,7 @@ properties: type: type: string - enum: [Int32, Fixed32, Float32, String, Boolean, MultiflagValue, Enum, CompoundValue, Custom] + enum: [Int32, Fixed32, Float32, String, Boolean, MultiflagValue, Enum, CompoundValue, Custom, CompoundCustomClass] allOf: ############################# # Int32 Type @@ -131,15 +131,16 @@ const: CompoundValue then: additionalProperties: false - required: [{shared_fields}, xml_export, components] + required: [{shared_fields}, components] properties: {shared_field_properties} - xml_export: + xml_parent_export: type: string - enum: - - Parent - - Parent and Children - - Children + xml_child_export: + type: array + items: + type: string + pattern: "^[A-Za-z' ]+$" components: type: array items: @@ -156,7 +157,7 @@ type: array items: type: string - pattern: "^[A-Za-z]+$" + pattern: "^[A-Za-z ]+$" protobuf_field: type: string pattern: "^[a-z_.]+$" @@ -187,6 +188,13 @@ type: string uses_file_path: type: boolean + xml_parent_export: + type: string + xml_child_export: + type: array + items: + type: string + pattern: "^[A-Za-z' ]+$" """.format( shared_field_properties="""type: @@ -290,9 +298,12 @@ class AttributeVariable: protobuf_field: str args: List[str] = field(default_factory=list) default_xml_fields: List[str] = field(default_factory=list) - xml_export: str = "" side_effects: List[str] = field(default_factory=list) compound_name: Optional[str] = None + xml_child_export: str = "" + xml_parent_export: str = "" + compound_name: Optional[str] = None + is_xml_export: bool = True is_trigger: bool = False uses_file_path: bool = False @@ -439,9 +450,11 @@ def generate_cpp_variable_data( xml_fields: List[str] = [] default_xml_fields: List[str] = [] side_effects: List[str] = [] - xml_export: str = "" args: List[str] = [] + xml_child_export: List[str] = [] + xml_parent_export: List[str] = [] protobuf_field: str = "" + is_xml_export: bool = True is_trigger: bool = False cpp_includes.hpp_absolute_includes.add("string") @@ -474,14 +487,15 @@ def generate_cpp_variable_data( default_xml_fields = [] side_effects = [] xml_export = "" - args = XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS.copy() + args = XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS.copy( if fieldval['type'] in documentation_type_data: cpp_type = documentation_type_data[fieldval['type']]["cpp_type"] class_name = documentation_type_data[fieldval['type']]["class_name"] cpp_includes.cpp_relative_includes.add("attribute/{}.hpp".format(class_name)) - elif fieldval['type'] == "Custom": + + elif fieldval['type'] in ["Custom", "CompoundCustomClass"]: cpp_type = fieldval['class'] class_name = insert_delimiter(fieldval['class'], delimiter="_") cpp_includes.hpp_relative_includes.add("attribute/{}.hpp".format(class_name)) @@ -549,11 +563,13 @@ def generate_cpp_variable_data( class_name=class_name, xml_fields=xml_fields, default_xml_fields=default_xml_fields, - xml_export=xml_export, + xml_child_export=xml_child_export, + xml_parent_export=xml_parent_export, protobuf_field=protobuf_field, is_trigger=is_trigger, args=args, side_effects=side_effects, + is_xml_export=is_xml_export, ) attribute_variables.append(attribute_variable) @@ -636,7 +652,8 @@ def write_attribute(self, output_directory: str) -> None: cpp_type=doc_type_to_cpp_type[component['type']], class_name=attribute_name, xml_fields=xml_fields, - xml_export=metadata[filepath]["xml_export"], + xml_child_export=metadata[filepath]["xml_child_export"], + xml_parent_export=metadata[filepath]["xml_parent_export"], protobuf_field=component["protobuf_field"], is_trigger=is_trigger, ) diff --git a/xml_converter/generators/cpp_templates/class_template.cpp b/xml_converter/generators/cpp_templates/class_template.cpp index b9fa7839..78483ff2 100644 --- a/xml_converter/generators/cpp_templates/class_template.cpp +++ b/xml_converter/generators/cpp_templates/class_template.cpp @@ -44,7 +44,7 @@ bool {{cpp_class}}::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vec this->{{attribute_variable.attribute_name}} = parse_{{attribute_variable.class_name}}({{", ".join(attribute_variable.args)}}); this->{{attribute_variable.attribute_name}}_is_set = true; } - {% elif (attribute_variable.attribute_type == "CompoundValue" and attribute_variable.compound_name != None) %} + {% elif (attribute_variable.attribute_type in ["CompoundValue", "CompoundCustomClass"] and attribute_variable.compound_name != None) %} else if (attributename == "{{value}}") { this->{{attribute_variable.compound_name}}.{{attribute_variable.attribute_name}} = parse_float(attribute, errors); this->{{attribute_variable.compound_name}}_is_set = true; @@ -81,30 +81,20 @@ vector {{cpp_class}}::as_xml() const { vector xml_node_contents; xml_node_contents.push_back("<{{xml_class_name}} "); {% for attribute_variable in attribute_variables %} - {% if (attribute_variable.attribute_type == "CompoundValue") %} - {% if (attribute_variable.xml_export == "Children" and attribute_variable.compound_name != None) %} - if (this->{{attribute_variable.compound_name}}_is_set) { - xml_node_contents.push_back(" {{attribute_variable.default_xml_fields[0]}}=\"" + to_string(this->{{attribute_variable.compound_name}}.{{attribute_variable.attribute_name}}) + "\""); - } - {% elif (attribute_variable.xml_export == "Parent" and attribute_variable.compound_name == None)%} - if (this->{{attribute_variable.attribute_name}}_is_set) { - xml_node_contents.push_back(" {{attribute_variable.default_xml_fields[0]}}=\"" + stringify_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}}) + "\""); - } - {% elif (attribute_variable.xml_export == "Parent and Children")%} - {% for value in attribute_variable.xml_fields %} - if (this->{{attribute_variable.attribute_name}}_is_set) { - xml_node_contents.push_back(" {{value}}=\"" + stringify_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}}) + "\""); - {% endfor %} - } - {% endif %} - {% else: %} - if (this->{{attribute_variable.attribute_name}}_is_set) { - xml_node_contents.push_back(" {{attribute_variable.default_xml_fields[0]}}=\"" + stringify_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}}) + "\""); - } - {% endif %} - {% endfor %} - {% if cpp_class == "Category": %} - xml_node_contents.push_back(">\n"); + {% if attribute_variable.is_xml_export == true %} + {% if (attribute_variable.attribute_type in ["CompoundValue", "CompoundCustomClass"] and attribute_variable.compound_name != None) %} + if (this->{{attribute_variable.compound_name}}_is_set) { + xml_node_contents.push_back(" {{attribute_variable.default_xml_fields[0]}}=\"" + stringify_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}}) + "\""); + } + {% else %} + if (this->{{attribute_variable.attribute_name}}_is_set) { + xml_node_contents.push_back(" {{attribute_variable.default_xml_fields[0]}}=\"" + stringify_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}}) + "\""); + } + {% endif %} + {% endif %} +{% endfor %} +{% if cpp_class == "Category": %} + xml_node_contents.push_back(">\n"); for (const auto& [key, val] : this->children) { string text; @@ -156,7 +146,7 @@ waypoint::{{cpp_class}} {{cpp_class}}::as_protobuf() const { if (this->{{attribute_variable.attribute_name}}_is_set) { proto_{{cpp_class_header}}.set_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); } - {% elif (attribute_variable.attribute_type in ["MultiflagValue", "CompoundValue", "Custom"]) and attribute_variable.compound_name == None%} + {% elif (attribute_variable.attribute_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"]) and attribute_variable.compound_name == None%} if (this->{{attribute_variable.attribute_name}}_is_set) { proto_{{cpp_class_header}}.set_allocated_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); } @@ -215,7 +205,7 @@ void {{cpp_class}}::parse_protobuf(waypoint::{{cpp_class}} proto_{{cpp_class_hea this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}()); this->{{attribute_variable.attribute_name}}_is_set = true; } - {% elif (attribute_variable.attribute_type in ["MultiflagValue", "CompoundValue", "Custom"]) and attribute_variable.compound_name == None%} + {% elif (attribute_variable.attribute_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"]) and attribute_variable.compound_name == None%} if (proto_{{cpp_class_header}}.has_{{attribute_variable.protobuf_field}}()) { this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}()); this->{{attribute_variable.attribute_name}}_is_set = true; diff --git a/xml_converter/generators/cpp_templates/compoundvalue.cpp b/xml_converter/generators/cpp_templates/compoundvalue.cpp index eb5ab4c6..97d22ff8 100644 --- a/xml_converter/generators/cpp_templates/compoundvalue.cpp +++ b/xml_converter/generators/cpp_templates/compoundvalue.cpp @@ -27,7 +27,7 @@ using namespace std; } return {{attribute_name}}; } -{% if attribute_variables[0].xml_export == "Parent" %} +{% if attribute_variables[0].xml_parent_export != "" %} string stringify_{{attribute_name}}({{class_name}} attribute_value) { string output; {% for n, attribute_variable in enumerate(attribute_variables) %} @@ -38,7 +38,7 @@ using namespace std; {% endif %} {% endfor %} return output; - } +} {% endif %} waypoint::{{class_name}}* to_proto_{{attribute_name}}({{class_name}} attribute_value) { diff --git a/xml_converter/proto/waypoint.proto b/xml_converter/proto/waypoint.proto index 1e62199e..65156ca2 100644 --- a/xml_converter/proto/waypoint.proto +++ b/xml_converter/proto/waypoint.proto @@ -122,7 +122,8 @@ message Trigger { Category action_hide_category = 12; Category action_show_category = 13; Category action_toggle_category = 14; - ResetBehavior reset_behavior= 15; + ResetBehavior reset_behavior = 15; + int32 reset_offset = 16; } message GUID { diff --git a/xml_converter/src/attribute/color.cpp b/xml_converter/src/attribute/color.cpp index 5b93d9b2..83fe3a50 100644 --- a/xml_converter/src/attribute/color.cpp +++ b/xml_converter/src/attribute/color.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -17,12 +18,35 @@ using namespace std; // parse_color // // Parses a Color from the value of a rapidxml::xml_attribute. -// TODO(#98): Color should be saved in a better format then the raw hex string. -// TODO(#129): Compound Value XML Export //////////////////////////////////////////////////////////////////////////////// Color parse_color(rapidxml::xml_attribute<>* input, vector*) { Color color; - color.hex = get_attribute_value(input); + std::string input_string = get_attribute_value(input); + std::string hex_string; + + if (input_string.size() > 0 && input_string[0] == '#') { + hex_string = input_string.substr(1); + } + else { + hex_string = input_string; + } + + std::regex hex_pattern("^([A-Fa-f0-9]{6})$|^([A-Fa-f0-9]{8})$"); + + if (std::regex_match(hex_string, hex_pattern)) { + // Extract the R, G, B, and A values from the Hex string + if (hex_string.size() == 6 || hex_string.size() == 8) { + color.r = std::stoi(hex_string.substr(0, 2), nullptr, 16); + color.g = std::stoi(hex_string.substr(2, 2), nullptr, 16); + color.b = std::stoi(hex_string.substr(4, 2), nullptr, 16); + if (hex_string.size() == 8) { + color.a = std::stoi(hex_string.substr(6, 2), nullptr, 16); + } + else { + color.a = 255; + } + } + } return color; } @@ -32,7 +56,20 @@ Color parse_color(rapidxml::xml_attribute<>* input, vector*) { // Converts a Color into a stringy value so it can be saved to xml. //////////////////////////////////////////////////////////////////////////////// string stringify_color(Color attribute_value) { - return attribute_value.hex; + std::stringstream stream; + std::string hex_string = "#"; + + stream << std::hex << attribute_value.r; + hex_string += stream.str(); + + stream << std::hex << attribute_value.g; + hex_string += stream.str(); + + stream << std::hex << attribute_value.b; + hex_string += stream.str(); + + std::string rgb = hex_string; + return rgb; } //////////////////////////////////////////////////////////////////////////////// @@ -41,14 +78,27 @@ string stringify_color(Color attribute_value) { // Converts a Color into a proto message //////////////////////////////////////////////////////////////////////////////// waypoint::RGBAColor* to_proto_color(Color attribute_value) { - string hex = attribute_value.hex; - waypoint::RGBAColor* color = new waypoint::RGBAColor; - // Adding default values until TODO #98 - int r = 255; - int g = 255; - int b = 255; - int a = 255; - uint32_t rgba = ((r & 0xff) << 24) + ((g & 0xff) << 16) + ((b & 0xff) << 8) + (a & 0xff); + waypoint::RGBAColor* color = new waypoint::RGBAColor(); + // The default RGB in burrito will be 000000 (i.e. black) + + // If alpha (float) is not the default value, convert to int + if (attribute_value.alpha != 0) { + int alpha_int = static_cast(attribute_value.alpha * 255); + // Check that it doesnt exceed the bounds of {0,255} + if (alpha_int > 255) { + alpha_int = 255; + } + if (alpha_int < 0) { + alpha_int = 0; + } + attribute_value.a = alpha_int; + } + else { + // Default value of alpha in Burrito + attribute_value.a = 255; + } + + uint32_t rgba = ((attribute_value.r & 0xff) << 24) + ((attribute_value.g & 0xff) << 16) + ((attribute_value.b & 0xff) << 8) + (attribute_value.a & 0xff); color->set_rgba_color(rgba); return color; } @@ -62,10 +112,17 @@ Color from_proto_color(waypoint::RGBAColor attribute_value) { Color color; std::stringstream stream; stream << std::hex << attribute_value.rgba_color(); - std::string rgba = stream.str(); + std::string hex_string = stream.str(); + + color.r = std::stoi(hex_string.substr(0, 2), nullptr, 16); + color.g = std::stoi(hex_string.substr(2, 2), nullptr, 16); + color.b = std::stoi(hex_string.substr(4, 2), nullptr, 16); + color.a = std::stoi(hex_string.substr(6, 2), nullptr, 16); - color.hex = rgba.substr(0, 6); - // Adding default values until TODO #98 - color.alpha = 1.0; + color.red = static_cast(color.r) / 255.0f; + color.green = static_cast(color.g) / 255.0f; + color.blue = static_cast(color.b) / 255.0f; + color.alpha = static_cast(color.a) / 255.0f; + return color; } diff --git a/xml_converter/src/attribute/color.hpp b/xml_converter/src/attribute/color.hpp index 7f5f4fab..08449ddd 100644 --- a/xml_converter/src/attribute/color.hpp +++ b/xml_converter/src/attribute/color.hpp @@ -12,8 +12,14 @@ class RGBAColor; class Color { public: - std::string hex; + float red; + float green; + float blue; float alpha; + int r; + int g; + int b; + int a; }; Color parse_color(rapidxml::xml_attribute<>* input, std::vector* errors); diff --git a/xml_converter/src/icon_gen.cpp b/xml_converter/src/icon_gen.cpp index f1db5a3e..92ddddb8 100644 --- a/xml_converter/src/icon_gen.cpp +++ b/xml_converter/src/icon_gen.cpp @@ -30,10 +30,18 @@ bool Icon::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectorachievement_id = parse_int(attribute, errors); this->achievement_id_is_set = true; } + else if (attributename == "alpha") { + this->color.alpha = parse_float(attribute, errors); + this->color_is_set = true; + } else if (attributename == "autotrigger") { this->auto_trigger = parse_bool(attribute, errors); this->auto_trigger_is_set = true; } + else if (attributename == "blue") { + this->color.blue = parse_float(attribute, errors); + this->color_is_set = true; + } else if (attributename == "bouncedelay") { this->bounce_delay = parse_float(attribute, errors); this->bounce_delay_is_set = true; @@ -106,6 +114,10 @@ bool Icon::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectorfestival_filter = parse_festival_filter(attribute, errors); this->festival_filter_is_set = true; } + else if (attributename == "green") { + this->color.green = parse_float(attribute, errors); + this->color_is_set = true; + } else if (attributename == "guid") { this->guid = parse_unique_id(attribute, errors); this->guid_is_set = true; @@ -174,6 +186,10 @@ bool Icon::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectorprofession_filter = parse_profession_filter(attribute, errors); this->profession_filter_is_set = true; } + else if (attributename == "red") { + this->color.red = parse_float(attribute, errors); + this->color_is_set = true; + } else if (attributename == "ingamevisibility") { this->render_ingame = parse_bool(attribute, errors); this->render_ingame_is_set = true; @@ -202,10 +218,14 @@ bool Icon::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectorreset_behavior = parse_reset_behavior(attribute, errors); this->reset_behavior_is_set = true; } - else if (attributename == "resetlength") { + else if (attributename == "resetoffset") { this->reset_length = parse_float(attribute, errors); this->reset_length_is_set = true; } + else if (attributename == "resetlength") { + this->reset_offset = parse_float(attribute, errors); + this->reset_offset_is_set = true; + } else if (attributename == "scaleonmapwithzoom") { this->scale_on_map_with_zoom = parse_bool(attribute, errors); this->scale_on_map_with_zoom_is_set = true; @@ -316,6 +336,9 @@ vector Icon::as_xml() const { if (this->achievement_id_is_set) { xml_node_contents.push_back(" AchievementId=\"" + stringify_int(this->achievement_id) + "\""); } + if (this->color_is_set) { + xml_node_contents.push_back(" Alpha=\"" + stringify_float(this->color.alpha) + "\""); + } if (this->auto_trigger_is_set) { xml_node_contents.push_back(" AutoTrigger=\"" + stringify_bool(this->auto_trigger) + "\""); } @@ -352,9 +375,6 @@ vector Icon::as_xml() const { if (this->distance_fade_start_is_set) { xml_node_contents.push_back(" FadeNear=\"" + stringify_float(this->distance_fade_start) + "\""); } - if (this->euler_rotation_is_set) { - xml_node_contents.push_back(" Rotate=\"" + stringify_euler_rotation(this->euler_rotation) + "\""); - } if (this->festival_filter_is_set) { xml_node_contents.push_back(" Festival=\"" + stringify_festival_filter(this->festival_filter) + "\""); } @@ -416,7 +436,10 @@ vector Icon::as_xml() const { xml_node_contents.push_back(" Behavior=\"" + stringify_reset_behavior(this->reset_behavior) + "\""); } if (this->reset_length_is_set) { - xml_node_contents.push_back(" ResetLength=\"" + stringify_float(this->reset_length) + "\""); + xml_node_contents.push_back(" ResetOffset=\"" + stringify_float(this->reset_length) + "\""); + } + if (this->reset_offset_is_set) { + xml_node_contents.push_back(" ResetLength=\"" + stringify_float(this->reset_offset) + "\""); } if (this->scale_on_map_with_zoom_is_set) { xml_node_contents.push_back(" ScaleOnMapWithZoom=\"" + stringify_bool(this->scale_on_map_with_zoom) + "\""); @@ -609,7 +632,13 @@ waypoint::Icon Icon::as_protobuf() const { if (trigger == nullptr) { trigger = new waypoint::Trigger(); } - trigger->set_reset_length(this->reset_length); + trigger->set_reset_offset(this->reset_length); + } + if (this->reset_offset_is_set) { + if (trigger == nullptr) { + trigger = new waypoint::Trigger(); + } + trigger->set_reset_length(this->reset_offset); } if (this->scale_on_map_with_zoom_is_set) { proto_icon.set_scale_on_map_with_zoom(this->scale_on_map_with_zoom); @@ -802,10 +831,14 @@ void Icon::parse_protobuf(waypoint::Icon proto_icon) { this->reset_behavior = from_proto_reset_behavior(trigger.reset_behavior()); this->reset_behavior_is_set = true; } - if (trigger.reset_length() != 0) { - this->reset_length = trigger.reset_length(); + if (trigger.reset_offset() != 0) { + this->reset_length = trigger.reset_offset(); this->reset_length_is_set = true; } + if (trigger.reset_length() != 0) { + this->reset_offset = trigger.reset_length(); + this->reset_offset_is_set = true; + } if (proto_icon.scale_on_map_with_zoom() != 0) { this->scale_on_map_with_zoom = proto_icon.scale_on_map_with_zoom(); this->scale_on_map_with_zoom_is_set = true; diff --git a/xml_converter/src/icon_gen.hpp b/xml_converter/src/icon_gen.hpp index 771b72fa..d35f058a 100644 --- a/xml_converter/src/icon_gen.hpp +++ b/xml_converter/src/icon_gen.hpp @@ -28,6 +28,7 @@ class Icon : public Parseable { int achievement_bitmask; int achievement_id; bool auto_trigger; + float blue; float bounce_delay; float bounce_duration; float bounce_height; @@ -41,6 +42,7 @@ class Icon : public Parseable { float distance_fade_start; EulerRotation euler_rotation; FestivalFilter festival_filter; + float green; UniqueId guid; bool has_countdown; float height_offset; @@ -57,11 +59,13 @@ class Icon : public Parseable { MountFilter mount_filter; Position position; ProfessionFilter profession_filter; + float red; bool render_ingame; bool render_on_map; bool render_on_minimap; ResetBehavior reset_behavior; float reset_length; + float reset_offset; bool scale_on_map_with_zoom; std::string schedule; float schedule_duration; @@ -75,6 +79,7 @@ class Icon : public Parseable { bool achievement_bitmask_is_set = false; bool achievement_id_is_set = false; bool auto_trigger_is_set = false; + bool blue_is_set = false; bool bounce_delay_is_set = false; bool bounce_duration_is_set = false; bool bounce_height_is_set = false; @@ -88,6 +93,7 @@ class Icon : public Parseable { bool distance_fade_start_is_set = false; bool euler_rotation_is_set = false; bool festival_filter_is_set = false; + bool green_is_set = false; bool guid_is_set = false; bool has_countdown_is_set = false; bool height_offset_is_set = false; @@ -104,11 +110,13 @@ class Icon : public Parseable { bool mount_filter_is_set = false; bool position_is_set = false; bool profession_filter_is_set = false; + bool red_is_set = false; bool render_ingame_is_set = false; bool render_on_map_is_set = false; bool render_on_minimap_is_set = false; bool reset_behavior_is_set = false; bool reset_length_is_set = false; + bool reset_offset_is_set = false; bool scale_on_map_with_zoom_is_set = false; bool schedule_is_set = false; bool schedule_duration_is_set = false; diff --git a/xml_converter/src/trail_gen.cpp b/xml_converter/src/trail_gen.cpp index 57676fb4..d5465b9e 100644 --- a/xml_converter/src/trail_gen.cpp +++ b/xml_converter/src/trail_gen.cpp @@ -38,6 +38,10 @@ bool Trail::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectoranimation_speed = parse_float(attribute, errors); this->animation_speed_is_set = true; } + else if (attributename == "blue") { + this->color.blue = parse_float(attribute, errors); + this->color_is_set = true; + } else if (attributename == "canfade") { this->can_fade = parse_bool(attribute, errors); this->can_fade_is_set = true; @@ -82,6 +86,10 @@ bool Trail::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectorfestival_filter = parse_festival_filter(attribute, errors); this->festival_filter_is_set = true; } + else if (attributename == "green") { + this->color.green = parse_float(attribute, errors); + this->color_is_set = true; + } else if (attributename == "guid") { this->guid = parse_unique_id(attribute, errors); this->guid_is_set = true; @@ -110,6 +118,10 @@ bool Trail::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectorprofession_filter = parse_profession_filter(attribute, errors); this->profession_filter_is_set = true; } + else if (attributename == "red") { + this->color.red = parse_float(attribute, errors); + this->color_is_set = true; + } else if (attributename == "ingamevisibility") { this->render_ingame = parse_bool(attribute, errors); this->render_ingame_is_set = true; diff --git a/xml_converter/src/trail_gen.hpp b/xml_converter/src/trail_gen.hpp index d2a5d488..5f58444a 100644 --- a/xml_converter/src/trail_gen.hpp +++ b/xml_converter/src/trail_gen.hpp @@ -26,6 +26,7 @@ class Trail : public Parseable { int achievement_bitmask; int achievement_id; float animation_speed; + float blue; bool can_fade; MarkerCategory category; Color color; @@ -33,6 +34,7 @@ class Trail : public Parseable { float distance_fade_end; float distance_fade_start; FestivalFilter festival_filter; + float green; UniqueId guid; bool is_wall; int map_display_size; @@ -40,6 +42,7 @@ class Trail : public Parseable { MapTypeFilter map_type_filter; MountFilter mount_filter; ProfessionFilter profession_filter; + float red; bool render_ingame; bool render_on_map; bool render_on_minimap; @@ -53,6 +56,7 @@ class Trail : public Parseable { bool achievement_bitmask_is_set = false; bool achievement_id_is_set = false; bool animation_speed_is_set = false; + bool blue_is_set = false; bool can_fade_is_set = false; bool category_is_set = false; bool color_is_set = false; @@ -60,6 +64,7 @@ class Trail : public Parseable { bool distance_fade_end_is_set = false; bool distance_fade_start_is_set = false; bool festival_filter_is_set = false; + bool green_is_set = false; bool guid_is_set = false; bool is_wall_is_set = false; bool map_display_size_is_set = false; @@ -67,6 +72,7 @@ class Trail : public Parseable { bool map_type_filter_is_set = false; bool mount_filter_is_set = false; bool profession_filter_is_set = false; + bool red_is_set = false; bool render_ingame_is_set = false; bool render_on_map_is_set = false; bool render_on_minimap_is_set = false; diff --git a/xml_converter/src/xml_converter.cpp b/xml_converter/src/xml_converter.cpp index 1617b099..84bed650 100644 --- a/xml_converter/src/xml_converter.cpp +++ b/xml_converter/src/xml_converter.cpp @@ -217,7 +217,7 @@ vector parse_pois(rapidxml::xml_node<>* root_node, map markers; for (rapidxml::xml_node<>* node = root_node->first_node(); node; node = node->next_sibling()) { - if (get_node_name(node) == "POI") { + if (normalize(get_node_name(node)) == "poi") { Category* default_category = get_category(node, marker_categories, errors); Icon* icon = new Icon(); @@ -229,7 +229,7 @@ vector parse_pois(rapidxml::xml_node<>* root_node, mapinit_from_xml(node, errors); markers.push_back(icon); } - else if (get_node_name(node) == "Trail") { + else if (normalize(get_node_name(node)) == "trail") { Category* default_category = get_category(node, marker_categories, errors); Trail* trail = new Trail(); From 608e08b652d9ef2ba1cf54f627ba5b4972f7b67b Mon Sep 17 00:00:00 2001 From: klingbolt Date: Tue, 21 Mar 2023 20:58:24 -0400 Subject: [PATCH 02/12] Fixing small errors --- xml_converter/doc/trigger/reset_length.md | 4 ++-- xml_converter/generators/code_generator.py | 3 ++- xml_converter/src/icon_gen.cpp | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/xml_converter/doc/trigger/reset_length.md b/xml_converter/doc/trigger/reset_length.md index 64a6279a..30bb9bb7 100644 --- a/xml_converter/doc/trigger/reset_length.md +++ b/xml_converter/doc/trigger/reset_length.md @@ -2,8 +2,8 @@ name: Reset Length type: Float32 applies_to: [Icon] -xml_fields: [ResetOffset] -protobuf_field: trigger.reset_offset +xml_fields: [ResetLength] +protobuf_field: trigger.reset_length compatability: [TacO, BlishHUD, Burrito] --- When using behavior 4 (reappear after timer) this value defines, in seconds, the duration until the marker is reset after being activated. diff --git a/xml_converter/generators/code_generator.py b/xml_converter/generators/code_generator.py index d512637d..03e42ae7 100644 --- a/xml_converter/generators/code_generator.py +++ b/xml_converter/generators/code_generator.py @@ -452,7 +452,7 @@ def generate_cpp_variable_data( side_effects: List[str] = [] args: List[str] = [] xml_child_export: List[str] = [] - xml_parent_export: List[str] = [] + xml_parent_export: str = "" protobuf_field: str = "" is_xml_export: bool = True is_trigger: bool = False @@ -489,6 +489,7 @@ def generate_cpp_variable_data( xml_export = "" args = XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS.copy( + if fieldval['type'] in documentation_type_data: cpp_type = documentation_type_data[fieldval['type']]["cpp_type"] class_name = documentation_type_data[fieldval['type']]["class_name"] diff --git a/xml_converter/src/icon_gen.cpp b/xml_converter/src/icon_gen.cpp index 92ddddb8..5f7fb7e8 100644 --- a/xml_converter/src/icon_gen.cpp +++ b/xml_converter/src/icon_gen.cpp @@ -218,7 +218,7 @@ bool Icon::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectorreset_behavior = parse_reset_behavior(attribute, errors); this->reset_behavior_is_set = true; } - else if (attributename == "resetoffset") { + else if (attributename == "resetlength") { this->reset_length = parse_float(attribute, errors); this->reset_length_is_set = true; } @@ -436,7 +436,7 @@ vector Icon::as_xml() const { xml_node_contents.push_back(" Behavior=\"" + stringify_reset_behavior(this->reset_behavior) + "\""); } if (this->reset_length_is_set) { - xml_node_contents.push_back(" ResetOffset=\"" + stringify_float(this->reset_length) + "\""); + xml_node_contents.push_back(" ResetLength=\"" + stringify_float(this->reset_length) + "\""); } if (this->reset_offset_is_set) { xml_node_contents.push_back(" ResetLength=\"" + stringify_float(this->reset_offset) + "\""); @@ -632,7 +632,7 @@ waypoint::Icon Icon::as_protobuf() const { if (trigger == nullptr) { trigger = new waypoint::Trigger(); } - trigger->set_reset_offset(this->reset_length); + trigger->set_reset_length(this->reset_length); } if (this->reset_offset_is_set) { if (trigger == nullptr) { @@ -831,8 +831,8 @@ void Icon::parse_protobuf(waypoint::Icon proto_icon) { this->reset_behavior = from_proto_reset_behavior(trigger.reset_behavior()); this->reset_behavior_is_set = true; } - if (trigger.reset_offset() != 0) { - this->reset_length = trigger.reset_offset(); + if (trigger.reset_length() != 0) { + this->reset_length = trigger.reset_length(); this->reset_length_is_set = true; } if (trigger.reset_length() != 0) { From 625ded075f28aec7b21033b22cd00ca1628b003d Mon Sep 17 00:00:00 2001 From: klingbolt Date: Tue, 21 Mar 2023 21:09:45 -0400 Subject: [PATCH 03/12] Removing unused variables --- xml_converter/generators/cpp_templates/class_template.cpp | 2 +- xml_converter/src/icon_gen.cpp | 6 +++--- xml_converter/src/icon_gen.hpp | 6 ------ xml_converter/src/trail_gen.cpp | 3 +++ xml_converter/src/trail_gen.hpp | 6 ------ 5 files changed, 7 insertions(+), 16 deletions(-) diff --git a/xml_converter/generators/cpp_templates/class_template.cpp b/xml_converter/generators/cpp_templates/class_template.cpp index 78483ff2..9d0f74e9 100644 --- a/xml_converter/generators/cpp_templates/class_template.cpp +++ b/xml_converter/generators/cpp_templates/class_template.cpp @@ -84,7 +84,7 @@ vector {{cpp_class}}::as_xml() const { {% if attribute_variable.is_xml_export == true %} {% if (attribute_variable.attribute_type in ["CompoundValue", "CompoundCustomClass"] and attribute_variable.compound_name != None) %} if (this->{{attribute_variable.compound_name}}_is_set) { - xml_node_contents.push_back(" {{attribute_variable.default_xml_fields[0]}}=\"" + stringify_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}}) + "\""); + xml_node_contents.push_back(" {{attribute_variable.default_xml_fields[0]}}=\"" + stringify_{{attribute_variable.class_name}}(this->{{attribute_variable.compound_name}}.{{attribute_variable.attribute_name}}) + "\""); } {% else %} if (this->{{attribute_variable.attribute_name}}_is_set) { diff --git a/xml_converter/src/icon_gen.cpp b/xml_converter/src/icon_gen.cpp index 5f7fb7e8..085d1529 100644 --- a/xml_converter/src/icon_gen.cpp +++ b/xml_converter/src/icon_gen.cpp @@ -472,13 +472,13 @@ vector Icon::as_xml() const { xml_node_contents.push_back(" TriggerRange=\"" + stringify_float(this->trigger_range) + "\""); } if (this->position_is_set) { - xml_node_contents.push_back(" XPos=\"" + to_string(this->position.x_position) + "\""); + xml_node_contents.push_back(" XPos=\"" + stringify_float(this->position.x_position) + "\""); } if (this->position_is_set) { - xml_node_contents.push_back(" YPos=\"" + to_string(this->position.y_position) + "\""); + xml_node_contents.push_back(" YPos=\"" + stringify_float(this->position.y_position) + "\""); } if (this->position_is_set) { - xml_node_contents.push_back(" ZPos=\"" + to_string(this->position.z_position) + "\""); + xml_node_contents.push_back(" ZPos=\"" + stringify_float(this->position.z_position) + "\""); } xml_node_contents.push_back("/>"); return xml_node_contents; diff --git a/xml_converter/src/icon_gen.hpp b/xml_converter/src/icon_gen.hpp index d35f058a..919d36b4 100644 --- a/xml_converter/src/icon_gen.hpp +++ b/xml_converter/src/icon_gen.hpp @@ -28,7 +28,6 @@ class Icon : public Parseable { int achievement_bitmask; int achievement_id; bool auto_trigger; - float blue; float bounce_delay; float bounce_duration; float bounce_height; @@ -42,7 +41,6 @@ class Icon : public Parseable { float distance_fade_start; EulerRotation euler_rotation; FestivalFilter festival_filter; - float green; UniqueId guid; bool has_countdown; float height_offset; @@ -59,7 +57,6 @@ class Icon : public Parseable { MountFilter mount_filter; Position position; ProfessionFilter profession_filter; - float red; bool render_ingame; bool render_on_map; bool render_on_minimap; @@ -79,7 +76,6 @@ class Icon : public Parseable { bool achievement_bitmask_is_set = false; bool achievement_id_is_set = false; bool auto_trigger_is_set = false; - bool blue_is_set = false; bool bounce_delay_is_set = false; bool bounce_duration_is_set = false; bool bounce_height_is_set = false; @@ -93,7 +89,6 @@ class Icon : public Parseable { bool distance_fade_start_is_set = false; bool euler_rotation_is_set = false; bool festival_filter_is_set = false; - bool green_is_set = false; bool guid_is_set = false; bool has_countdown_is_set = false; bool height_offset_is_set = false; @@ -110,7 +105,6 @@ class Icon : public Parseable { bool mount_filter_is_set = false; bool position_is_set = false; bool profession_filter_is_set = false; - bool red_is_set = false; bool render_ingame_is_set = false; bool render_on_map_is_set = false; bool render_on_minimap_is_set = false; diff --git a/xml_converter/src/trail_gen.cpp b/xml_converter/src/trail_gen.cpp index d5465b9e..d065b3de 100644 --- a/xml_converter/src/trail_gen.cpp +++ b/xml_converter/src/trail_gen.cpp @@ -199,6 +199,9 @@ vector Trail::as_xml() const { if (this->achievement_id_is_set) { xml_node_contents.push_back(" AchievementId=\"" + stringify_int(this->achievement_id) + "\""); } + if (this->color_is_set) { + xml_node_contents.push_back(" Alpha=\"" + stringify_float(this->color.alpha) + "\""); + } if (this->animation_speed_is_set) { xml_node_contents.push_back(" AnimSpeed=\"" + stringify_float(this->animation_speed) + "\""); } diff --git a/xml_converter/src/trail_gen.hpp b/xml_converter/src/trail_gen.hpp index 5f58444a..d2a5d488 100644 --- a/xml_converter/src/trail_gen.hpp +++ b/xml_converter/src/trail_gen.hpp @@ -26,7 +26,6 @@ class Trail : public Parseable { int achievement_bitmask; int achievement_id; float animation_speed; - float blue; bool can_fade; MarkerCategory category; Color color; @@ -34,7 +33,6 @@ class Trail : public Parseable { float distance_fade_end; float distance_fade_start; FestivalFilter festival_filter; - float green; UniqueId guid; bool is_wall; int map_display_size; @@ -42,7 +40,6 @@ class Trail : public Parseable { MapTypeFilter map_type_filter; MountFilter mount_filter; ProfessionFilter profession_filter; - float red; bool render_ingame; bool render_on_map; bool render_on_minimap; @@ -56,7 +53,6 @@ class Trail : public Parseable { bool achievement_bitmask_is_set = false; bool achievement_id_is_set = false; bool animation_speed_is_set = false; - bool blue_is_set = false; bool can_fade_is_set = false; bool category_is_set = false; bool color_is_set = false; @@ -64,7 +60,6 @@ class Trail : public Parseable { bool distance_fade_end_is_set = false; bool distance_fade_start_is_set = false; bool festival_filter_is_set = false; - bool green_is_set = false; bool guid_is_set = false; bool is_wall_is_set = false; bool map_display_size_is_set = false; @@ -72,7 +67,6 @@ class Trail : public Parseable { bool map_type_filter_is_set = false; bool mount_filter_is_set = false; bool profession_filter_is_set = false; - bool red_is_set = false; bool render_ingame_is_set = false; bool render_on_map_is_set = false; bool render_on_minimap_is_set = false; From 21b1a5126794a7222e7a8e5b997041a53e7f170c Mon Sep 17 00:00:00 2001 From: klingbolt Date: Sat, 6 May 2023 20:30:26 -0400 Subject: [PATCH 04/12] Made changes to color and generated code templates and generator --- xml_converter/doc/position/position.md | 2 +- xml_converter/doc/rotation/euler_rotation.md | 2 +- xml_converter/doc/texture/color.md | 4 +- xml_converter/generators/code_generator.py | 88 ++++---- .../cpp_templates/class_template.cpp | 207 ++++++++---------- .../cpp_templates/class_template.hpp | 4 +- .../cpp_templates/compoundvalue.cpp | 23 +- xml_converter/src/attribute/color.cpp | 83 ++++--- xml_converter/src/attribute/color.hpp | 4 - .../src/attribute/euler_rotation_gen.cpp | 1 + xml_converter/src/category_gen.cpp | 1 + xml_converter/src/icon_gen.cpp | 129 +++++------ xml_converter/src/trail_gen.cpp | 35 +-- 13 files changed, 296 insertions(+), 287 deletions(-) diff --git a/xml_converter/doc/position/position.md b/xml_converter/doc/position/position.md index a6898767..390cc514 100644 --- a/xml_converter/doc/position/position.md +++ b/xml_converter/doc/position/position.md @@ -5,7 +5,7 @@ applies_to: ["Icon"] xml_fields: ["Position"] compatability: [TacO, Burrito, BlishHUD] protobuf_field: position -xml_parent_export: "" +xml_parent_export: [] xml_child_export: ["X Position", "Y Position", "Z Position"] components: diff --git a/xml_converter/doc/rotation/euler_rotation.md b/xml_converter/doc/rotation/euler_rotation.md index 71e56289..d8c3004e 100644 --- a/xml_converter/doc/rotation/euler_rotation.md +++ b/xml_converter/doc/rotation/euler_rotation.md @@ -5,7 +5,7 @@ applies_to: ["Icon"] xml_fields: ["Rotate"] compatability: [TacO, Burrito, BlishHUD] protobuf_field: euler_rotation -xml_parent_export: "'X Rotation', 'Y Rotation', 'Z Rotation'" +xml_parent_export: ['X Rotation', 'Y Rotation', 'Z Rotation'] xml_child_export: [] components: - name: X Rotation diff --git a/xml_converter/doc/texture/color.md b/xml_converter/doc/texture/color.md index d1b69e1d..df6e7965 100644 --- a/xml_converter/doc/texture/color.md +++ b/xml_converter/doc/texture/color.md @@ -6,8 +6,8 @@ applies_to: [Icon, Trail] xml_fields: [Color, BHColor] protobuf_field: rgba_color compatability: [TacO, BlishHUD, Burrito] -xml_parent_export: "{Red},{Green},{Blue}" -xml_child_export: ["Alpha"] +xml_parent_export: ['Red', 'Green', 'Blue'] +xml_child_export: ['Alpha'] components: diff --git a/xml_converter/generators/code_generator.py b/xml_converter/generators/code_generator.py index 03e42ae7..e9ab74f3 100644 --- a/xml_converter/generators/code_generator.py +++ b/xml_converter/generators/code_generator.py @@ -135,12 +135,15 @@ properties: {shared_field_properties} xml_parent_export: - type: string + type: array + items: + type: string + pattern: "^[A-Za-z ]+$" xml_child_export: type: array items: type: string - pattern: "^[A-Za-z' ]+$" + pattern: "^[A-Za-z ]+$" components: type: array items: @@ -157,7 +160,7 @@ type: array items: type: string - pattern: "^[A-Za-z ]+$" + pattern: "^[A-Za-z]+$" protobuf_field: type: string pattern: "^[a-z_.]+$" @@ -189,12 +192,15 @@ uses_file_path: type: boolean xml_parent_export: - type: string + type: array + items: + type: string + pattern: "^[A-Za-z ]+$" xml_child_export: type: array items: type: string - pattern: "^[A-Za-z' ]+$" + pattern: "^[A-Za-z ]+$" """.format( shared_field_properties="""type: @@ -297,15 +303,14 @@ class AttributeVariable: xml_fields: List[str] protobuf_field: str args: List[str] = field(default_factory=list) - default_xml_fields: List[str] = field(default_factory=list) + default_xml_field: str = "" side_effects: List[str] = field(default_factory=list) - compound_name: Optional[str] = None - xml_child_export: str = "" - xml_parent_export: str = "" - compound_name: Optional[str] = None - is_xml_export: bool = True + xml_parent_export: List[str] = field(default_factory=list) + parser_flag_name: Optional[str] = "" + write_to_xml: bool = True is_trigger: bool = False uses_file_path: bool = False + is_component: bool = False XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS: Final[List[str]] = ["attribute", "errors"] @@ -448,13 +453,11 @@ def generate_cpp_variable_data( attribute_name: str = "" attribute_variables: List[AttributeVariable] = [] xml_fields: List[str] = [] - default_xml_fields: List[str] = [] + default_xml_field: str = "" side_effects: List[str] = [] args: List[str] = [] - xml_child_export: List[str] = [] - xml_parent_export: str = "" protobuf_field: str = "" - is_xml_export: bool = True + write_to_xml: bool = True is_trigger: bool = False cpp_includes.hpp_absolute_includes.add("string") @@ -484,18 +487,16 @@ def generate_cpp_variable_data( if doc_type in fieldval['applies_to']: xml_fields = [] - default_xml_fields = [] + default_xml_field = "" side_effects = [] - xml_export = "" - args = XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS.copy( - + write_to_xml = True + args = XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS.copy() if fieldval['type'] in documentation_type_data: cpp_type = documentation_type_data[fieldval['type']]["cpp_type"] class_name = documentation_type_data[fieldval['type']]["class_name"] cpp_includes.cpp_relative_includes.add("attribute/{}.hpp".format(class_name)) - elif fieldval['type'] in ["Custom", "CompoundCustomClass"]: cpp_type = fieldval['class'] class_name = insert_delimiter(fieldval['class'], delimiter="_") @@ -515,7 +516,7 @@ def generate_cpp_variable_data( for x in fieldval['xml_fields']: xml_fields.append(lowercase(x, delimiter="")) - default_xml_fields.append(fieldval['xml_fields'][0]) + default_xml_field = fieldval['xml_fields'][0] if fieldval["protobuf_field"].startswith("trigger"): is_trigger = True @@ -532,30 +533,35 @@ def generate_cpp_variable_data( side_effects.append(attribute_name_from_markdown_data(side_effect)) # Compound Values are unique in that the components have xml fields in addition to the compound variable - if fieldval['type'] == "CompoundValue": - xml_export = fieldval['xml_export'] + if fieldval['type'] in ["CompoundValue", "CompoundCustomClass"]: for component in fieldval['components']: - component_xml_fields = [] - component_default_xml_fields = [] - for item in component['xml_fields']: - if xml_export == "Children": - component_default_xml_fields.append(item) - if xml_export == "Parent": - component_default_xml_fields.append(fieldval["xml_fields"][0]) - component_xml_fields.append(lowercase(item, delimiter="")) + component_xml_fields: List[str] = [] + for x in component['xml_fields']: + component_xml_fields.append(lowercase(x, delimiter="")) + component_default_xml_field: str = "" + component_class_name = documentation_type_data[component['type']]["class_name"] + if component['name'] in fieldval['xml_child_export']: + component_default_xml_field = component['xml_fields'][0] + write_to_xml = True + if component['name'] in fieldval['xml_parent_export']: + component_default_xml_field = fieldval['xml_fields'][0] + write_to_xml = False component_attribute_variable = AttributeVariable( - attribute_name=lowercase(component['name'], delimiter="_"), + attribute_name=lowercase(fieldval['name'], delimiter="_") + "." + lowercase(component['name'], delimiter="_"), attribute_type="CompoundValue", cpp_type=doc_type_to_cpp_type[component['type']], - class_name=class_name, + class_name=component_class_name, xml_fields=component_xml_fields, - default_xml_fields=component_default_xml_fields, - xml_export=xml_export, + default_xml_field=component_default_xml_field, protobuf_field=component["protobuf_field"], - compound_name=lowercase(fieldval['name'], delimiter="_"), + parser_flag_name=lowercase(fieldval['name'], delimiter="_"), + write_to_xml=write_to_xml, + is_component=True, args=args, ) attribute_variables.append(component_attribute_variable) + if fieldval['xml_parent_export'] == []: + write_to_xml = False attribute_variable = AttributeVariable( attribute_name=attribute_name, @@ -563,14 +569,13 @@ def generate_cpp_variable_data( cpp_type=cpp_type, class_name=class_name, xml_fields=xml_fields, - default_xml_fields=default_xml_fields, - xml_child_export=xml_child_export, - xml_parent_export=xml_parent_export, + default_xml_field=default_xml_field, protobuf_field=protobuf_field, is_trigger=is_trigger, args=args, + write_to_xml=write_to_xml, + parser_flag_name=attribute_name, side_effects=side_effects, - is_xml_export=is_xml_export, ) attribute_variables.append(attribute_variable) @@ -653,8 +658,7 @@ def write_attribute(self, output_directory: str) -> None: cpp_type=doc_type_to_cpp_type[component['type']], class_name=attribute_name, xml_fields=xml_fields, - xml_child_export=metadata[filepath]["xml_child_export"], - xml_parent_export=metadata[filepath]["xml_parent_export"], + xml_parent_export=metadata[filepath]['xml_parent_export'], protobuf_field=component["protobuf_field"], is_trigger=is_trigger, ) diff --git a/xml_converter/generators/cpp_templates/class_template.cpp b/xml_converter/generators/cpp_templates/class_template.cpp index 9d0f74e9..a5741248 100644 --- a/xml_converter/generators/cpp_templates/class_template.cpp +++ b/xml_converter/generators/cpp_templates/class_template.cpp @@ -39,26 +39,14 @@ bool {{cpp_class}}::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vec attributename = normalize(get_attribute_name(attribute)); {% for n, attribute_variable in enumerate(attribute_variables) %} {% for i, value in enumerate(attribute_variable.xml_fields) %} - {% if i == 0 and n == 0: %} - if (attributename == "{{value}}") { - this->{{attribute_variable.attribute_name}} = parse_{{attribute_variable.class_name}}({{", ".join(attribute_variable.args)}}); - this->{{attribute_variable.attribute_name}}_is_set = true; - } - {% elif (attribute_variable.attribute_type in ["CompoundValue", "CompoundCustomClass"] and attribute_variable.compound_name != None) %} - else if (attributename == "{{value}}") { - this->{{attribute_variable.compound_name}}.{{attribute_variable.attribute_name}} = parse_float(attribute, errors); - this->{{attribute_variable.compound_name}}_is_set = true; - } - {% else: %} - else if (attributename == "{{value}}") { - this->{{attribute_variable.attribute_name}} = parse_{{attribute_variable.class_name}}({{", ".join(attribute_variable.args)}}); - this->{{attribute_variable.attribute_name}}_is_set = true; - {% for side_effect in attribute_variable.side_effects %} - this->{{side_effect}} = this->{{attribute_variable.class_name}}.side_effect_{{side_effect}}; - this->{{side_effect}}_is_set = true; - {% endfor %} - } - {% endif %} + {{ "" if i == 0 and n == 0 else "else " }}if (attributename == "{{value}}") { + this->{{attribute_variable.attribute_name}} = parse_{{attribute_variable.class_name}}({{", ".join(attribute_variable.args)}}); + this->{{attribute_variable.parser_flag_name}}_is_set = true; + {% for side_effect in attribute_variable.side_effects %} + this->{{side_effect}} = this->{{attribute_variable.class_name}}.side_effect_{{side_effect}}; + this->{{side_effect}}_is_set = true; + {% endfor %} + } {% endfor %} {% endfor %} else { @@ -66,8 +54,7 @@ bool {{cpp_class}}::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vec } return true; } - -{%- if attributes_of_type_marker_category %} +{% if attributes_of_type_marker_category %} bool {{cpp_class}}::validate_attributes_of_type_marker_category() { {% for attribute in attributes_of_type_marker_category %} @@ -81,20 +68,14 @@ vector {{cpp_class}}::as_xml() const { vector xml_node_contents; xml_node_contents.push_back("<{{xml_class_name}} "); {% for attribute_variable in attribute_variables %} - {% if attribute_variable.is_xml_export == true %} - {% if (attribute_variable.attribute_type in ["CompoundValue", "CompoundCustomClass"] and attribute_variable.compound_name != None) %} - if (this->{{attribute_variable.compound_name}}_is_set) { - xml_node_contents.push_back(" {{attribute_variable.default_xml_fields[0]}}=\"" + stringify_{{attribute_variable.class_name}}(this->{{attribute_variable.compound_name}}.{{attribute_variable.attribute_name}}) + "\""); - } - {% else %} - if (this->{{attribute_variable.attribute_name}}_is_set) { - xml_node_contents.push_back(" {{attribute_variable.default_xml_fields[0]}}=\"" + stringify_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}}) + "\""); - } - {% endif %} - {% endif %} -{% endfor %} -{% if cpp_class == "Category": %} - xml_node_contents.push_back(">\n"); + {% if attribute_variable.write_to_xml == true %} + if (this->{{attribute_variable.parser_flag_name}}_is_set) { + xml_node_contents.push_back(" {{attribute_variable.default_xml_field}}=\"" + stringify_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}}) + "\""); + } + {% endif %} + {% endfor %} + {% if cpp_class == "Category": %} + xml_node_contents.push_back(">\n"); for (const auto& [key, val] : this->children) { string text; @@ -118,43 +99,44 @@ waypoint::{{cpp_class}} {{cpp_class}}::as_protobuf() const { waypoint::Trigger* trigger = nullptr; {% endif %} {% for attribute_variable in attribute_variables %} - {% if (attribute_variable.is_trigger == true)%} - {% if (attribute_variable.attribute_type == "Custom")%} - if (this->{{attribute_variable.attribute_name}}_is_set) { - if (trigger == nullptr) { - trigger = new waypoint::Trigger(); + {% if attribute_variable.is_component == false %} + {% if (attribute_variable.is_trigger == true)%} + {% if (attribute_variable.attribute_type == "Custom")%} + if (this->{{attribute_variable.attribute_name}}_is_set) { + if (trigger == nullptr) { + trigger = new waypoint::Trigger(); + } + trigger->set_allocated_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); } - trigger->set_allocated_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); - } - {% elif (attribute_variable.attribute_type == "Enum")%} - if (this->{{attribute_variable.attribute_name}}_is_set) { - if (trigger == nullptr) { - trigger = new waypoint::Trigger(); + {% elif (attribute_variable.attribute_type == "Enum")%} + if (this->{{attribute_variable.attribute_name}}_is_set) { + if (trigger == nullptr) { + trigger = new waypoint::Trigger(); + } + trigger->set_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); } - trigger->set_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); - } - {% else: %} - if (this->{{attribute_variable.attribute_name}}_is_set) { - if (trigger == nullptr) { - trigger = new waypoint::Trigger(); + {% else: %} + if (this->{{attribute_variable.attribute_name}}_is_set) { + if (trigger == nullptr) { + trigger = new waypoint::Trigger(); + } + trigger->set_{{attribute_variable.protobuf_field}}(this->{{attribute_variable.attribute_name}}); } - trigger->set_{{attribute_variable.protobuf_field}}(this->{{attribute_variable.attribute_name}}); - } - {% endif %} - {% else: %} - {% if (attribute_variable.attribute_type == "Enum")%} - if (this->{{attribute_variable.attribute_name}}_is_set) { - proto_{{cpp_class_header}}.set_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); - } - {% elif (attribute_variable.attribute_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"]) and attribute_variable.compound_name == None%} - if (this->{{attribute_variable.attribute_name}}_is_set) { - proto_{{cpp_class_header}}.set_allocated_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); - } - {% elif (attribute_variable.compound_name != None)%} + {% endif %} {% else: %} - if (this->{{attribute_variable.attribute_name}}_is_set) { - proto_{{cpp_class_header}}.set_{{attribute_variable.protobuf_field}}(this->{{attribute_variable.attribute_name}}); - } + {% if (attribute_variable.attribute_type == "Enum")%} + if (this->{{attribute_variable.attribute_name}}_is_set) { + proto_{{cpp_class_header}}.set_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); + } + {% elif (attribute_variable.attribute_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"])%} + if (this->{{attribute_variable.attribute_name}}_is_set) { + proto_{{cpp_class_header}}.set_allocated_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); + } + {% else: %} + if (this->{{attribute_variable.attribute_name}}_is_set) { + proto_{{cpp_class_header}}.set_{{attribute_variable.protobuf_field}}(this->{{attribute_variable.attribute_name}}); + } + {% endif %} {% endif %} {% endif %} {% endfor %} @@ -177,50 +159,51 @@ void {{cpp_class}}::parse_protobuf(waypoint::{{cpp_class}} proto_{{cpp_class_hea waypoint::Trigger trigger = proto_{{cpp_class_header}}.trigger(); {% endif %} {% for attribute_variable in attribute_variables %} - {% if (attribute_variable.is_trigger == true) %} - {% if (attribute_variable.attribute_type == "Custom") %} - if (trigger.has_{{attribute_variable.protobuf_field}}()) { - this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(trigger.{{attribute_variable.protobuf_field}}()); - this->{{attribute_variable.attribute_name}}_is_set = true; - } - {% elif attribute_variable.class_name == "string" %} - if (trigger.{{attribute_variable.protobuf_field}}() != "") { - this->{{attribute_variable.attribute_name}} = trigger.{{attribute_variable.protobuf_field}}(); - this->{{attribute_variable.attribute_name}}_is_set = true; - } - {% elif (attribute_variable.attribute_type == "Enum") %} - if (trigger.{{attribute_variable.protobuf_field}}() != 0) { - this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(trigger.{{attribute_variable.protobuf_field}}()); - this->{{attribute_variable.attribute_name}}_is_set = true; - } - {% else: %} - if (trigger.{{attribute_variable.protobuf_field}}() != 0) { - this->{{attribute_variable.attribute_name}} = trigger.{{attribute_variable.protobuf_field}}(); - this->{{attribute_variable.attribute_name}}_is_set = true; - } - {% endif %} - {% else: %} - {% if (attribute_variable.attribute_type == "Enum") %} - if (proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}() != 0) { - this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}()); - this->{{attribute_variable.attribute_name}}_is_set = true; - } - {% elif (attribute_variable.attribute_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"]) and attribute_variable.compound_name == None%} - if (proto_{{cpp_class_header}}.has_{{attribute_variable.protobuf_field}}()) { - this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}()); - this->{{attribute_variable.attribute_name}}_is_set = true; - } - {% elif (attribute_variable.compound_name != None) %} - {% elif (attribute_variable.class_name == "string") %} - if (proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}() != "") { - this->{{attribute_variable.attribute_name}} = proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}(); - this->{{attribute_variable.attribute_name}}_is_set = true; - } + {% if attribute_variable.is_component == false %} + {% if (attribute_variable.is_trigger == true) %} + {% if (attribute_variable.attribute_type == "Custom") %} + if (trigger.has_{{attribute_variable.protobuf_field}}()) { + this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(trigger.{{attribute_variable.protobuf_field}}()); + this->{{attribute_variable.attribute_name}}_is_set = true; + } + {% elif attribute_variable.class_name == "string" %} + if (trigger.{{attribute_variable.protobuf_field}}() != "") { + this->{{attribute_variable.attribute_name}} = trigger.{{attribute_variable.protobuf_field}}(); + this->{{attribute_variable.attribute_name}}_is_set = true; + } + {% elif (attribute_variable.attribute_type == "Enum") %} + if (trigger.{{attribute_variable.protobuf_field}}() != 0) { + this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(trigger.{{attribute_variable.protobuf_field}}()); + this->{{attribute_variable.attribute_name}}_is_set = true; + } + {% else: %} + if (trigger.{{attribute_variable.protobuf_field}}() != 0) { + this->{{attribute_variable.attribute_name}} = trigger.{{attribute_variable.protobuf_field}}(); + this->{{attribute_variable.attribute_name}}_is_set = true; + } + {% endif %} {% else: %} - if (proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}() != 0) { - this->{{attribute_variable.attribute_name}} = proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}(); - this->{{attribute_variable.attribute_name}}_is_set = true; - } + {% if (attribute_variable.attribute_type == "Enum") %} + if (proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}() != 0) { + this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}()); + this->{{attribute_variable.attribute_name}}_is_set = true; + } + {% elif (attribute_variable.attribute_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"])%} + if (proto_{{cpp_class_header}}.has_{{attribute_variable.protobuf_field}}()) { + this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}()); + this->{{attribute_variable.attribute_name}}_is_set = true; + } + {% elif (attribute_variable.class_name == "string") %} + if (proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}() != "") { + this->{{attribute_variable.attribute_name}} = proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}(); + this->{{attribute_variable.attribute_name}}_is_set = true; + } + {% else: %} + if (proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}() != 0) { + this->{{attribute_variable.attribute_name}} = proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}(); + this->{{attribute_variable.attribute_name}}_is_set = true; + } + {% endif %} {% endif %} {% endif %} {% endfor %} diff --git a/xml_converter/generators/cpp_templates/class_template.hpp b/xml_converter/generators/cpp_templates/class_template.hpp index 7574f46a..014f8431 100644 --- a/xml_converter/generators/cpp_templates/class_template.hpp +++ b/xml_converter/generators/cpp_templates/class_template.hpp @@ -15,12 +15,12 @@ class {{cpp_class}} : public Parseable { public: {% for attribute_variable in attribute_variables: %} - {% if attribute_variable.compound_name == None: %} + {% if attribute_variable.is_component == false: %} {{attribute_variable.cpp_type}} {{attribute_variable.attribute_name}}; {% endif %} {% endfor %} {% for attribute_variable in attribute_variables: %} - {% if attribute_variable.compound_name == None: %} + {% if attribute_variable.is_component == false: %} bool {{attribute_variable.attribute_name}}_is_set = false; {% endif %} {% endfor %} diff --git a/xml_converter/generators/cpp_templates/compoundvalue.cpp b/xml_converter/generators/cpp_templates/compoundvalue.cpp index 97d22ff8..4801beba 100644 --- a/xml_converter/generators/cpp_templates/compoundvalue.cpp +++ b/xml_converter/generators/cpp_templates/compoundvalue.cpp @@ -27,17 +27,18 @@ using namespace std; } return {{attribute_name}}; } -{% if attribute_variables[0].xml_parent_export != "" %} - string stringify_{{attribute_name}}({{class_name}} attribute_value) { - string output; - {% for n, attribute_variable in enumerate(attribute_variables) %} - {% if n == 0: %} - output = to_string(attribute_value.{{attribute_variables[n].attribute_name}}); - {% else %} - output = output + "," + to_string(attribute_value.{{attribute_variables[n].attribute_name}}); - {% endif %} - {% endfor %} - return output; +{% if attribute_variables[0].xml_parent_export != [] %} + +string stringify_{{attribute_name}}({{class_name}} attribute_value) { + string output; + {% for n, attribute_variable in enumerate(attribute_variables) %} + {% if n == 0: %} + output = to_string(attribute_value.{{attribute_variables[n].attribute_name}}); + {% else %} + output = output + "," + to_string(attribute_value.{{attribute_variables[n].attribute_name}}); + {% endif %} + {% endfor %} + return output; } {% endif %} diff --git a/xml_converter/src/attribute/color.cpp b/xml_converter/src/attribute/color.cpp index 83fe3a50..8d418b5f 100644 --- a/xml_converter/src/attribute/color.cpp +++ b/xml_converter/src/attribute/color.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include @@ -14,6 +14,34 @@ using namespace std; +//////////////////////////////////////////////////////////////////////////////// +// int_to_float // float_to_int +// +// Helper functions to convert the value of colors from one type to another. +// Also serves to make sure the values stay within the bounds. +//////////////////////////////////////////////////////////////////////////////// +float int_to_float(int input) { + if (input > 255) { + input = 255; + } + if (input < 0) { + input = 0; + } + float output = static_cast(input) / 255.0f; + return output; +} + +int float_to_int(float input) { + if (input > 1.0) { + input = 1.0; + } + if (input < 0) { + input = 0; + } + int output = static_cast(input * 255); + return output; +} + //////////////////////////////////////////////////////////////////////////////// // parse_color // @@ -36,14 +64,14 @@ Color parse_color(rapidxml::xml_attribute<>* input, vector*) { if (std::regex_match(hex_string, hex_pattern)) { // Extract the R, G, B, and A values from the Hex string if (hex_string.size() == 6 || hex_string.size() == 8) { - color.r = std::stoi(hex_string.substr(0, 2), nullptr, 16); - color.g = std::stoi(hex_string.substr(2, 2), nullptr, 16); - color.b = std::stoi(hex_string.substr(4, 2), nullptr, 16); + color.red = int_to_float(std::stoi(hex_string.substr(0, 2), nullptr, 16)); + color.green = int_to_float(std::stoi(hex_string.substr(2, 2), nullptr, 16)); + color.blue = int_to_float(std::stoi(hex_string.substr(4, 2), nullptr, 16)); if (hex_string.size() == 8) { - color.a = std::stoi(hex_string.substr(6, 2), nullptr, 16); + color.alpha = int_to_float(std::stoi(hex_string.substr(6, 2), nullptr, 16)); } else { - color.a = 255; + color.alpha = 1.0; } } } @@ -59,13 +87,13 @@ string stringify_color(Color attribute_value) { std::stringstream stream; std::string hex_string = "#"; - stream << std::hex << attribute_value.r; + stream << std::hex << float_to_int(attribute_value.red); hex_string += stream.str(); - stream << std::hex << attribute_value.g; + stream << std::hex << float_to_int(attribute_value.green); hex_string += stream.str(); - stream << std::hex << attribute_value.b; + stream << std::hex << float_to_int(attribute_value.blue); hex_string += stream.str(); std::string rgb = hex_string; @@ -80,25 +108,14 @@ string stringify_color(Color attribute_value) { waypoint::RGBAColor* to_proto_color(Color attribute_value) { waypoint::RGBAColor* color = new waypoint::RGBAColor(); // The default RGB in burrito will be 000000 (i.e. black) - + // Default value of alpha in Burrito is 1.0 (i.e. 255) + int int_alpha = 255; // If alpha (float) is not the default value, convert to int if (attribute_value.alpha != 0) { - int alpha_int = static_cast(attribute_value.alpha * 255); - // Check that it doesnt exceed the bounds of {0,255} - if (alpha_int > 255) { - alpha_int = 255; - } - if (alpha_int < 0) { - alpha_int = 0; - } - attribute_value.a = alpha_int; - } - else { - // Default value of alpha in Burrito - attribute_value.a = 255; + int_alpha = float_to_int(attribute_value.alpha); } - uint32_t rgba = ((attribute_value.r & 0xff) << 24) + ((attribute_value.g & 0xff) << 16) + ((attribute_value.b & 0xff) << 8) + (attribute_value.a & 0xff); + uint32_t rgba = ((float_to_int(attribute_value.red) & 0xff) << 24) + ((float_to_int(attribute_value.green) & 0xff) << 16) + ((float_to_int(attribute_value.blue) & 0xff) << 8) + (int_alpha & 0xff); color->set_rgba_color(rgba); return color; } @@ -114,15 +131,15 @@ Color from_proto_color(waypoint::RGBAColor attribute_value) { stream << std::hex << attribute_value.rgba_color(); std::string hex_string = stream.str(); - color.r = std::stoi(hex_string.substr(0, 2), nullptr, 16); - color.g = std::stoi(hex_string.substr(2, 2), nullptr, 16); - color.b = std::stoi(hex_string.substr(4, 2), nullptr, 16); - color.a = std::stoi(hex_string.substr(6, 2), nullptr, 16); + int int_red = std::stoi(hex_string.substr(0, 2), nullptr, 16); + int int_green = std::stoi(hex_string.substr(2, 2), nullptr, 16); + int int_blue = std::stoi(hex_string.substr(4, 2), nullptr, 16); + int int_alpha = std::stoi(hex_string.substr(6, 2), nullptr, 16); + + color.red = int_to_float(int_red); + color.green = int_to_float(int_green); + color.blue = int_to_float(int_blue); + color.alpha = int_to_float(int_alpha); - color.red = static_cast(color.r) / 255.0f; - color.green = static_cast(color.g) / 255.0f; - color.blue = static_cast(color.b) / 255.0f; - color.alpha = static_cast(color.a) / 255.0f; - return color; } diff --git a/xml_converter/src/attribute/color.hpp b/xml_converter/src/attribute/color.hpp index 08449ddd..564e7307 100644 --- a/xml_converter/src/attribute/color.hpp +++ b/xml_converter/src/attribute/color.hpp @@ -16,10 +16,6 @@ class Color { float green; float blue; float alpha; - int r; - int g; - int b; - int a; }; Color parse_color(rapidxml::xml_attribute<>* input, std::vector* errors); diff --git a/xml_converter/src/attribute/euler_rotation_gen.cpp b/xml_converter/src/attribute/euler_rotation_gen.cpp index f960aee7..fcc17686 100644 --- a/xml_converter/src/attribute/euler_rotation_gen.cpp +++ b/xml_converter/src/attribute/euler_rotation_gen.cpp @@ -27,6 +27,7 @@ EulerRotation parse_euler_rotation(rapidxml::xml_attribute<>* input, vector* attribute, vector Category::as_xml() const { vector xml_node_contents; xml_node_contents.push_back("* attribute, vectorachievement_id = parse_int(attribute, errors); this->achievement_id_is_set = true; } - else if (attributename == "alpha") { - this->color.alpha = parse_float(attribute, errors); - this->color_is_set = true; - } else if (attributename == "autotrigger") { this->auto_trigger = parse_bool(attribute, errors); this->auto_trigger_is_set = true; } - else if (attributename == "blue") { - this->color.blue = parse_float(attribute, errors); - this->color_is_set = true; - } else if (attributename == "bouncedelay") { this->bounce_delay = parse_float(attribute, errors); this->bounce_delay_is_set = true; @@ -74,6 +66,22 @@ bool Icon::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectorcolor = parse_color(attribute, errors); this->color_is_set = true; } + else if (attributename == "alpha") { + this->color.alpha = parse_float(attribute, errors); + this->color_is_set = true; + } + else if (attributename == "blue") { + this->color.blue = parse_float(attribute, errors); + this->color_is_set = true; + } + else if (attributename == "green") { + this->color.green = parse_float(attribute, errors); + this->color_is_set = true; + } + else if (attributename == "red") { + this->color.red = parse_float(attribute, errors); + this->color_is_set = true; + } else if (attributename == "copy") { this->copy_clipboard = parse_string(attribute, errors); this->copy_clipboard_is_set = true; @@ -110,14 +118,22 @@ bool Icon::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectoreuler_rotation = parse_euler_rotation(attribute, errors); this->euler_rotation_is_set = true; } + else if (attributename == "rotatex") { + this->euler_rotation.x_rotation = parse_float(attribute, errors); + this->euler_rotation_is_set = true; + } + else if (attributename == "rotatey") { + this->euler_rotation.y_rotation = parse_float(attribute, errors); + this->euler_rotation_is_set = true; + } + else if (attributename == "rotatez") { + this->euler_rotation.z_rotation = parse_float(attribute, errors); + this->euler_rotation_is_set = true; + } else if (attributename == "festival") { this->festival_filter = parse_festival_filter(attribute, errors); this->festival_filter_is_set = true; } - else if (attributename == "green") { - this->color.green = parse_float(attribute, errors); - this->color_is_set = true; - } else if (attributename == "guid") { this->guid = parse_unique_id(attribute, errors); this->guid_is_set = true; @@ -182,14 +198,34 @@ bool Icon::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectorposition = parse_position(attribute, errors); this->position_is_set = true; } + else if (attributename == "xpos") { + this->position.x_position = parse_float(attribute, errors); + this->position_is_set = true; + } + else if (attributename == "positionx") { + this->position.x_position = parse_float(attribute, errors); + this->position_is_set = true; + } + else if (attributename == "ypos") { + this->position.y_position = parse_float(attribute, errors); + this->position_is_set = true; + } + else if (attributename == "positiony") { + this->position.y_position = parse_float(attribute, errors); + this->position_is_set = true; + } + else if (attributename == "zpos") { + this->position.z_position = parse_float(attribute, errors); + this->position_is_set = true; + } + else if (attributename == "positionz") { + this->position.z_position = parse_float(attribute, errors); + this->position_is_set = true; + } else if (attributename == "profession") { this->profession_filter = parse_profession_filter(attribute, errors); this->profession_filter_is_set = true; } - else if (attributename == "red") { - this->color.red = parse_float(attribute, errors); - this->color_is_set = true; - } else if (attributename == "ingamevisibility") { this->render_ingame = parse_bool(attribute, errors); this->render_ingame_is_set = true; @@ -278,47 +314,12 @@ bool Icon::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectortrigger_range = parse_float(attribute, errors); this->trigger_range_is_set = true; } - else if (attributename == "xpos") { - this->position.x_position = parse_float(attribute, errors); - this->position_is_set = true; - } - else if (attributename == "positionx") { - this->position.x_position = parse_float(attribute, errors); - this->position_is_set = true; - } - else if (attributename == "rotatex") { - this->euler_rotation.x_rotation = parse_float(attribute, errors); - this->euler_rotation_is_set = true; - } - else if (attributename == "ypos") { - this->position.y_position = parse_float(attribute, errors); - this->position_is_set = true; - } - else if (attributename == "positiony") { - this->position.y_position = parse_float(attribute, errors); - this->position_is_set = true; - } - else if (attributename == "rotatey") { - this->euler_rotation.y_rotation = parse_float(attribute, errors); - this->euler_rotation_is_set = true; - } - else if (attributename == "zpos") { - this->position.z_position = parse_float(attribute, errors); - this->position_is_set = true; - } - else if (attributename == "positionz") { - this->position.z_position = parse_float(attribute, errors); - this->position_is_set = true; - } - else if (attributename == "rotatez") { - this->euler_rotation.z_rotation = parse_float(attribute, errors); - this->euler_rotation_is_set = true; - } else { return false; } return true; } + bool Icon::validate_attributes_of_type_marker_category() { // TODO: validate "category" // TODO: validate "hide_category" @@ -336,9 +337,6 @@ vector Icon::as_xml() const { if (this->achievement_id_is_set) { xml_node_contents.push_back(" AchievementId=\"" + stringify_int(this->achievement_id) + "\""); } - if (this->color_is_set) { - xml_node_contents.push_back(" Alpha=\"" + stringify_float(this->color.alpha) + "\""); - } if (this->auto_trigger_is_set) { xml_node_contents.push_back(" AutoTrigger=\"" + stringify_bool(this->auto_trigger) + "\""); } @@ -360,6 +358,9 @@ vector Icon::as_xml() const { if (this->color_is_set) { xml_node_contents.push_back(" Color=\"" + stringify_color(this->color) + "\""); } + if (this->color_is_set) { + xml_node_contents.push_back(" Alpha=\"" + stringify_float(this->color.alpha) + "\""); + } if (this->copy_clipboard_is_set) { xml_node_contents.push_back(" Copy=\"" + stringify_string(this->copy_clipboard) + "\""); } @@ -420,6 +421,15 @@ vector Icon::as_xml() const { if (this->mount_filter_is_set) { xml_node_contents.push_back(" Mount=\"" + stringify_mount_filter(this->mount_filter) + "\""); } + if (this->position_is_set) { + xml_node_contents.push_back(" XPos=\"" + stringify_float(this->position.x_position) + "\""); + } + if (this->position_is_set) { + xml_node_contents.push_back(" YPos=\"" + stringify_float(this->position.y_position) + "\""); + } + if (this->position_is_set) { + xml_node_contents.push_back(" ZPos=\"" + stringify_float(this->position.z_position) + "\""); + } if (this->profession_filter_is_set) { xml_node_contents.push_back(" Profession=\"" + stringify_profession_filter(this->profession_filter) + "\""); } @@ -471,15 +481,6 @@ vector Icon::as_xml() const { if (this->trigger_range_is_set) { xml_node_contents.push_back(" TriggerRange=\"" + stringify_float(this->trigger_range) + "\""); } - if (this->position_is_set) { - xml_node_contents.push_back(" XPos=\"" + stringify_float(this->position.x_position) + "\""); - } - if (this->position_is_set) { - xml_node_contents.push_back(" YPos=\"" + stringify_float(this->position.y_position) + "\""); - } - if (this->position_is_set) { - xml_node_contents.push_back(" ZPos=\"" + stringify_float(this->position.z_position) + "\""); - } xml_node_contents.push_back("/>"); return xml_node_contents; } diff --git a/xml_converter/src/trail_gen.cpp b/xml_converter/src/trail_gen.cpp index d065b3de..e2491b5d 100644 --- a/xml_converter/src/trail_gen.cpp +++ b/xml_converter/src/trail_gen.cpp @@ -38,10 +38,6 @@ bool Trail::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectoranimation_speed = parse_float(attribute, errors); this->animation_speed_is_set = true; } - else if (attributename == "blue") { - this->color.blue = parse_float(attribute, errors); - this->color_is_set = true; - } else if (attributename == "canfade") { this->can_fade = parse_bool(attribute, errors); this->can_fade_is_set = true; @@ -62,6 +58,22 @@ bool Trail::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectorcolor = parse_color(attribute, errors); this->color_is_set = true; } + else if (attributename == "alpha") { + this->color.alpha = parse_float(attribute, errors); + this->color_is_set = true; + } + else if (attributename == "blue") { + this->color.blue = parse_float(attribute, errors); + this->color_is_set = true; + } + else if (attributename == "green") { + this->color.green = parse_float(attribute, errors); + this->color_is_set = true; + } + else if (attributename == "red") { + this->color.red = parse_float(attribute, errors); + this->color_is_set = true; + } else if (attributename == "cull") { this->cull_chirality = parse_cull_chirality(attribute, errors); this->cull_chirality_is_set = true; @@ -86,10 +98,6 @@ bool Trail::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectorfestival_filter = parse_festival_filter(attribute, errors); this->festival_filter_is_set = true; } - else if (attributename == "green") { - this->color.green = parse_float(attribute, errors); - this->color_is_set = true; - } else if (attributename == "guid") { this->guid = parse_unique_id(attribute, errors); this->guid_is_set = true; @@ -118,10 +126,6 @@ bool Trail::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectorprofession_filter = parse_profession_filter(attribute, errors); this->profession_filter_is_set = true; } - else if (attributename == "red") { - this->color.red = parse_float(attribute, errors); - this->color_is_set = true; - } else if (attributename == "ingamevisibility") { this->render_ingame = parse_bool(attribute, errors); this->render_ingame_is_set = true; @@ -185,6 +189,7 @@ bool Trail::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vector Trail::as_xml() const { if (this->achievement_id_is_set) { xml_node_contents.push_back(" AchievementId=\"" + stringify_int(this->achievement_id) + "\""); } - if (this->color_is_set) { - xml_node_contents.push_back(" Alpha=\"" + stringify_float(this->color.alpha) + "\""); - } if (this->animation_speed_is_set) { xml_node_contents.push_back(" AnimSpeed=\"" + stringify_float(this->animation_speed) + "\""); } @@ -214,6 +216,9 @@ vector Trail::as_xml() const { if (this->color_is_set) { xml_node_contents.push_back(" Color=\"" + stringify_color(this->color) + "\""); } + if (this->color_is_set) { + xml_node_contents.push_back(" Alpha=\"" + stringify_float(this->color.alpha) + "\""); + } if (this->cull_chirality_is_set) { xml_node_contents.push_back(" Cull=\"" + stringify_cull_chirality(this->cull_chirality) + "\""); } From 2514bb71367156fe1c12c704bb74c020af48cd6b Mon Sep 17 00:00:00 2001 From: klingbolt Date: Sun, 7 May 2023 14:00:17 -0400 Subject: [PATCH 05/12] Removing changes that do not pertain to this PR --- xml_converter/doc/trigger/reset_offset.md | 12 ------------ xml_converter/proto/waypoint.proto | 1 - xml_converter/src/icon_gen.cpp | 17 ----------------- xml_converter/src/icon_gen.hpp | 2 -- xml_converter/src/xml_converter.cpp | 4 ++-- 5 files changed, 2 insertions(+), 34 deletions(-) delete mode 100644 xml_converter/doc/trigger/reset_offset.md diff --git a/xml_converter/doc/trigger/reset_offset.md b/xml_converter/doc/trigger/reset_offset.md deleted file mode 100644 index 38e75bee..00000000 --- a/xml_converter/doc/trigger/reset_offset.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -name: Reset Offset -type: Float32 -applies_to: [Icon] -xml_fields: [ResetLength] -protobuf_field: trigger.reset_length -compatability: [] ---- -When using behavior 5 ('Reappear on map reset') this value defines, in seconds, when the first map cycle of the day begins after the daily reset. -Notes -===== -Behavior 5 is Not implemented by TacO or BlishHUD \ No newline at end of file diff --git a/xml_converter/proto/waypoint.proto b/xml_converter/proto/waypoint.proto index 65156ca2..33545ca2 100644 --- a/xml_converter/proto/waypoint.proto +++ b/xml_converter/proto/waypoint.proto @@ -123,7 +123,6 @@ message Trigger { Category action_show_category = 13; Category action_toggle_category = 14; ResetBehavior reset_behavior = 15; - int32 reset_offset = 16; } message GUID { diff --git a/xml_converter/src/icon_gen.cpp b/xml_converter/src/icon_gen.cpp index 0f4c4252..3fff2a59 100644 --- a/xml_converter/src/icon_gen.cpp +++ b/xml_converter/src/icon_gen.cpp @@ -258,10 +258,6 @@ bool Icon::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectorreset_length = parse_float(attribute, errors); this->reset_length_is_set = true; } - else if (attributename == "resetlength") { - this->reset_offset = parse_float(attribute, errors); - this->reset_offset_is_set = true; - } else if (attributename == "scaleonmapwithzoom") { this->scale_on_map_with_zoom = parse_bool(attribute, errors); this->scale_on_map_with_zoom_is_set = true; @@ -448,9 +444,6 @@ vector Icon::as_xml() const { if (this->reset_length_is_set) { xml_node_contents.push_back(" ResetLength=\"" + stringify_float(this->reset_length) + "\""); } - if (this->reset_offset_is_set) { - xml_node_contents.push_back(" ResetLength=\"" + stringify_float(this->reset_offset) + "\""); - } if (this->scale_on_map_with_zoom_is_set) { xml_node_contents.push_back(" ScaleOnMapWithZoom=\"" + stringify_bool(this->scale_on_map_with_zoom) + "\""); } @@ -635,12 +628,6 @@ waypoint::Icon Icon::as_protobuf() const { } trigger->set_reset_length(this->reset_length); } - if (this->reset_offset_is_set) { - if (trigger == nullptr) { - trigger = new waypoint::Trigger(); - } - trigger->set_reset_length(this->reset_offset); - } if (this->scale_on_map_with_zoom_is_set) { proto_icon.set_scale_on_map_with_zoom(this->scale_on_map_with_zoom); } @@ -836,10 +823,6 @@ void Icon::parse_protobuf(waypoint::Icon proto_icon) { this->reset_length = trigger.reset_length(); this->reset_length_is_set = true; } - if (trigger.reset_length() != 0) { - this->reset_offset = trigger.reset_length(); - this->reset_offset_is_set = true; - } if (proto_icon.scale_on_map_with_zoom() != 0) { this->scale_on_map_with_zoom = proto_icon.scale_on_map_with_zoom(); this->scale_on_map_with_zoom_is_set = true; diff --git a/xml_converter/src/icon_gen.hpp b/xml_converter/src/icon_gen.hpp index 919d36b4..771b72fa 100644 --- a/xml_converter/src/icon_gen.hpp +++ b/xml_converter/src/icon_gen.hpp @@ -62,7 +62,6 @@ class Icon : public Parseable { bool render_on_minimap; ResetBehavior reset_behavior; float reset_length; - float reset_offset; bool scale_on_map_with_zoom; std::string schedule; float schedule_duration; @@ -110,7 +109,6 @@ class Icon : public Parseable { bool render_on_minimap_is_set = false; bool reset_behavior_is_set = false; bool reset_length_is_set = false; - bool reset_offset_is_set = false; bool scale_on_map_with_zoom_is_set = false; bool schedule_is_set = false; bool schedule_duration_is_set = false; diff --git a/xml_converter/src/xml_converter.cpp b/xml_converter/src/xml_converter.cpp index 84bed650..c67414e9 100644 --- a/xml_converter/src/xml_converter.cpp +++ b/xml_converter/src/xml_converter.cpp @@ -217,7 +217,7 @@ vector parse_pois(rapidxml::xml_node<>* root_node, map markers; for (rapidxml::xml_node<>* node = root_node->first_node(); node; node = node->next_sibling()) { - if (normalize(get_node_name(node)) == "poi") { + if (get_node_name(node) == "POI") { Category* default_category = get_category(node, marker_categories, errors); Icon* icon = new Icon(); @@ -229,7 +229,7 @@ vector parse_pois(rapidxml::xml_node<>* root_node, mapinit_from_xml(node, errors); markers.push_back(icon); } - else if (normalize(get_node_name(node)) == "trail") { + else if (get_node_name(node) == "Tcd rail") { Category* default_category = get_category(node, marker_categories, errors); Trail* trail = new Trail(); From 0881b13adb1c6552b7c5a348872ab6cfb281b457 Mon Sep 17 00:00:00 2001 From: klingbolt <89052698+klingbolt@users.noreply.github.com> Date: Sun, 7 May 2023 18:05:45 -0400 Subject: [PATCH 06/12] Update xml_converter.cpp Accidental typo --- xml_converter/src/xml_converter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml_converter/src/xml_converter.cpp b/xml_converter/src/xml_converter.cpp index c67414e9..1617b099 100644 --- a/xml_converter/src/xml_converter.cpp +++ b/xml_converter/src/xml_converter.cpp @@ -229,7 +229,7 @@ vector parse_pois(rapidxml::xml_node<>* root_node, mapinit_from_xml(node, errors); markers.push_back(icon); } - else if (get_node_name(node) == "Tcd rail") { + else if (get_node_name(node) == "Trail") { Category* default_category = get_category(node, marker_categories, errors); Trail* trail = new Trail(); From 661c7716af10788da937962793a9b842ce3bd3ec Mon Sep 17 00:00:00 2001 From: klingbolt Date: Tue, 27 Jun 2023 22:07:28 -0400 Subject: [PATCH 07/12] Addressing code review --- xml_converter/doc/position/position.md | 41 +++---- xml_converter/doc/rotation/euler_rotation.md | 8 +- xml_converter/doc/texture/color.md | 46 ++++---- xml_converter/generators/code_generator.py | 108 ++++++++++++------ .../cpp_templates/class_template.cpp | 4 +- .../cpp_templates/compoundvalue.cpp | 26 ++--- xml_converter/src/attribute/color.cpp | 50 ++++---- 7 files changed, 154 insertions(+), 129 deletions(-) diff --git a/xml_converter/doc/position/position.md b/xml_converter/doc/position/position.md index 390cc514..2e613976 100644 --- a/xml_converter/doc/position/position.md +++ b/xml_converter/doc/position/position.md @@ -5,29 +5,26 @@ applies_to: ["Icon"] xml_fields: ["Position"] compatability: [TacO, Burrito, BlishHUD] protobuf_field: position -xml_parent_export: [] -xml_child_export: ["X Position", "Y Position", "Z Position"] +components_bundled_in_xml: [] +components_separate_in_xml: ["X Position", "Y Position", "Z Position"] components: - - - name: X Position - type: Float32 - xml_fields: [XPos, PositionX] - protobuf_field: "x" - compatability: [TacO, Burrito, BlishHUD] - - - - name: Y Position - type: Float32 - xml_fields: [YPos, PositionY] - protobuf_field: "y" - compatability: [TacO, Burrito, BlishHUD] - - - - name: Z Position - type: Float32 - xml_fields: [ZPos, PositionZ] - protobuf_field: "z" - compatability: [TacO, Burrito, BlishHUD] +- name: X Position + type: Float32 + xml_fields: [XPos, PositionX] + protobuf_field: "x" + compatability: [TacO, Burrito, BlishHUD] + +- name: Y Position + type: Float32 + xml_fields: [YPos, PositionY] + protobuf_field: "y" + compatability: [TacO, Burrito, BlishHUD] + +- name: Z Position + type: Float32 + xml_fields: [ZPos, PositionZ] + protobuf_field: "z" + compatability: [TacO, Burrito, BlishHUD] --- An XYZ location of a point in the game world. diff --git a/xml_converter/doc/rotation/euler_rotation.md b/xml_converter/doc/rotation/euler_rotation.md index d8c3004e..944a2632 100644 --- a/xml_converter/doc/rotation/euler_rotation.md +++ b/xml_converter/doc/rotation/euler_rotation.md @@ -5,29 +5,27 @@ applies_to: ["Icon"] xml_fields: ["Rotate"] compatability: [TacO, Burrito, BlishHUD] protobuf_field: euler_rotation -xml_parent_export: ['X Rotation', 'Y Rotation', 'Z Rotation'] -xml_child_export: [] +components_bundled_in_xml: ['X Rotation', 'Y Rotation', 'Z Rotation'] +components_separate_in_xml: [] components: - name: X Rotation type: Float32 xml_fields: [RotateX] protobuf_field: "x" compatability: [TacO, Burrito, BlishHUD] - - name: Y Rotation type: Float32 xml_fields: [RotateY] protobuf_field: "y" compatability: [TacO, Burrito, BlishHUD] - - name: Z Rotation type: Float32 xml_fields: [RotateZ] protobuf_field: "z" compatability: [TacO, Burrito, BlishHUD] - + --- Euler X Y Z rotation. diff --git a/xml_converter/doc/texture/color.md b/xml_converter/doc/texture/color.md index df6e7965..4824a4df 100644 --- a/xml_converter/doc/texture/color.md +++ b/xml_converter/doc/texture/color.md @@ -6,34 +6,32 @@ applies_to: [Icon, Trail] xml_fields: [Color, BHColor] protobuf_field: rgba_color compatability: [TacO, BlishHUD, Burrito] -xml_parent_export: ['Red', 'Green', 'Blue'] -xml_child_export: ['Alpha'] - +components_bundled_in_xml: ['Red', 'Green', 'Blue'] +components_separate_in_xml: ['Alpha'] components: - - - name: Red # fake, to make thing "square" - type: Float32 - xml_fields: [Red] - protobuf_field: rgba_color - compatability: [TacO, Burrito, BlishHUD] +- name: Red + type: Float32 + xml_fields: [Red] + protobuf_field: rgba_color + compatability: [TacO, Burrito, BlishHUD] - - name: Green - type: Float32 - xml_fields: [Green] - protobuf_field: rgba_color - compatability: [TacO, Burrito, BlishHUD] +- name: Green + type: Float32 + xml_fields: [Green] + protobuf_field: rgba_color + compatability: [TacO, Burrito, BlishHUD] - - name: Blue - type: Float32 - xml_fields: [Blue] - protobuf_field: rgba_color - compatability: [TacO, Burrito, BlishHUD] +- name: Blue + type: Float32 + xml_fields: [Blue] + protobuf_field: rgba_color + compatability: [TacO, Burrito, BlishHUD] - - name: Alpha - type: Float32 - xml_fields: [Alpha] - protobuf_field: rgba_color - compatability: [TacO, Burrito, BlishHUD] +- name: Alpha + type: Float32 + xml_fields: [Alpha] + protobuf_field: rgba_color + compatability: [TacO, Burrito, BlishHUD] --- diff --git a/xml_converter/generators/code_generator.py b/xml_converter/generators/code_generator.py index e9ab74f3..edb0c17b 100644 --- a/xml_converter/generators/code_generator.py +++ b/xml_converter/generators/code_generator.py @@ -131,19 +131,64 @@ const: CompoundValue then: additionalProperties: false - required: [{shared_fields}, components] + required: [{shared_fields}, components_bundled_in_xml, components_separate_in_xml, components] properties: {shared_field_properties} - xml_parent_export: + components_bundled_in_xml: type: array items: type: string - pattern: "^[A-Za-z ]+$" - xml_child_export: + components_separate_in_xml: + type: array + items: + type: string + components: + type: array + items: + type: object + additionalProperties: false + required: [name, type, xml_fields, protobuf_field, compatability] + properties: + name: + type: string + type: + type: string + enum: [Int32, Fixed32, Float32] + xml_fields: + type: array + items: + type: string + pattern: "^[A-Za-z]+$" + protobuf_field: + type: string + pattern: "^[a-z_.]+$" + compatability: + type: array + items: + type: string + enum: [BlishHUD, Burrito, TacO] + ############################# + # CompoundCustomClass Type + ############################# + - if: + properties: + type: + const: CompoundCustomClass + then: + additionalProperties: false + required: [{shared_fields}, components_bundled_in_xml, components_separate_in_xml, class] + properties: + {shared_field_properties} + class: + type: string + components_bundled_in_xml: + type: array + items: + type: string + components_separate_in_xml: type: array items: type: string - pattern: "^[A-Za-z ]+$" components: type: array items: @@ -169,7 +214,6 @@ items: type: string enum: [BlishHUD, Burrito, TacO] - ############################# # Custom Type @@ -191,16 +235,6 @@ type: string uses_file_path: type: boolean - xml_parent_export: - type: array - items: - type: string - pattern: "^[A-Za-z ]+$" - xml_child_export: - type: array - items: - type: string - pattern: "^[A-Za-z ]+$" """.format( shared_field_properties="""type: @@ -305,7 +339,7 @@ class AttributeVariable: args: List[str] = field(default_factory=list) default_xml_field: str = "" side_effects: List[str] = field(default_factory=list) - xml_parent_export: List[str] = field(default_factory=list) + components_bundled_in_xml: List[str] = field(default_factory=list) parser_flag_name: Optional[str] = "" write_to_xml: bool = True is_trigger: bool = False @@ -449,16 +483,9 @@ def generate_cpp_variable_data( doc_type: str, ) -> Tuple[List[AttributeVariable], CPPInclude]: - cpp_includes: CPPInclude = CPPInclude() - attribute_name: str = "" + # Type defining the outputs attribute_variables: List[AttributeVariable] = [] - xml_fields: List[str] = [] - default_xml_field: str = "" - side_effects: List[str] = [] - args: List[str] = [] - protobuf_field: str = "" - write_to_xml: bool = True - is_trigger: bool = False + cpp_includes: CPPInclude = CPPInclude() cpp_includes.hpp_absolute_includes.add("string") cpp_includes.hpp_absolute_includes.add("vector") @@ -486,11 +513,14 @@ def generate_cpp_variable_data( attribute_name = attribute_name_from_markdown_data(fieldval['name']) if doc_type in fieldval['applies_to']: - xml_fields = [] - default_xml_field = "" - side_effects = [] - write_to_xml = True - args = XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS.copy() + xml_fields: List[str] = [] + side_effects: List[str] = [] + write_to_xml: bool = True + protobuf_field: str = "" + is_trigger: bool = False + default_xml_field: str = "" + + args: List[str] = XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS.copy() if fieldval['type'] in documentation_type_data: cpp_type = documentation_type_data[fieldval['type']]["cpp_type"] @@ -536,31 +566,33 @@ def generate_cpp_variable_data( if fieldval['type'] in ["CompoundValue", "CompoundCustomClass"]: for component in fieldval['components']: component_xml_fields: List[str] = [] + component_name: str = attribute_name_from_markdown_data(component['name']) + component_default_xml_field: str = "" for x in component['xml_fields']: component_xml_fields.append(lowercase(x, delimiter="")) - component_default_xml_field: str = "" component_class_name = documentation_type_data[component['type']]["class_name"] - if component['name'] in fieldval['xml_child_export']: + if component['name'] in fieldval['components_separate_in_xml']: component_default_xml_field = component['xml_fields'][0] write_to_xml = True - if component['name'] in fieldval['xml_parent_export']: + if component['name'] in fieldval['components_bundled_in_xml']: component_default_xml_field = fieldval['xml_fields'][0] write_to_xml = False component_attribute_variable = AttributeVariable( - attribute_name=lowercase(fieldval['name'], delimiter="_") + "." + lowercase(component['name'], delimiter="_"), + attribute_name=attribute_name + "." + component_name, attribute_type="CompoundValue", cpp_type=doc_type_to_cpp_type[component['type']], class_name=component_class_name, xml_fields=component_xml_fields, default_xml_field=component_default_xml_field, protobuf_field=component["protobuf_field"], - parser_flag_name=lowercase(fieldval['name'], delimiter="_"), + parser_flag_name=attribute_name, write_to_xml=write_to_xml, is_component=True, args=args, ) attribute_variables.append(component_attribute_variable) - if fieldval['xml_parent_export'] == []: + # If there aren't any components to bundle, we don't want to render the attribute + if fieldval['components_bundled_in_xml'] == []: write_to_xml = False attribute_variable = AttributeVariable( @@ -658,7 +690,7 @@ def write_attribute(self, output_directory: str) -> None: cpp_type=doc_type_to_cpp_type[component['type']], class_name=attribute_name, xml_fields=xml_fields, - xml_parent_export=metadata[filepath]['xml_parent_export'], + components_bundled_in_xml=metadata[filepath]['components_bundled_in_xml'], protobuf_field=component["protobuf_field"], is_trigger=is_trigger, ) diff --git a/xml_converter/generators/cpp_templates/class_template.cpp b/xml_converter/generators/cpp_templates/class_template.cpp index a5741248..f187696b 100644 --- a/xml_converter/generators/cpp_templates/class_template.cpp +++ b/xml_converter/generators/cpp_templates/class_template.cpp @@ -39,7 +39,7 @@ bool {{cpp_class}}::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vec attributename = normalize(get_attribute_name(attribute)); {% for n, attribute_variable in enumerate(attribute_variables) %} {% for i, value in enumerate(attribute_variable.xml_fields) %} - {{ "" if i == 0 and n == 0 else "else " }}if (attributename == "{{value}}") { + {{ "if" if i == n == 0 else "else if" }} (attributename == "{{value}}") { this->{{attribute_variable.attribute_name}} = parse_{{attribute_variable.class_name}}({{", ".join(attribute_variable.args)}}); this->{{attribute_variable.parser_flag_name}}_is_set = true; {% for side_effect in attribute_variable.side_effects %} @@ -87,7 +87,7 @@ vector {{cpp_class}}::as_xml() const { } xml_node_contents.push_back("\n"); - {% else: %} + {% else %} xml_node_contents.push_back("/>"); {% endif %} return xml_node_contents; diff --git a/xml_converter/generators/cpp_templates/compoundvalue.cpp b/xml_converter/generators/cpp_templates/compoundvalue.cpp index 4801beba..36c89cdd 100644 --- a/xml_converter/generators/cpp_templates/compoundvalue.cpp +++ b/xml_converter/generators/cpp_templates/compoundvalue.cpp @@ -27,19 +27,19 @@ using namespace std; } return {{attribute_name}}; } -{% if attribute_variables[0].xml_parent_export != [] %} - -string stringify_{{attribute_name}}({{class_name}} attribute_value) { - string output; - {% for n, attribute_variable in enumerate(attribute_variables) %} - {% if n == 0: %} - output = to_string(attribute_value.{{attribute_variables[n].attribute_name}}); - {% else %} - output = output + "," + to_string(attribute_value.{{attribute_variables[n].attribute_name}}); - {% endif %} - {% endfor %} - return output; -} +{% if attribute_variables[0].components_bundled_in_xml != [] %} + + string stringify_{{attribute_name}}({{class_name}} attribute_value) { + string output; + {% for n, attribute_variable in enumerate(attribute_variables) %} + {% if n == 0: %} + output = to_string(attribute_value.{{attribute_variables[n].attribute_name}}); + {% else %} + output = output + "," + to_string(attribute_value.{{attribute_variables[n].attribute_name}}); + {% endif %} + {% endfor %} + return output; + } {% endif %} waypoint::{{class_name}}* to_proto_{{attribute_name}}({{class_name}} attribute_value) { diff --git a/xml_converter/src/attribute/color.cpp b/xml_converter/src/attribute/color.cpp index 8d418b5f..57f93f36 100644 --- a/xml_converter/src/attribute/color.cpp +++ b/xml_converter/src/attribute/color.cpp @@ -20,7 +20,7 @@ using namespace std; // Helper functions to convert the value of colors from one type to another. // Also serves to make sure the values stay within the bounds. //////////////////////////////////////////////////////////////////////////////// -float int_to_float(int input) { +float convert_color_channel_int_to_float(int input) { if (input > 255) { input = 255; } @@ -31,7 +31,7 @@ float int_to_float(int input) { return output; } -int float_to_int(float input) { +int convert_color_channel_float_to_int(float input) { if (input > 1.0) { input = 1.0; } @@ -47,7 +47,7 @@ int float_to_int(float input) { // // Parses a Color from the value of a rapidxml::xml_attribute. //////////////////////////////////////////////////////////////////////////////// -Color parse_color(rapidxml::xml_attribute<>* input, vector*) { +Color parse_color(rapidxml::xml_attribute<>* input, vector* errors) { Color color; std::string input_string = get_attribute_value(input); std::string hex_string; @@ -59,21 +59,27 @@ Color parse_color(rapidxml::xml_attribute<>* input, vector*) { hex_string = input_string; } - std::regex hex_pattern("^([A-Fa-f0-9]{6})$|^([A-Fa-f0-9]{8})$"); + std::regex hex_pattern("^([A-Fa-f0-9]+)"); if (std::regex_match(hex_string, hex_pattern)) { // Extract the R, G, B, and A values from the Hex string if (hex_string.size() == 6 || hex_string.size() == 8) { - color.red = int_to_float(std::stoi(hex_string.substr(0, 2), nullptr, 16)); - color.green = int_to_float(std::stoi(hex_string.substr(2, 2), nullptr, 16)); - color.blue = int_to_float(std::stoi(hex_string.substr(4, 2), nullptr, 16)); + color.red = convert_color_channel_int_to_float(std::stoi(hex_string.substr(0, 2), nullptr, 16)); + color.green = convert_color_channel_int_to_float(std::stoi(hex_string.substr(2, 2), nullptr, 16)); + color.blue = convert_color_channel_int_to_float(std::stoi(hex_string.substr(4, 2), nullptr, 16)); if (hex_string.size() == 8) { - color.alpha = int_to_float(std::stoi(hex_string.substr(6, 2), nullptr, 16)); + color.alpha = convert_color_channel_int_to_float(std::stoi(hex_string.substr(6, 2), nullptr, 16)); } else { color.alpha = 1.0; } } + else { + errors->push_back(new XMLAttributeValueError("Found a hex color value that was not 6 or 8 characters", input)); + } + } + else { + errors->push_back(new XMLAttributeValueError("Found a color value not in hex format", input)); } return color; } @@ -87,13 +93,13 @@ string stringify_color(Color attribute_value) { std::stringstream stream; std::string hex_string = "#"; - stream << std::hex << float_to_int(attribute_value.red); + stream << std::hex << convert_color_channel_float_to_int(attribute_value.red); hex_string += stream.str(); - stream << std::hex << float_to_int(attribute_value.green); + stream << std::hex << convert_color_channel_float_to_int(attribute_value.green); hex_string += stream.str(); - stream << std::hex << float_to_int(attribute_value.blue); + stream << std::hex << convert_color_channel_float_to_int(attribute_value.blue); hex_string += stream.str(); std::string rgb = hex_string; @@ -112,10 +118,10 @@ waypoint::RGBAColor* to_proto_color(Color attribute_value) { int int_alpha = 255; // If alpha (float) is not the default value, convert to int if (attribute_value.alpha != 0) { - int_alpha = float_to_int(attribute_value.alpha); + int_alpha = convert_color_channel_float_to_int(attribute_value.alpha); } - uint32_t rgba = ((float_to_int(attribute_value.red) & 0xff) << 24) + ((float_to_int(attribute_value.green) & 0xff) << 16) + ((float_to_int(attribute_value.blue) & 0xff) << 8) + (int_alpha & 0xff); + uint32_t rgba = ((convert_color_channel_float_to_int(attribute_value.red) & 0xff) << 24) + ((convert_color_channel_float_to_int(attribute_value.green) & 0xff) << 16) + ((convert_color_channel_float_to_int(attribute_value.blue) & 0xff) << 8) + (int_alpha & 0xff); color->set_rgba_color(rgba); return color; } @@ -128,18 +134,12 @@ waypoint::RGBAColor* to_proto_color(Color attribute_value) { Color from_proto_color(waypoint::RGBAColor attribute_value) { Color color; std::stringstream stream; - stream << std::hex << attribute_value.rgba_color(); - std::string hex_string = stream.str(); - - int int_red = std::stoi(hex_string.substr(0, 2), nullptr, 16); - int int_green = std::stoi(hex_string.substr(2, 2), nullptr, 16); - int int_blue = std::stoi(hex_string.substr(4, 2), nullptr, 16); - int int_alpha = std::stoi(hex_string.substr(6, 2), nullptr, 16); - - color.red = int_to_float(int_red); - color.green = int_to_float(int_green); - color.blue = int_to_float(int_blue); - color.alpha = int_to_float(int_alpha); + uint32_t rgba = attribute_value.rgba_color(); + + color.red = convert_color_channel_int_to_float((rgba >> 24) & 0xff); + color.green = convert_color_channel_int_to_float((rgba >> 16) & 0xff); + color.blue = convert_color_channel_int_to_float((rgba >> 8) & 0xff); + color.alpha = convert_color_channel_int_to_float(rgba & 0xff); return color; } From eafee064317aaf2280bc8035794270747cd4df91 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Wed, 28 Jun 2023 00:13:31 -0400 Subject: [PATCH 08/12] Changed variable name --- xml_converter/generators/code_generator.py | 6 ++-- .../cpp_templates/class_template.cpp | 32 +++++++++---------- .../cpp_templates/class_template.hpp | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/xml_converter/generators/code_generator.py b/xml_converter/generators/code_generator.py index edb0c17b..91bb5232 100644 --- a/xml_converter/generators/code_generator.py +++ b/xml_converter/generators/code_generator.py @@ -340,7 +340,7 @@ class AttributeVariable: default_xml_field: str = "" side_effects: List[str] = field(default_factory=list) components_bundled_in_xml: List[str] = field(default_factory=list) - parser_flag_name: Optional[str] = "" + attribute_flag_name: Optional[str] = "" write_to_xml: bool = True is_trigger: bool = False uses_file_path: bool = False @@ -585,7 +585,7 @@ def generate_cpp_variable_data( xml_fields=component_xml_fields, default_xml_field=component_default_xml_field, protobuf_field=component["protobuf_field"], - parser_flag_name=attribute_name, + attribute_flag_name=attribute_name + "_is_set", write_to_xml=write_to_xml, is_component=True, args=args, @@ -606,7 +606,7 @@ def generate_cpp_variable_data( is_trigger=is_trigger, args=args, write_to_xml=write_to_xml, - parser_flag_name=attribute_name, + attribute_flag_name=attribute_name + "_is_set", side_effects=side_effects, ) attribute_variables.append(attribute_variable) diff --git a/xml_converter/generators/cpp_templates/class_template.cpp b/xml_converter/generators/cpp_templates/class_template.cpp index f187696b..51932b58 100644 --- a/xml_converter/generators/cpp_templates/class_template.cpp +++ b/xml_converter/generators/cpp_templates/class_template.cpp @@ -41,7 +41,7 @@ bool {{cpp_class}}::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vec {% for i, value in enumerate(attribute_variable.xml_fields) %} {{ "if" if i == n == 0 else "else if" }} (attributename == "{{value}}") { this->{{attribute_variable.attribute_name}} = parse_{{attribute_variable.class_name}}({{", ".join(attribute_variable.args)}}); - this->{{attribute_variable.parser_flag_name}}_is_set = true; + this->{{attribute_variable.attribute_flag_name}} = true; {% for side_effect in attribute_variable.side_effects %} this->{{side_effect}} = this->{{attribute_variable.class_name}}.side_effect_{{side_effect}}; this->{{side_effect}}_is_set = true; @@ -69,7 +69,7 @@ vector {{cpp_class}}::as_xml() const { xml_node_contents.push_back("<{{xml_class_name}} "); {% for attribute_variable in attribute_variables %} {% if attribute_variable.write_to_xml == true %} - if (this->{{attribute_variable.parser_flag_name}}_is_set) { + if (this->{{attribute_variable.attribute_flag_name}}) { xml_node_contents.push_back(" {{attribute_variable.default_xml_field}}=\"" + stringify_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}}) + "\""); } {% endif %} @@ -102,21 +102,21 @@ waypoint::{{cpp_class}} {{cpp_class}}::as_protobuf() const { {% if attribute_variable.is_component == false %} {% if (attribute_variable.is_trigger == true)%} {% if (attribute_variable.attribute_type == "Custom")%} - if (this->{{attribute_variable.attribute_name}}_is_set) { + if (this->{{attribute_variable.attribute_flag_name}}) { if (trigger == nullptr) { trigger = new waypoint::Trigger(); } trigger->set_allocated_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); } {% elif (attribute_variable.attribute_type == "Enum")%} - if (this->{{attribute_variable.attribute_name}}_is_set) { + if (this->{{attribute_variable.attribute_flag_name}}) { if (trigger == nullptr) { trigger = new waypoint::Trigger(); } trigger->set_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); } {% else: %} - if (this->{{attribute_variable.attribute_name}}_is_set) { + if (this->{{attribute_variable.attribute_flag_name}}) { if (trigger == nullptr) { trigger = new waypoint::Trigger(); } @@ -125,15 +125,15 @@ waypoint::{{cpp_class}} {{cpp_class}}::as_protobuf() const { {% endif %} {% else: %} {% if (attribute_variable.attribute_type == "Enum")%} - if (this->{{attribute_variable.attribute_name}}_is_set) { + if (this->{{attribute_variable.attribute_flag_name}}) { proto_{{cpp_class_header}}.set_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); } {% elif (attribute_variable.attribute_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"])%} - if (this->{{attribute_variable.attribute_name}}_is_set) { + if (this->{{attribute_variable.attribute_flag_name}}) { proto_{{cpp_class_header}}.set_allocated_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); } {% else: %} - if (this->{{attribute_variable.attribute_name}}_is_set) { + if (this->{{attribute_variable.attribute_flag_name}}) { proto_{{cpp_class_header}}.set_{{attribute_variable.protobuf_field}}(this->{{attribute_variable.attribute_name}}); } {% endif %} @@ -164,44 +164,44 @@ void {{cpp_class}}::parse_protobuf(waypoint::{{cpp_class}} proto_{{cpp_class_hea {% if (attribute_variable.attribute_type == "Custom") %} if (trigger.has_{{attribute_variable.protobuf_field}}()) { this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(trigger.{{attribute_variable.protobuf_field}}()); - this->{{attribute_variable.attribute_name}}_is_set = true; + this->{{attribute_variable.attribute_flag_name}} = true; } {% elif attribute_variable.class_name == "string" %} if (trigger.{{attribute_variable.protobuf_field}}() != "") { this->{{attribute_variable.attribute_name}} = trigger.{{attribute_variable.protobuf_field}}(); - this->{{attribute_variable.attribute_name}}_is_set = true; + this->{{attribute_variable.attribute_flag_name}} = true; } {% elif (attribute_variable.attribute_type == "Enum") %} if (trigger.{{attribute_variable.protobuf_field}}() != 0) { this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(trigger.{{attribute_variable.protobuf_field}}()); - this->{{attribute_variable.attribute_name}}_is_set = true; + this->{{attribute_variable.attribute_flag_name}} = true; } {% else: %} if (trigger.{{attribute_variable.protobuf_field}}() != 0) { this->{{attribute_variable.attribute_name}} = trigger.{{attribute_variable.protobuf_field}}(); - this->{{attribute_variable.attribute_name}}_is_set = true; + this->{{attribute_variable.attribute_flag_name}} = true; } {% endif %} {% else: %} {% if (attribute_variable.attribute_type == "Enum") %} if (proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}() != 0) { this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}()); - this->{{attribute_variable.attribute_name}}_is_set = true; + this->{{attribute_variable.attribute_flag_name}} = true; } {% elif (attribute_variable.attribute_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"])%} if (proto_{{cpp_class_header}}.has_{{attribute_variable.protobuf_field}}()) { this->{{attribute_variable.attribute_name}} = from_proto_{{attribute_variable.class_name}}(proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}()); - this->{{attribute_variable.attribute_name}}_is_set = true; + this->{{attribute_variable.attribute_flag_name}} = true; } {% elif (attribute_variable.class_name == "string") %} if (proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}() != "") { this->{{attribute_variable.attribute_name}} = proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}(); - this->{{attribute_variable.attribute_name}}_is_set = true; + this->{{attribute_variable.attribute_flag_name}} = true; } {% else: %} if (proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}() != 0) { this->{{attribute_variable.attribute_name}} = proto_{{cpp_class_header}}.{{attribute_variable.protobuf_field}}(); - this->{{attribute_variable.attribute_name}}_is_set = true; + this->{{attribute_variable.attribute_flag_name}} = true; } {% endif %} {% endif %} diff --git a/xml_converter/generators/cpp_templates/class_template.hpp b/xml_converter/generators/cpp_templates/class_template.hpp index 014f8431..19d7aa26 100644 --- a/xml_converter/generators/cpp_templates/class_template.hpp +++ b/xml_converter/generators/cpp_templates/class_template.hpp @@ -21,7 +21,7 @@ class {{cpp_class}} : public Parseable { {% endfor %} {% for attribute_variable in attribute_variables: %} {% if attribute_variable.is_component == false: %} - bool {{attribute_variable.attribute_name}}_is_set = false; + bool {{attribute_variable.attribute_flag_name}} = false; {% endif %} {% endfor %} {% if cpp_class == "Category": %} From 15946c93f328930fd41ab8d9d84adcfbda767de1 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Wed, 28 Jun 2023 00:20:17 -0400 Subject: [PATCH 09/12] Addressing IWYU --- xml_converter/src/attribute/color.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/xml_converter/src/attribute/color.cpp b/xml_converter/src/attribute/color.cpp index 57f93f36..24636522 100644 --- a/xml_converter/src/attribute/color.cpp +++ b/xml_converter/src/attribute/color.cpp @@ -2,6 +2,7 @@ #include +#include #include #include #include From 0f49697af6d1fc6ba5559a750fb280cbddd4dbd4 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Thu, 6 Jul 2023 23:36:02 -0400 Subject: [PATCH 10/12] Addressing code review --- xml_converter/generators/code_generator.py | 32 +++++++++++-------- .../cpp_templates/compoundvalue.cpp | 12 ++++--- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/xml_converter/generators/code_generator.py b/xml_converter/generators/code_generator.py index 91bb5232..c35fc1d1 100644 --- a/xml_converter/generators/code_generator.py +++ b/xml_converter/generators/code_generator.py @@ -131,14 +131,14 @@ const: CompoundValue then: additionalProperties: false - required: [{shared_fields}, components_bundled_in_xml, components_separate_in_xml, components] + required: [{shared_fields}, xml_bundled_components, xml_separate_components, components] properties: {shared_field_properties} - components_bundled_in_xml: + xml_bundled_components: type: array items: type: string - components_separate_in_xml: + xml_separate_components: type: array items: type: string @@ -176,16 +176,16 @@ const: CompoundCustomClass then: additionalProperties: false - required: [{shared_fields}, components_bundled_in_xml, components_separate_in_xml, class] + required: [{shared_fields}, xml_bundled_components, xml_separate_components, class] properties: {shared_field_properties} class: type: string - components_bundled_in_xml: + xml_bundled_components: type: array items: type: string - components_separate_in_xml: + xml_separate_components: type: array items: type: string @@ -339,7 +339,7 @@ class AttributeVariable: args: List[str] = field(default_factory=list) default_xml_field: str = "" side_effects: List[str] = field(default_factory=list) - components_bundled_in_xml: List[str] = field(default_factory=list) + xml_bundled_components: List[str] = field(default_factory=list) attribute_flag_name: Optional[str] = "" write_to_xml: bool = True is_trigger: bool = False @@ -510,7 +510,7 @@ def generate_cpp_variable_data( for filepath, document in sorted(self.data.items()): fieldval = document.metadata - attribute_name = attribute_name_from_markdown_data(fieldval['name']) + attribute_name: str = attribute_name_from_markdown_data(fieldval['name']) if doc_type in fieldval['applies_to']: xml_fields: List[str] = [] @@ -571,10 +571,10 @@ def generate_cpp_variable_data( for x in component['xml_fields']: component_xml_fields.append(lowercase(x, delimiter="")) component_class_name = documentation_type_data[component['type']]["class_name"] - if component['name'] in fieldval['components_separate_in_xml']: + if component['name'] in fieldval['xml_separate_components']: component_default_xml_field = component['xml_fields'][0] write_to_xml = True - if component['name'] in fieldval['components_bundled_in_xml']: + if component['name'] in fieldval['xml_bundled_components']: component_default_xml_field = fieldval['xml_fields'][0] write_to_xml = False component_attribute_variable = AttributeVariable( @@ -592,7 +592,7 @@ def generate_cpp_variable_data( ) attribute_variables.append(component_attribute_variable) # If there aren't any components to bundle, we don't want to render the attribute - if fieldval['components_bundled_in_xml'] == []: + if fieldval['xml_bundled_components'] == []: write_to_xml = False attribute_variable = AttributeVariable( @@ -648,8 +648,9 @@ def write_attribute(self, output_directory: str) -> None: for filepath in attribute_names: attribute_variables = [] - attribute_name = attribute_names[filepath] + xml_bundled_components: List[str] = [] metadata[filepath] = self.data[filepath].metadata + attribute_name = attribute_name_from_markdown_data(metadata[filepath]['name']) if metadata[filepath]["protobuf_field"].startswith("trigger"): is_trigger = True @@ -682,15 +683,17 @@ def write_attribute(self, output_directory: str) -> None: raise ValueError("Unexpected type for component. Look at markdown file {attribute_name}".format( attribute_name=attribute_name )) + component_attribute_name: str = attribute_name_from_markdown_data(component['name']) for item in component['xml_fields']: xml_fields.append(normalize(item)) + if component['name'] in metadata[filepath]['xml_bundled_components']: + xml_bundled_components.append(component_attribute_name) attribute_variable = AttributeVariable( - attribute_name=lowercase(component['name'], delimiter="_"), + attribute_name=component_attribute_name, attribute_type=metadata[filepath]['type'], cpp_type=doc_type_to_cpp_type[component['type']], class_name=attribute_name, xml_fields=xml_fields, - components_bundled_in_xml=metadata[filepath]['components_bundled_in_xml'], protobuf_field=component["protobuf_field"], is_trigger=is_trigger, ) @@ -729,6 +732,7 @@ def write_attribute(self, output_directory: str) -> None: attribute_variables=attribute_variables, class_name=capitalize(attribute_name, delimiter=""), enumerate=enumerate, + xml_bundled_components=xml_bundled_components )) ############################################################################ diff --git a/xml_converter/generators/cpp_templates/compoundvalue.cpp b/xml_converter/generators/cpp_templates/compoundvalue.cpp index 36c89cdd..20ff8247 100644 --- a/xml_converter/generators/cpp_templates/compoundvalue.cpp +++ b/xml_converter/generators/cpp_templates/compoundvalue.cpp @@ -27,15 +27,17 @@ using namespace std; } return {{attribute_name}}; } -{% if attribute_variables[0].components_bundled_in_xml != [] %} +{% if xml_bundled_components != [] %} string stringify_{{attribute_name}}({{class_name}} attribute_value) { string output; {% for n, attribute_variable in enumerate(attribute_variables) %} - {% if n == 0: %} - output = to_string(attribute_value.{{attribute_variables[n].attribute_name}}); - {% else %} - output = output + "," + to_string(attribute_value.{{attribute_variables[n].attribute_name}}); + {% if attribute_variables[n].attribute_name in xml_bundled_components %} + {% if n == 0: %} + output = to_string(attribute_value.{{attribute_variables[n].attribute_name}}); + {% else %} + output = output + "," + to_string(attribute_value.{{attribute_variables[n].attribute_name}}); + {% endif %} {% endif %} {% endfor %} return output; From 72ec83ef8d6f4c0d6448997984bb4564c02817a7 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Fri, 7 Jul 2023 19:48:24 -0400 Subject: [PATCH 11/12] Adding the changes to the markdown files --- xml_converter/doc/position/position.md | 4 ++-- xml_converter/doc/rotation/euler_rotation.md | 4 ++-- xml_converter/doc/texture/color.md | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/xml_converter/doc/position/position.md b/xml_converter/doc/position/position.md index 2e613976..6ddc7514 100644 --- a/xml_converter/doc/position/position.md +++ b/xml_converter/doc/position/position.md @@ -5,8 +5,8 @@ applies_to: ["Icon"] xml_fields: ["Position"] compatability: [TacO, Burrito, BlishHUD] protobuf_field: position -components_bundled_in_xml: [] -components_separate_in_xml: ["X Position", "Y Position", "Z Position"] +xml_bundled_components: [] +xml_separate_components: ["X Position", "Y Position", "Z Position"] components: - name: X Position type: Float32 diff --git a/xml_converter/doc/rotation/euler_rotation.md b/xml_converter/doc/rotation/euler_rotation.md index 944a2632..e628fd67 100644 --- a/xml_converter/doc/rotation/euler_rotation.md +++ b/xml_converter/doc/rotation/euler_rotation.md @@ -5,8 +5,8 @@ applies_to: ["Icon"] xml_fields: ["Rotate"] compatability: [TacO, Burrito, BlishHUD] protobuf_field: euler_rotation -components_bundled_in_xml: ['X Rotation', 'Y Rotation', 'Z Rotation'] -components_separate_in_xml: [] +xml_bundled_components: ['X Rotation', 'Y Rotation', 'Z Rotation'] +xml_separate_components: [] components: - name: X Rotation type: Float32 diff --git a/xml_converter/doc/texture/color.md b/xml_converter/doc/texture/color.md index 4824a4df..eff7724e 100644 --- a/xml_converter/doc/texture/color.md +++ b/xml_converter/doc/texture/color.md @@ -6,8 +6,8 @@ applies_to: [Icon, Trail] xml_fields: [Color, BHColor] protobuf_field: rgba_color compatability: [TacO, BlishHUD, Burrito] -components_bundled_in_xml: ['Red', 'Green', 'Blue'] -components_separate_in_xml: ['Alpha'] +xml_bundled_components: ['Red', 'Green', 'Blue'] +xml_separate_components: ['Alpha'] components: - name: Red type: Float32 From b7b0b6aa96dfc9f7e76dfa04dc06e4e84678456e Mon Sep 17 00:00:00 2001 From: klingbolt Date: Fri, 7 Jul 2023 19:57:47 -0400 Subject: [PATCH 12/12] Changed from using a element in an array to the element itself --- xml_converter/generators/cpp_templates/compoundvalue.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xml_converter/generators/cpp_templates/compoundvalue.cpp b/xml_converter/generators/cpp_templates/compoundvalue.cpp index 20ff8247..3480fe65 100644 --- a/xml_converter/generators/cpp_templates/compoundvalue.cpp +++ b/xml_converter/generators/cpp_templates/compoundvalue.cpp @@ -22,7 +22,7 @@ using namespace std; compound_values = split(get_attribute_value(input), ","); if (compound_values.size() == {{ attribute_variables|length }}) { {% for n, attribute_variable in enumerate(attribute_variables) %} - {{attribute_name}}.{{attribute_variables[n].attribute_name}} = std::stof(compound_values[{{n}}]); + {{attribute_name}}.{{attribute_variable.attribute_name}} = std::stof(compound_values[{{n}}]); {% endfor %} } return {{attribute_name}}; @@ -32,11 +32,11 @@ using namespace std; string stringify_{{attribute_name}}({{class_name}} attribute_value) { string output; {% for n, attribute_variable in enumerate(attribute_variables) %} - {% if attribute_variables[n].attribute_name in xml_bundled_components %} + {% if attribute_variable.attribute_name in xml_bundled_components %} {% if n == 0: %} - output = to_string(attribute_value.{{attribute_variables[n].attribute_name}}); + output = to_string(attribute_value.{{attribute_variable.attribute_name}}); {% else %} - output = output + "," + to_string(attribute_value.{{attribute_variables[n].attribute_name}}); + output = output + "," + to_string(attribute_value.{{attribute_variable.attribute_name}}); {% endif %} {% endif %} {% endfor %}