From f895ed4c391aa796cefad670cfc9fd44bc3974f0 Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Sat, 20 Jan 2024 06:42:57 -0600 Subject: [PATCH 01/18] fixing a segault that occurs if a category does not have a "name" attribute --- .../category_name_invalid/input/pack/xml_file.xml | 4 ++++ .../category_name_invalid/output_proto/markers.bin | 0 .../category_name_invalid/output_xml/xml_file.xml | 10 ++++++++++ .../test_cases/category_name_invalid/testcase.yaml | 13 +++++++++++++ xml_converter/src/packaging_xml.cpp | 12 ++++++++++++ xml_converter/src/rapid_helpers.cpp | 14 +++++++++++++- 6 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 xml_converter/integration_tests/test_cases/category_name_invalid/input/pack/xml_file.xml create mode 100644 xml_converter/integration_tests/test_cases/category_name_invalid/output_proto/markers.bin create mode 100644 xml_converter/integration_tests/test_cases/category_name_invalid/output_xml/xml_file.xml create mode 100644 xml_converter/integration_tests/test_cases/category_name_invalid/testcase.yaml diff --git a/xml_converter/integration_tests/test_cases/category_name_invalid/input/pack/xml_file.xml b/xml_converter/integration_tests/test_cases/category_name_invalid/input/pack/xml_file.xml new file mode 100644 index 00000000..7ae0a3fb --- /dev/null +++ b/xml_converter/integration_tests/test_cases/category_name_invalid/input/pack/xml_file.xml @@ -0,0 +1,4 @@ + + + + diff --git a/xml_converter/integration_tests/test_cases/category_name_invalid/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/category_name_invalid/output_proto/markers.bin new file mode 100644 index 00000000..e69de29b diff --git a/xml_converter/integration_tests/test_cases/category_name_invalid/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/category_name_invalid/output_xml/xml_file.xml new file mode 100644 index 00000000..d6de0503 --- /dev/null +++ b/xml_converter/integration_tests/test_cases/category_name_invalid/output_xml/xml_file.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/xml_converter/integration_tests/test_cases/category_name_invalid/testcase.yaml b/xml_converter/integration_tests/test_cases/category_name_invalid/testcase.yaml new file mode 100644 index 00000000..3ca733b5 --- /dev/null +++ b/xml_converter/integration_tests/test_cases/category_name_invalid/testcase.yaml @@ -0,0 +1,13 @@ +input_paths: + "pack": "xml" +expected_stdout: | + Error: Category attribute 'name' is missing or is an empty string when it should be a non-empty string + test_cases/category_name_invalid/input/pack/xml_file.xml + 2 | + | ^^^^^^^^^^^^^^ + Error: Category attribute 'name' is missing or is an empty string when it should be a non-empty string + test_cases/category_name_invalid/input/pack/xml_file.xml + 3 | + | ^^^^^^^^^^^^^^ +expected_stderr: | +expected_returncode: 0 diff --git a/xml_converter/src/packaging_xml.cpp b/xml_converter/src/packaging_xml.cpp index 5efc42ab..44779ebd 100644 --- a/xml_converter/src/packaging_xml.cpp +++ b/xml_converter/src/packaging_xml.cpp @@ -13,8 +13,14 @@ using namespace std; ////////////////////////////////// SERIALIZE /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// +unsigned int UNKNOWN_CATEGORY_COUNTER = 0; void parse_marker_categories(rapidxml::xml_node<>* node, map* marker_categories, vector* errors, string base_dir, int depth = 0) { if (get_node_name(node) == "MarkerCategory") { + // TODO: Eventually this process should be removed. Instead we should be + // grabbing the name during the parsing of all the atrributes to + // avoid doing a secondary search through the attributes, and then + // we should have a method of applying the parsed node on top of + // its hirearchy probably using the is_set flags. string name = lowercase(find_attribute_value(node, "name")); XMLReaderState state = { @@ -22,6 +28,12 @@ void parse_marker_categories(rapidxml::xml_node<>* node, map* marker_categories, }; + if (name == "") { + errors->push_back(new XMLNodeNameError("Category attribute 'name' is missing or is an empty string when it should be a non-empty string", node)); + name = "UNKNOWN_CATEGORY_" + to_string(UNKNOWN_CATEGORY_COUNTER); + UNKNOWN_CATEGORY_COUNTER++; + } + Category* this_category = &(*marker_categories)[name]; this_category->init_from_xml(node, errors, &state); for (rapidxml::xml_node<>* child_node = node->first_node(); child_node; child_node = child_node->next_sibling()) { diff --git a/xml_converter/src/rapid_helpers.cpp b/xml_converter/src/rapid_helpers.cpp index 21d42b98..3b7c313c 100644 --- a/xml_converter/src/rapid_helpers.cpp +++ b/xml_converter/src/rapid_helpers.cpp @@ -9,8 +9,20 @@ using namespace std; +//////////////////////////////////////////////////////////////////////////////// +// find_attribute_value (depricated) +// +// This function does a linear search over an xml node to try and find an +// attribute with the specified name. It the attribute is not found then an +// empty string is returned. +// +// This function is depricated and should not be used by any new code. +//////////////////////////////////////////////////////////////////////////////// string find_attribute_value(rapidxml::xml_node<>* node, string attribute_name) { - auto attribute = node->first_attribute(attribute_name.data(), attribute_name.size(), false); + rapidxml::xml_attribute* attribute = node->first_attribute(attribute_name.data(), attribute_name.size(), false); + if (attribute == nullptr) { + return ""; + } return string(attribute->value(), attribute->value_size()); } From e1187d5c6ea4602566cd2c61bbc1e0e5ed8526a8 Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Sun, 21 Jan 2024 08:37:17 -0600 Subject: [PATCH 02/18] adding a method to overlay the parseable classes on top of themselves This allows us to parse a node it its entirety before trying to read any of its attributes to determine what default values it should have. --- .../cpp_templates/class_template.cpp | 46 ++ .../cpp_templates/class_template.hpp | 2 + .../category_name_invalid/testcase.yaml | 4 +- xml_converter/src/category_gen.cpp | 66 +++ xml_converter/src/category_gen.hpp | 2 + xml_converter/src/icon_gen.cpp | 398 ++++++++++++++++++ xml_converter/src/icon_gen.hpp | 2 + xml_converter/src/packaging_xml.cpp | 32 +- xml_converter/src/trail_gen.cpp | 238 +++++++++++ xml_converter/src/trail_gen.hpp | 2 + 10 files changed, 778 insertions(+), 14 deletions(-) diff --git a/xml_converter/generators/cpp_templates/class_template.cpp b/xml_converter/generators/cpp_templates/class_template.cpp index e8ee4109..a9451c85 100644 --- a/xml_converter/generators/cpp_templates/class_template.cpp +++ b/xml_converter/generators/cpp_templates/class_template.cpp @@ -120,3 +120,49 @@ void {{cpp_class}}::parse_protobuf(waypoint::{{cpp_class}} proto_{{cpp_class_hea {% endif %} {% endfor %} } + + +//////////////////////////////////////////////////////////////////////////////// +// apply_underlay +// +// Transforms this {{cpp_class}} as if this class was overlayed on top of the +// underlay argument. +//////////////////////////////////////////////////////////////////////////////// +void {{cpp_class}}::apply_underlay(const {{cpp_class}}& underlay) { + {% for attribute_variable in attribute_variables %} + {% if attribute_variable.is_component == false %} + if (!this->{{attribute_variable.attribute_flag_name}} && underlay.{{attribute_variable.attribute_flag_name}}) { + this->{{attribute_variable.attribute_name}} = underlay.{{attribute_variable.attribute_name}}; + this->{{attribute_variable.attribute_flag_name}} = true; + } + {% endif %} + {% endfor %} + + {% if cpp_class == "Category": %} + this->default_icon.apply_underlay(underlay.default_icon); + this->default_trail.apply_underlay(underlay.default_trail); + {% endif %} +} + +//////////////////////////////////////////////////////////////////////////////// +// apply_overlay +// +// Transforms this {{cpp_class}} as if the overlay argument were overlayed on +// top of this class. +//////////////////////////////////////////////////////////////////////////////// +void {{cpp_class}}::apply_overlay(const {{cpp_class}}& overlay) { + {% for attribute_variable in attribute_variables %} + {% if attribute_variable.is_component == false %} + if (overlay.{{attribute_variable.attribute_flag_name}}) { + this->{{attribute_variable.attribute_name}} = overlay.{{attribute_variable.attribute_name}}; + this->{{attribute_variable.attribute_flag_name}} = true; + } + {% endif %} + {% endfor %} + + {% if cpp_class == "Category": %} + this->default_icon.apply_overlay(overlay.default_icon); + this->default_trail.apply_overlay(overlay.default_trail); + {% endif %} +} + diff --git a/xml_converter/generators/cpp_templates/class_template.hpp b/xml_converter/generators/cpp_templates/class_template.hpp index 3856a687..d509d9d7 100644 --- a/xml_converter/generators/cpp_templates/class_template.hpp +++ b/xml_converter/generators/cpp_templates/class_template.hpp @@ -39,4 +39,6 @@ class {{cpp_class}} : public Parseable { {% if attributes_of_type_marker_category %} bool validate_attributes_of_type_marker_category(); {% endif %} + void apply_underlay(const {{cpp_class}}& underlay); + void apply_overlay(const {{cpp_class}}& overlay); }; diff --git a/xml_converter/integration_tests/test_cases/category_name_invalid/testcase.yaml b/xml_converter/integration_tests/test_cases/category_name_invalid/testcase.yaml index 3ca733b5..23f69adc 100644 --- a/xml_converter/integration_tests/test_cases/category_name_invalid/testcase.yaml +++ b/xml_converter/integration_tests/test_cases/category_name_invalid/testcase.yaml @@ -1,11 +1,11 @@ input_paths: "pack": "xml" expected_stdout: | - Error: Category attribute 'name' is missing or is an empty string when it should be a non-empty string + Error: Category attribute 'name' is missing so it cannot be properly referenced test_cases/category_name_invalid/input/pack/xml_file.xml 2 | | ^^^^^^^^^^^^^^ - Error: Category attribute 'name' is missing or is an empty string when it should be a non-empty string + Error: Category attribute 'name' is an empty string so it cannot be properly referenced test_cases/category_name_invalid/input/pack/xml_file.xml 3 | | ^^^^^^^^^^^^^^ diff --git a/xml_converter/src/category_gen.cpp b/xml_converter/src/category_gen.cpp index 5d6bc9cc..c7b3f2ae 100644 --- a/xml_converter/src/category_gen.cpp +++ b/xml_converter/src/category_gen.cpp @@ -132,3 +132,69 @@ void Category::parse_protobuf(waypoint::Category proto_category, ProtoReaderStat proto_to_string(proto_category.tip_description(), state, &(this->tooltip_description), &(this->tooltip_description_is_set)); } } + + +//////////////////////////////////////////////////////////////////////////////// +// apply_underlay +// +// Transforms this Category as if this class was overlayed on top of the +// underlay argument. +//////////////////////////////////////////////////////////////////////////////// +void Category::apply_underlay(const Category& underlay) { + if (!this->default_visibility_is_set && underlay.default_visibility_is_set) { + this->default_visibility = underlay.default_visibility; + this->default_visibility_is_set = true; + } + if (!this->display_name_is_set && underlay.display_name_is_set) { + this->display_name = underlay.display_name; + this->display_name_is_set = true; + } + if (!this->is_separator_is_set && underlay.is_separator_is_set) { + this->is_separator = underlay.is_separator; + this->is_separator_is_set = true; + } + if (!this->name_is_set && underlay.name_is_set) { + this->name = underlay.name; + this->name_is_set = true; + } + if (!this->tooltip_description_is_set && underlay.tooltip_description_is_set) { + this->tooltip_description = underlay.tooltip_description; + this->tooltip_description_is_set = true; + } + + this->default_icon.apply_underlay(underlay.default_icon); + this->default_trail.apply_underlay(underlay.default_trail); +} + +//////////////////////////////////////////////////////////////////////////////// +// apply_overlay +// +// Transforms this Category as if the overlay argument were overlayed on +// top of this class. +//////////////////////////////////////////////////////////////////////////////// +void Category::apply_overlay(const Category& overlay) { + if (overlay.default_visibility_is_set) { + this->default_visibility = overlay.default_visibility; + this->default_visibility_is_set = true; + } + if (overlay.display_name_is_set) { + this->display_name = overlay.display_name; + this->display_name_is_set = true; + } + if (overlay.is_separator_is_set) { + this->is_separator = overlay.is_separator; + this->is_separator_is_set = true; + } + if (overlay.name_is_set) { + this->name = overlay.name; + this->name_is_set = true; + } + if (overlay.tooltip_description_is_set) { + this->tooltip_description = overlay.tooltip_description; + this->tooltip_description_is_set = true; + } + + this->default_icon.apply_overlay(overlay.default_icon); + this->default_trail.apply_overlay(overlay.default_trail); +} + diff --git a/xml_converter/src/category_gen.hpp b/xml_converter/src/category_gen.hpp index 4a608fa3..4a6ecf91 100644 --- a/xml_converter/src/category_gen.hpp +++ b/xml_converter/src/category_gen.hpp @@ -36,4 +36,6 @@ class Category : public Parseable { bool init_xml_attribute(rapidxml::xml_attribute<>* attribute, std::vector* errors, XMLReaderState* state); waypoint::Category as_protobuf(ProtoWriterState* state) const; void parse_protobuf(waypoint::Category proto_category, ProtoReaderState* state); + void apply_underlay(const Category& underlay); + void apply_overlay(const Category& overlay); }; diff --git a/xml_converter/src/icon_gen.cpp b/xml_converter/src/icon_gen.cpp index 36c0fbe3..23ddcb20 100644 --- a/xml_converter/src/icon_gen.cpp +++ b/xml_converter/src/icon_gen.cpp @@ -742,3 +742,401 @@ void Icon::parse_protobuf(waypoint::Icon proto_icon, ProtoReaderState* state) { proto_to_float(proto_icon.trigger().range(), state, &(this->trigger_range), &(this->trigger_range_is_set)); } } + + +//////////////////////////////////////////////////////////////////////////////// +// apply_underlay +// +// Transforms this Icon as if this class was overlayed on top of the +// underlay argument. +//////////////////////////////////////////////////////////////////////////////// +void Icon::apply_underlay(const Icon& underlay) { + if (!this->achievement_bitmask_is_set && underlay.achievement_bitmask_is_set) { + this->achievement_bitmask = underlay.achievement_bitmask; + this->achievement_bitmask_is_set = true; + } + if (!this->achievement_id_is_set && underlay.achievement_id_is_set) { + this->achievement_id = underlay.achievement_id; + this->achievement_id_is_set = true; + } + if (!this->auto_trigger_is_set && underlay.auto_trigger_is_set) { + this->auto_trigger = underlay.auto_trigger; + this->auto_trigger_is_set = true; + } + if (!this->bounce_delay_is_set && underlay.bounce_delay_is_set) { + this->bounce_delay = underlay.bounce_delay; + this->bounce_delay_is_set = true; + } + if (!this->bounce_duration_is_set && underlay.bounce_duration_is_set) { + this->bounce_duration = underlay.bounce_duration; + this->bounce_duration_is_set = true; + } + if (!this->bounce_height_is_set && underlay.bounce_height_is_set) { + this->bounce_height = underlay.bounce_height; + this->bounce_height_is_set = true; + } + if (!this->category_is_set && underlay.category_is_set) { + this->category = underlay.category; + this->category_is_set = true; + } + if (!this->color_is_set && underlay.color_is_set) { + this->color = underlay.color; + this->color_is_set = true; + } + if (!this->copy_clipboard_is_set && underlay.copy_clipboard_is_set) { + this->copy_clipboard = underlay.copy_clipboard; + this->copy_clipboard_is_set = true; + } + if (!this->copy_message_is_set && underlay.copy_message_is_set) { + this->copy_message = underlay.copy_message; + this->copy_message_is_set = true; + } + if (!this->cull_chirality_is_set && underlay.cull_chirality_is_set) { + this->cull_chirality = underlay.cull_chirality; + this->cull_chirality_is_set = true; + } + if (!this->disable_player_cutout_is_set && underlay.disable_player_cutout_is_set) { + this->disable_player_cutout = underlay.disable_player_cutout; + this->disable_player_cutout_is_set = true; + } + if (!this->distance_fade_end_is_set && underlay.distance_fade_end_is_set) { + this->distance_fade_end = underlay.distance_fade_end; + this->distance_fade_end_is_set = true; + } + if (!this->distance_fade_start_is_set && underlay.distance_fade_start_is_set) { + this->distance_fade_start = underlay.distance_fade_start; + this->distance_fade_start_is_set = true; + } + if (!this->euler_rotation_is_set && underlay.euler_rotation_is_set) { + this->euler_rotation = underlay.euler_rotation; + this->euler_rotation_is_set = true; + } + if (!this->festival_filter_is_set && underlay.festival_filter_is_set) { + this->festival_filter = underlay.festival_filter; + this->festival_filter_is_set = true; + } + if (!this->guid_is_set && underlay.guid_is_set) { + this->guid = underlay.guid; + this->guid_is_set = true; + } + if (!this->has_countdown_is_set && underlay.has_countdown_is_set) { + this->has_countdown = underlay.has_countdown; + this->has_countdown_is_set = true; + } + if (!this->height_offset_is_set && underlay.height_offset_is_set) { + this->height_offset = underlay.height_offset; + this->height_offset_is_set = true; + } + if (!this->hide_category_is_set && underlay.hide_category_is_set) { + this->hide_category = underlay.hide_category; + this->hide_category_is_set = true; + } + if (!this->icon_is_set && underlay.icon_is_set) { + this->icon = underlay.icon; + this->icon_is_set = true; + } + if (!this->icon_size_is_set && underlay.icon_size_is_set) { + this->icon_size = underlay.icon_size; + this->icon_size_is_set = true; + } + if (!this->info_message_is_set && underlay.info_message_is_set) { + this->info_message = underlay.info_message; + this->info_message_is_set = true; + } + if (!this->invert_visibility_is_set && underlay.invert_visibility_is_set) { + this->invert_visibility = underlay.invert_visibility; + this->invert_visibility_is_set = true; + } + if (!this->map_display_size_is_set && underlay.map_display_size_is_set) { + this->map_display_size = underlay.map_display_size; + this->map_display_size_is_set = true; + } + if (!this->map_id_is_set && underlay.map_id_is_set) { + this->map_id = underlay.map_id; + this->map_id_is_set = true; + } + if (!this->map_type_filter_is_set && underlay.map_type_filter_is_set) { + this->map_type_filter = underlay.map_type_filter; + this->map_type_filter_is_set = true; + } + if (!this->maximum_size_on_screen_is_set && underlay.maximum_size_on_screen_is_set) { + this->maximum_size_on_screen = underlay.maximum_size_on_screen; + this->maximum_size_on_screen_is_set = true; + } + if (!this->minimum_size_on_screen_is_set && underlay.minimum_size_on_screen_is_set) { + this->minimum_size_on_screen = underlay.minimum_size_on_screen; + this->minimum_size_on_screen_is_set = true; + } + if (!this->mount_filter_is_set && underlay.mount_filter_is_set) { + this->mount_filter = underlay.mount_filter; + this->mount_filter_is_set = true; + } + if (!this->position_is_set && underlay.position_is_set) { + this->position = underlay.position; + this->position_is_set = true; + } + if (!this->profession_filter_is_set && underlay.profession_filter_is_set) { + this->profession_filter = underlay.profession_filter; + this->profession_filter_is_set = true; + } + if (!this->render_ingame_is_set && underlay.render_ingame_is_set) { + this->render_ingame = underlay.render_ingame; + this->render_ingame_is_set = true; + } + if (!this->render_on_map_is_set && underlay.render_on_map_is_set) { + this->render_on_map = underlay.render_on_map; + this->render_on_map_is_set = true; + } + if (!this->render_on_minimap_is_set && underlay.render_on_minimap_is_set) { + this->render_on_minimap = underlay.render_on_minimap; + this->render_on_minimap_is_set = true; + } + if (!this->reset_behavior_is_set && underlay.reset_behavior_is_set) { + this->reset_behavior = underlay.reset_behavior; + this->reset_behavior_is_set = true; + } + if (!this->reset_length_is_set && underlay.reset_length_is_set) { + this->reset_length = underlay.reset_length; + this->reset_length_is_set = true; + } + if (!this->scale_on_map_with_zoom_is_set && underlay.scale_on_map_with_zoom_is_set) { + this->scale_on_map_with_zoom = underlay.scale_on_map_with_zoom; + this->scale_on_map_with_zoom_is_set = true; + } + if (!this->schedule_is_set && underlay.schedule_is_set) { + this->schedule = underlay.schedule; + this->schedule_is_set = true; + } + if (!this->schedule_duration_is_set && underlay.schedule_duration_is_set) { + this->schedule_duration = underlay.schedule_duration; + this->schedule_duration_is_set = true; + } + if (!this->show_category_is_set && underlay.show_category_is_set) { + this->show_category = underlay.show_category; + this->show_category_is_set = true; + } + if (!this->specialization_filter_is_set && underlay.specialization_filter_is_set) { + this->specialization_filter = underlay.specialization_filter; + this->specialization_filter_is_set = true; + } + if (!this->species_filter_is_set && underlay.species_filter_is_set) { + this->species_filter = underlay.species_filter; + this->species_filter_is_set = true; + } + if (!this->toggle_category_is_set && underlay.toggle_category_is_set) { + this->toggle_category = underlay.toggle_category; + this->toggle_category_is_set = true; + } + if (!this->tooltip_description_is_set && underlay.tooltip_description_is_set) { + this->tooltip_description = underlay.tooltip_description; + this->tooltip_description_is_set = true; + } + if (!this->tooltip_name_is_set && underlay.tooltip_name_is_set) { + this->tooltip_name = underlay.tooltip_name; + this->tooltip_name_is_set = true; + } + if (!this->trigger_range_is_set && underlay.trigger_range_is_set) { + this->trigger_range = underlay.trigger_range; + this->trigger_range_is_set = true; + } + +} + +//////////////////////////////////////////////////////////////////////////////// +// apply_overlay +// +// Transforms this Icon as if the overlay argument were overlayed on +// top of this class. +//////////////////////////////////////////////////////////////////////////////// +void Icon::apply_overlay(const Icon& overlay) { + if (overlay.achievement_bitmask_is_set) { + this->achievement_bitmask = overlay.achievement_bitmask; + this->achievement_bitmask_is_set = true; + } + if (overlay.achievement_id_is_set) { + this->achievement_id = overlay.achievement_id; + this->achievement_id_is_set = true; + } + if (overlay.auto_trigger_is_set) { + this->auto_trigger = overlay.auto_trigger; + this->auto_trigger_is_set = true; + } + if (overlay.bounce_delay_is_set) { + this->bounce_delay = overlay.bounce_delay; + this->bounce_delay_is_set = true; + } + if (overlay.bounce_duration_is_set) { + this->bounce_duration = overlay.bounce_duration; + this->bounce_duration_is_set = true; + } + if (overlay.bounce_height_is_set) { + this->bounce_height = overlay.bounce_height; + this->bounce_height_is_set = true; + } + if (overlay.category_is_set) { + this->category = overlay.category; + this->category_is_set = true; + } + if (overlay.color_is_set) { + this->color = overlay.color; + this->color_is_set = true; + } + if (overlay.copy_clipboard_is_set) { + this->copy_clipboard = overlay.copy_clipboard; + this->copy_clipboard_is_set = true; + } + if (overlay.copy_message_is_set) { + this->copy_message = overlay.copy_message; + this->copy_message_is_set = true; + } + if (overlay.cull_chirality_is_set) { + this->cull_chirality = overlay.cull_chirality; + this->cull_chirality_is_set = true; + } + if (overlay.disable_player_cutout_is_set) { + this->disable_player_cutout = overlay.disable_player_cutout; + this->disable_player_cutout_is_set = true; + } + if (overlay.distance_fade_end_is_set) { + this->distance_fade_end = overlay.distance_fade_end; + this->distance_fade_end_is_set = true; + } + if (overlay.distance_fade_start_is_set) { + this->distance_fade_start = overlay.distance_fade_start; + this->distance_fade_start_is_set = true; + } + if (overlay.euler_rotation_is_set) { + this->euler_rotation = overlay.euler_rotation; + this->euler_rotation_is_set = true; + } + if (overlay.festival_filter_is_set) { + this->festival_filter = overlay.festival_filter; + this->festival_filter_is_set = true; + } + if (overlay.guid_is_set) { + this->guid = overlay.guid; + this->guid_is_set = true; + } + if (overlay.has_countdown_is_set) { + this->has_countdown = overlay.has_countdown; + this->has_countdown_is_set = true; + } + if (overlay.height_offset_is_set) { + this->height_offset = overlay.height_offset; + this->height_offset_is_set = true; + } + if (overlay.hide_category_is_set) { + this->hide_category = overlay.hide_category; + this->hide_category_is_set = true; + } + if (overlay.icon_is_set) { + this->icon = overlay.icon; + this->icon_is_set = true; + } + if (overlay.icon_size_is_set) { + this->icon_size = overlay.icon_size; + this->icon_size_is_set = true; + } + if (overlay.info_message_is_set) { + this->info_message = overlay.info_message; + this->info_message_is_set = true; + } + if (overlay.invert_visibility_is_set) { + this->invert_visibility = overlay.invert_visibility; + this->invert_visibility_is_set = true; + } + if (overlay.map_display_size_is_set) { + this->map_display_size = overlay.map_display_size; + this->map_display_size_is_set = true; + } + if (overlay.map_id_is_set) { + this->map_id = overlay.map_id; + this->map_id_is_set = true; + } + if (overlay.map_type_filter_is_set) { + this->map_type_filter = overlay.map_type_filter; + this->map_type_filter_is_set = true; + } + if (overlay.maximum_size_on_screen_is_set) { + this->maximum_size_on_screen = overlay.maximum_size_on_screen; + this->maximum_size_on_screen_is_set = true; + } + if (overlay.minimum_size_on_screen_is_set) { + this->minimum_size_on_screen = overlay.minimum_size_on_screen; + this->minimum_size_on_screen_is_set = true; + } + if (overlay.mount_filter_is_set) { + this->mount_filter = overlay.mount_filter; + this->mount_filter_is_set = true; + } + if (overlay.position_is_set) { + this->position = overlay.position; + this->position_is_set = true; + } + if (overlay.profession_filter_is_set) { + this->profession_filter = overlay.profession_filter; + this->profession_filter_is_set = true; + } + if (overlay.render_ingame_is_set) { + this->render_ingame = overlay.render_ingame; + this->render_ingame_is_set = true; + } + if (overlay.render_on_map_is_set) { + this->render_on_map = overlay.render_on_map; + this->render_on_map_is_set = true; + } + if (overlay.render_on_minimap_is_set) { + this->render_on_minimap = overlay.render_on_minimap; + this->render_on_minimap_is_set = true; + } + if (overlay.reset_behavior_is_set) { + this->reset_behavior = overlay.reset_behavior; + this->reset_behavior_is_set = true; + } + if (overlay.reset_length_is_set) { + this->reset_length = overlay.reset_length; + this->reset_length_is_set = true; + } + if (overlay.scale_on_map_with_zoom_is_set) { + this->scale_on_map_with_zoom = overlay.scale_on_map_with_zoom; + this->scale_on_map_with_zoom_is_set = true; + } + if (overlay.schedule_is_set) { + this->schedule = overlay.schedule; + this->schedule_is_set = true; + } + if (overlay.schedule_duration_is_set) { + this->schedule_duration = overlay.schedule_duration; + this->schedule_duration_is_set = true; + } + if (overlay.show_category_is_set) { + this->show_category = overlay.show_category; + this->show_category_is_set = true; + } + if (overlay.specialization_filter_is_set) { + this->specialization_filter = overlay.specialization_filter; + this->specialization_filter_is_set = true; + } + if (overlay.species_filter_is_set) { + this->species_filter = overlay.species_filter; + this->species_filter_is_set = true; + } + if (overlay.toggle_category_is_set) { + this->toggle_category = overlay.toggle_category; + this->toggle_category_is_set = true; + } + if (overlay.tooltip_description_is_set) { + this->tooltip_description = overlay.tooltip_description; + this->tooltip_description_is_set = true; + } + if (overlay.tooltip_name_is_set) { + this->tooltip_name = overlay.tooltip_name; + this->tooltip_name_is_set = true; + } + if (overlay.trigger_range_is_set) { + this->trigger_range = overlay.trigger_range; + this->trigger_range_is_set = true; + } + +} + diff --git a/xml_converter/src/icon_gen.hpp b/xml_converter/src/icon_gen.hpp index 70410b78..efbdf12d 100644 --- a/xml_converter/src/icon_gen.hpp +++ b/xml_converter/src/icon_gen.hpp @@ -127,4 +127,6 @@ class Icon : public Parseable { waypoint::Icon as_protobuf(ProtoWriterState* state) const; void parse_protobuf(waypoint::Icon proto_icon, ProtoReaderState* state); bool validate_attributes_of_type_marker_category(); + void apply_underlay(const Icon& underlay); + void apply_overlay(const Icon& overlay); }; diff --git a/xml_converter/src/packaging_xml.cpp b/xml_converter/src/packaging_xml.cpp index 44779ebd..b5dddf16 100644 --- a/xml_converter/src/packaging_xml.cpp +++ b/xml_converter/src/packaging_xml.cpp @@ -16,28 +16,36 @@ using namespace std; unsigned int UNKNOWN_CATEGORY_COUNTER = 0; void parse_marker_categories(rapidxml::xml_node<>* node, map* marker_categories, vector* errors, string base_dir, int depth = 0) { if (get_node_name(node) == "MarkerCategory") { - // TODO: Eventually this process should be removed. Instead we should be - // grabbing the name during the parsing of all the atrributes to - // avoid doing a secondary search through the attributes, and then - // we should have a method of applying the parsed node on top of - // its hirearchy probably using the is_set flags. - string name = lowercase(find_attribute_value(node, "name")); - XMLReaderState state = { base_dir, marker_categories, }; - if (name == "") { - errors->push_back(new XMLNodeNameError("Category attribute 'name' is missing or is an empty string when it should be a non-empty string", node)); + Category new_category; + new_category.init_from_xml(node, errors, &state); + + string name; + if (!new_category.name_is_set) { + errors->push_back(new XMLNodeNameError("Category attribute 'name' is missing so it cannot be properly referenced", node)); + // TODO: Maybe fall back on display name slugification. + name = "UNKNOWN_CATEGORY_" + to_string(UNKNOWN_CATEGORY_COUNTER); + UNKNOWN_CATEGORY_COUNTER++; + } + else if (new_category.name == "") { + errors->push_back(new XMLNodeNameError("Category attribute 'name' is an empty string so it cannot be properly referenced", node)); + // TODO: Maybe fall back on display name slugification. name = "UNKNOWN_CATEGORY_" + to_string(UNKNOWN_CATEGORY_COUNTER); UNKNOWN_CATEGORY_COUNTER++; } + else { + name = lowercase(new_category.name); + } + + Category* existing_category = &(*marker_categories)[name]; + existing_category->apply_overlay(new_category); - Category* this_category = &(*marker_categories)[name]; - this_category->init_from_xml(node, errors, &state); for (rapidxml::xml_node<>* child_node = node->first_node(); child_node; child_node = child_node->next_sibling()) { - parse_marker_categories(child_node, &(this_category->children), errors, base_dir, depth + 1); + parse_marker_categories(child_node, &(existing_category->children), errors, base_dir, depth + 1); } } else { diff --git a/xml_converter/src/trail_gen.cpp b/xml_converter/src/trail_gen.cpp index 23367e69..8ef6401d 100644 --- a/xml_converter/src/trail_gen.cpp +++ b/xml_converter/src/trail_gen.cpp @@ -440,3 +440,241 @@ void Trail::parse_protobuf(waypoint::Trail proto_trail, ProtoReaderState* state) proto_to_float(proto_trail.scale(), state, &(this->trail_scale), &(this->trail_scale_is_set)); } } + + +//////////////////////////////////////////////////////////////////////////////// +// apply_underlay +// +// Transforms this Trail as if this class was overlayed on top of the +// underlay argument. +//////////////////////////////////////////////////////////////////////////////// +void Trail::apply_underlay(const Trail& underlay) { + if (!this->achievement_bitmask_is_set && underlay.achievement_bitmask_is_set) { + this->achievement_bitmask = underlay.achievement_bitmask; + this->achievement_bitmask_is_set = true; + } + if (!this->achievement_id_is_set && underlay.achievement_id_is_set) { + this->achievement_id = underlay.achievement_id; + this->achievement_id_is_set = true; + } + if (!this->animation_speed_is_set && underlay.animation_speed_is_set) { + this->animation_speed = underlay.animation_speed; + this->animation_speed_is_set = true; + } + if (!this->category_is_set && underlay.category_is_set) { + this->category = underlay.category; + this->category_is_set = true; + } + if (!this->color_is_set && underlay.color_is_set) { + this->color = underlay.color; + this->color_is_set = true; + } + if (!this->cull_chirality_is_set && underlay.cull_chirality_is_set) { + this->cull_chirality = underlay.cull_chirality; + this->cull_chirality_is_set = true; + } + if (!this->disable_player_cutout_is_set && underlay.disable_player_cutout_is_set) { + this->disable_player_cutout = underlay.disable_player_cutout; + this->disable_player_cutout_is_set = true; + } + if (!this->distance_fade_end_is_set && underlay.distance_fade_end_is_set) { + this->distance_fade_end = underlay.distance_fade_end; + this->distance_fade_end_is_set = true; + } + if (!this->distance_fade_start_is_set && underlay.distance_fade_start_is_set) { + this->distance_fade_start = underlay.distance_fade_start; + this->distance_fade_start_is_set = true; + } + if (!this->festival_filter_is_set && underlay.festival_filter_is_set) { + this->festival_filter = underlay.festival_filter; + this->festival_filter_is_set = true; + } + if (!this->guid_is_set && underlay.guid_is_set) { + this->guid = underlay.guid; + this->guid_is_set = true; + } + if (!this->is_wall_is_set && underlay.is_wall_is_set) { + this->is_wall = underlay.is_wall; + this->is_wall_is_set = true; + } + if (!this->map_display_size_is_set && underlay.map_display_size_is_set) { + this->map_display_size = underlay.map_display_size; + this->map_display_size_is_set = true; + } + if (!this->map_id_is_set && underlay.map_id_is_set) { + this->map_id = underlay.map_id; + this->map_id_is_set = true; + } + if (!this->map_type_filter_is_set && underlay.map_type_filter_is_set) { + this->map_type_filter = underlay.map_type_filter; + this->map_type_filter_is_set = true; + } + if (!this->mount_filter_is_set && underlay.mount_filter_is_set) { + this->mount_filter = underlay.mount_filter; + this->mount_filter_is_set = true; + } + if (!this->profession_filter_is_set && underlay.profession_filter_is_set) { + this->profession_filter = underlay.profession_filter; + this->profession_filter_is_set = true; + } + if (!this->render_ingame_is_set && underlay.render_ingame_is_set) { + this->render_ingame = underlay.render_ingame; + this->render_ingame_is_set = true; + } + if (!this->render_on_map_is_set && underlay.render_on_map_is_set) { + this->render_on_map = underlay.render_on_map; + this->render_on_map_is_set = true; + } + if (!this->render_on_minimap_is_set && underlay.render_on_minimap_is_set) { + this->render_on_minimap = underlay.render_on_minimap; + this->render_on_minimap_is_set = true; + } + if (!this->schedule_is_set && underlay.schedule_is_set) { + this->schedule = underlay.schedule; + this->schedule_is_set = true; + } + if (!this->schedule_duration_is_set && underlay.schedule_duration_is_set) { + this->schedule_duration = underlay.schedule_duration; + this->schedule_duration_is_set = true; + } + if (!this->specialization_filter_is_set && underlay.specialization_filter_is_set) { + this->specialization_filter = underlay.specialization_filter; + this->specialization_filter_is_set = true; + } + if (!this->species_filter_is_set && underlay.species_filter_is_set) { + this->species_filter = underlay.species_filter; + this->species_filter_is_set = true; + } + if (!this->texture_is_set && underlay.texture_is_set) { + this->texture = underlay.texture; + this->texture_is_set = true; + } + if (!this->trail_data_is_set && underlay.trail_data_is_set) { + this->trail_data = underlay.trail_data; + this->trail_data_is_set = true; + } + if (!this->trail_scale_is_set && underlay.trail_scale_is_set) { + this->trail_scale = underlay.trail_scale; + this->trail_scale_is_set = true; + } + +} + +//////////////////////////////////////////////////////////////////////////////// +// apply_overlay +// +// Transforms this Trail as if the overlay argument were overlayed on +// top of this class. +//////////////////////////////////////////////////////////////////////////////// +void Trail::apply_overlay(const Trail& overlay) { + if (overlay.achievement_bitmask_is_set) { + this->achievement_bitmask = overlay.achievement_bitmask; + this->achievement_bitmask_is_set = true; + } + if (overlay.achievement_id_is_set) { + this->achievement_id = overlay.achievement_id; + this->achievement_id_is_set = true; + } + if (overlay.animation_speed_is_set) { + this->animation_speed = overlay.animation_speed; + this->animation_speed_is_set = true; + } + if (overlay.category_is_set) { + this->category = overlay.category; + this->category_is_set = true; + } + if (overlay.color_is_set) { + this->color = overlay.color; + this->color_is_set = true; + } + if (overlay.cull_chirality_is_set) { + this->cull_chirality = overlay.cull_chirality; + this->cull_chirality_is_set = true; + } + if (overlay.disable_player_cutout_is_set) { + this->disable_player_cutout = overlay.disable_player_cutout; + this->disable_player_cutout_is_set = true; + } + if (overlay.distance_fade_end_is_set) { + this->distance_fade_end = overlay.distance_fade_end; + this->distance_fade_end_is_set = true; + } + if (overlay.distance_fade_start_is_set) { + this->distance_fade_start = overlay.distance_fade_start; + this->distance_fade_start_is_set = true; + } + if (overlay.festival_filter_is_set) { + this->festival_filter = overlay.festival_filter; + this->festival_filter_is_set = true; + } + if (overlay.guid_is_set) { + this->guid = overlay.guid; + this->guid_is_set = true; + } + if (overlay.is_wall_is_set) { + this->is_wall = overlay.is_wall; + this->is_wall_is_set = true; + } + if (overlay.map_display_size_is_set) { + this->map_display_size = overlay.map_display_size; + this->map_display_size_is_set = true; + } + if (overlay.map_id_is_set) { + this->map_id = overlay.map_id; + this->map_id_is_set = true; + } + if (overlay.map_type_filter_is_set) { + this->map_type_filter = overlay.map_type_filter; + this->map_type_filter_is_set = true; + } + if (overlay.mount_filter_is_set) { + this->mount_filter = overlay.mount_filter; + this->mount_filter_is_set = true; + } + if (overlay.profession_filter_is_set) { + this->profession_filter = overlay.profession_filter; + this->profession_filter_is_set = true; + } + if (overlay.render_ingame_is_set) { + this->render_ingame = overlay.render_ingame; + this->render_ingame_is_set = true; + } + if (overlay.render_on_map_is_set) { + this->render_on_map = overlay.render_on_map; + this->render_on_map_is_set = true; + } + if (overlay.render_on_minimap_is_set) { + this->render_on_minimap = overlay.render_on_minimap; + this->render_on_minimap_is_set = true; + } + if (overlay.schedule_is_set) { + this->schedule = overlay.schedule; + this->schedule_is_set = true; + } + if (overlay.schedule_duration_is_set) { + this->schedule_duration = overlay.schedule_duration; + this->schedule_duration_is_set = true; + } + if (overlay.specialization_filter_is_set) { + this->specialization_filter = overlay.specialization_filter; + this->specialization_filter_is_set = true; + } + if (overlay.species_filter_is_set) { + this->species_filter = overlay.species_filter; + this->species_filter_is_set = true; + } + if (overlay.texture_is_set) { + this->texture = overlay.texture; + this->texture_is_set = true; + } + if (overlay.trail_data_is_set) { + this->trail_data = overlay.trail_data; + this->trail_data_is_set = true; + } + if (overlay.trail_scale_is_set) { + this->trail_scale = overlay.trail_scale; + this->trail_scale_is_set = true; + } + +} + diff --git a/xml_converter/src/trail_gen.hpp b/xml_converter/src/trail_gen.hpp index d10ea163..28f0ec19 100644 --- a/xml_converter/src/trail_gen.hpp +++ b/xml_converter/src/trail_gen.hpp @@ -85,4 +85,6 @@ class Trail : public Parseable { waypoint::Trail as_protobuf(ProtoWriterState* state) const; void parse_protobuf(waypoint::Trail proto_trail, ProtoReaderState* state); bool validate_attributes_of_type_marker_category(); + void apply_underlay(const Trail& underlay); + void apply_overlay(const Trail& overlay); }; From 122366940ab697f66c77bf11663961ebdbd6d47a Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Sun, 21 Jan 2024 08:39:19 -0600 Subject: [PATCH 03/18] remoing the now unused find_attribute_value function --- xml_converter/src/rapid_helpers.cpp | 17 ----------------- xml_converter/src/rapid_helpers.hpp | 1 - 2 files changed, 18 deletions(-) diff --git a/xml_converter/src/rapid_helpers.cpp b/xml_converter/src/rapid_helpers.cpp index 3b7c313c..c109ba8d 100644 --- a/xml_converter/src/rapid_helpers.cpp +++ b/xml_converter/src/rapid_helpers.cpp @@ -9,23 +9,6 @@ using namespace std; -//////////////////////////////////////////////////////////////////////////////// -// find_attribute_value (depricated) -// -// This function does a linear search over an xml node to try and find an -// attribute with the specified name. It the attribute is not found then an -// empty string is returned. -// -// This function is depricated and should not be used by any new code. -//////////////////////////////////////////////////////////////////////////////// -string find_attribute_value(rapidxml::xml_node<>* node, string attribute_name) { - rapidxml::xml_attribute* attribute = node->first_attribute(attribute_name.data(), attribute_name.size(), false); - if (attribute == nullptr) { - return ""; - } - - return string(attribute->value(), attribute->value_size()); -} rapidxml::xml_attribute<>* find_attribute(rapidxml::xml_node<>* node, string attribute_name) { return node->first_attribute(attribute_name.data(), attribute_name.size(), false); diff --git a/xml_converter/src/rapid_helpers.hpp b/xml_converter/src/rapid_helpers.hpp index 7c7e1845..4d36799c 100644 --- a/xml_converter/src/rapid_helpers.hpp +++ b/xml_converter/src/rapid_helpers.hpp @@ -4,7 +4,6 @@ #include "rapidxml-1.13/rapidxml.hpp" -std::string find_attribute_value(rapidxml::xml_node<>* node, std::string attribute_name); rapidxml::xml_attribute<>* find_attribute(rapidxml::xml_node<>* node, std::string attribute_name); std::string get_attribute_name(rapidxml::xml_attribute<>* attribute); From 994d6d94c917c031085fc83c0490b2cd7c08c63c Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Sun, 21 Jan 2024 18:33:45 -0600 Subject: [PATCH 04/18] linter checks --- .../generators/cpp_templates/class_template.cpp | 10 ++++------ xml_converter/src/category_gen.cpp | 2 -- xml_converter/src/icon_gen.cpp | 4 ---- xml_converter/src/rapid_helpers.cpp | 1 - xml_converter/src/trail_gen.cpp | 4 ---- 5 files changed, 4 insertions(+), 17 deletions(-) diff --git a/xml_converter/generators/cpp_templates/class_template.cpp b/xml_converter/generators/cpp_templates/class_template.cpp index a9451c85..c9311c0f 100644 --- a/xml_converter/generators/cpp_templates/class_template.cpp +++ b/xml_converter/generators/cpp_templates/class_template.cpp @@ -17,7 +17,7 @@ using namespace std; string {{cpp_class}}::classname() { return "{{xml_class_name}}"; } -{% if cpp_class == "Category": %} +{% if cpp_class == "Category" %} void {{cpp_class}}::init_from_xml(rapidxml::xml_node<>* node, vector* errors, XMLReaderState* state) { for (rapidxml::xml_attribute<>* attribute = node->first_attribute(); attribute; attribute = attribute->next_attribute()) { bool is_icon_value = this->default_icon.init_xml_attribute(attribute, errors, state); @@ -69,7 +69,7 @@ vector {{cpp_class}}::as_xml(XMLWriterState* state) const { } {% endif %} {% endfor %} - {% if cpp_class == "Category": %} + {% if cpp_class == "Category" %} xml_node_contents.push_back(">\n"); for (const auto& [key, val] : this->children) { @@ -121,7 +121,6 @@ void {{cpp_class}}::parse_protobuf(waypoint::{{cpp_class}} proto_{{cpp_class_hea {% endfor %} } - //////////////////////////////////////////////////////////////////////////////// // apply_underlay // @@ -137,8 +136,8 @@ void {{cpp_class}}::apply_underlay(const {{cpp_class}}& underlay) { } {% endif %} {% endfor %} + {% if cpp_class == "Category" %} - {% if cpp_class == "Category": %} this->default_icon.apply_underlay(underlay.default_icon); this->default_trail.apply_underlay(underlay.default_trail); {% endif %} @@ -159,10 +158,9 @@ void {{cpp_class}}::apply_overlay(const {{cpp_class}}& overlay) { } {% endif %} {% endfor %} + {% if cpp_class == "Category" %} - {% if cpp_class == "Category": %} this->default_icon.apply_overlay(overlay.default_icon); this->default_trail.apply_overlay(overlay.default_trail); {% endif %} } - diff --git a/xml_converter/src/category_gen.cpp b/xml_converter/src/category_gen.cpp index c7b3f2ae..39495ffc 100644 --- a/xml_converter/src/category_gen.cpp +++ b/xml_converter/src/category_gen.cpp @@ -133,7 +133,6 @@ void Category::parse_protobuf(waypoint::Category proto_category, ProtoReaderStat } } - //////////////////////////////////////////////////////////////////////////////// // apply_underlay // @@ -197,4 +196,3 @@ void Category::apply_overlay(const Category& overlay) { this->default_icon.apply_overlay(overlay.default_icon); this->default_trail.apply_overlay(overlay.default_trail); } - diff --git a/xml_converter/src/icon_gen.cpp b/xml_converter/src/icon_gen.cpp index 23ddcb20..b8e40350 100644 --- a/xml_converter/src/icon_gen.cpp +++ b/xml_converter/src/icon_gen.cpp @@ -743,7 +743,6 @@ void Icon::parse_protobuf(waypoint::Icon proto_icon, ProtoReaderState* state) { } } - //////////////////////////////////////////////////////////////////////////////// // apply_underlay // @@ -939,7 +938,6 @@ void Icon::apply_underlay(const Icon& underlay) { this->trigger_range = underlay.trigger_range; this->trigger_range_is_set = true; } - } //////////////////////////////////////////////////////////////////////////////// @@ -1137,6 +1135,4 @@ void Icon::apply_overlay(const Icon& overlay) { this->trigger_range = overlay.trigger_range; this->trigger_range_is_set = true; } - } - diff --git a/xml_converter/src/rapid_helpers.cpp b/xml_converter/src/rapid_helpers.cpp index c109ba8d..63e98426 100644 --- a/xml_converter/src/rapid_helpers.cpp +++ b/xml_converter/src/rapid_helpers.cpp @@ -9,7 +9,6 @@ using namespace std; - rapidxml::xml_attribute<>* find_attribute(rapidxml::xml_node<>* node, string attribute_name) { return node->first_attribute(attribute_name.data(), attribute_name.size(), false); } diff --git a/xml_converter/src/trail_gen.cpp b/xml_converter/src/trail_gen.cpp index 8ef6401d..becc14ae 100644 --- a/xml_converter/src/trail_gen.cpp +++ b/xml_converter/src/trail_gen.cpp @@ -441,7 +441,6 @@ void Trail::parse_protobuf(waypoint::Trail proto_trail, ProtoReaderState* state) } } - //////////////////////////////////////////////////////////////////////////////// // apply_underlay // @@ -557,7 +556,6 @@ void Trail::apply_underlay(const Trail& underlay) { this->trail_scale = underlay.trail_scale; this->trail_scale_is_set = true; } - } //////////////////////////////////////////////////////////////////////////////// @@ -675,6 +673,4 @@ void Trail::apply_overlay(const Trail& overlay) { this->trail_scale = overlay.trail_scale; this->trail_scale_is_set = true; } - } - From fe1bf76be98ef904d63b83a471f3b9eb565318fe Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Sun, 21 Jan 2024 22:11:18 -0600 Subject: [PATCH 05/18] adding helper functions to generate simple hashed values --- xml_converter/src/hash_helpers.cpp | 83 +++++++++++ xml_converter/src/hash_helpers.hpp | 29 ++++ xml_converter/tests/test_hash_helpers.cpp | 170 ++++++++++++++++++++++ 3 files changed, 282 insertions(+) create mode 100644 xml_converter/src/hash_helpers.cpp create mode 100644 xml_converter/src/hash_helpers.hpp create mode 100644 xml_converter/tests/test_hash_helpers.cpp diff --git a/xml_converter/src/hash_helpers.cpp b/xml_converter/src/hash_helpers.cpp new file mode 100644 index 00000000..1c7ad3b9 --- /dev/null +++ b/xml_converter/src/hash_helpers.cpp @@ -0,0 +1,83 @@ +// Hashing +#include "hash_helpers.hpp" + +const char* hex_chars = "0123456789abcdef"; + +Hash64::Hash64() { + this->hash = 0b0000010010000001001101100111001011100111010110000100001101011110; +} + +Hash64::Hash64(uint64_t init) { + this->hash = init; +} + +void Hash64::update(const unsigned char* str, size_t length) { + for (size_t i = 0; i < length; i++) { + hash = ((hash << 5) + hash) + str[i]; /* hash * 33 + c */ + } +} + +void Hash64::update(const std::string& str) { + this->update((unsigned char*)str.c_str(), str.length()); +} + +std::string Hash64::hex() const { + std::string hex_string(16, '0'); + + uint64_t number = this->hash; + + for (int i = 15; i >= 0; --i) { + hex_string[i] = hex_chars[number & 0xF]; + number >>= 4; + } + + return hex_string; +} + +Hash128::Hash128() { + this->lower = 0b0000010010000001001101100111001011100111010110000100001101011110; + this->upper = 0b0101011000001100111101000001001100111111010110011101101111100100; +} +Hash128::Hash128(uint64_t upper, uint64_t lower) { + this->upper = upper; + this->lower = lower; +} + +void Hash128::update(const unsigned char* str, size_t length) { + for (size_t i = 0; i < length; i++) { + upper = ((upper << 5) + upper) + ((lower >> 59) & 0x1F); + uint64_t original_lower = lower; + lower = lower << 5; + + uint64_t multiplication_overflow = (lower > UINT64_MAX - original_lower) ? 1 : 0; + lower += original_lower; + + uint64_t addition_overflow = (lower > UINT64_MAX - str[i]) ? 1 : 0; + + lower += str[i]; + upper += multiplication_overflow + addition_overflow; + } +} + +void Hash128::update(const std::string& str) { + this->update((unsigned char*)str.c_str(), str.length()); +} + +std::string Hash128::hex() const { + std::string hex_string(32, '0'); + + uint64_t number = this->lower; + + for (int i = 15; i >= 0; --i) { + hex_string[i + 16] = hex_chars[number & 0xF]; + number >>= 4; + } + + number = this->upper; + for (int i = 15; i >= 0; --i) { + hex_string[i] = hex_chars[number & 0xF]; + number >>= 4; + } + + return hex_string; +} diff --git a/xml_converter/src/hash_helpers.hpp b/xml_converter/src/hash_helpers.hpp new file mode 100644 index 00000000..6ce2c40c --- /dev/null +++ b/xml_converter/src/hash_helpers.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include + +class Hash64 { + private: + uint64_t hash; + + public: + Hash64(); + explicit Hash64(uint64_t init); + void update(const unsigned char* str, size_t length); + void update(const std::string& str); + std::string hex() const; +}; + +class Hash128 { + private: + uint64_t upper; + uint64_t lower; + + public: + Hash128(); + Hash128(uint64_t upper, uint64_t lower); + void update(const unsigned char* str, size_t length); + void update(const std::string& str); + std::string hex() const; + std::string base64() const; +}; diff --git a/xml_converter/tests/test_hash_helpers.cpp b/xml_converter/tests/test_hash_helpers.cpp new file mode 100644 index 00000000..16667c76 --- /dev/null +++ b/xml_converter/tests/test_hash_helpers.cpp @@ -0,0 +1,170 @@ +#include "../src/hash_helpers.hpp" +#include + +class Hash128Test : public ::testing::Test {}; + +//////////////////////////////////////////////////////////////////////////////// +// These test cases were computed in python using the code. Python was chosen +// because it is able to handle large integers natively. +// +// ```python +// start = 0 +// for i in range(26): +// start = start*33 + 97 +// print('TEST_HASH128_PROPAGATE("' + '{:032x}'.format(start) + '", ' + str(i+1) + ")") +// ``` +//////////////////////////////////////////////////////////////////////////////// +#define TEST_HASH128_PROPAGATE(EXPECTED_HASH, SIZE) \ + TEST_F(Hash128Test, Propagate##SIZE##Bytes) { \ + Hash128 hash(0,0); \ + hash.update(std::string(SIZE, 'a')); \ + EXPECT_EQ(hash.hex(), EXPECTED_HASH); \ + } +TEST_HASH128_PROPAGATE("00000000000000000000000000000000", 0) +TEST_HASH128_PROPAGATE("00000000000000000000000000000061", 1) +TEST_HASH128_PROPAGATE("00000000000000000000000000000ce2", 2) +TEST_HASH128_PROPAGATE("0000000000000000000000000001a983", 3) +TEST_HASH128_PROPAGATE("0000000000000000000000000036da44", 4) +TEST_HASH128_PROPAGATE("00000000000000000000000007122325", 5) +TEST_HASH128_PROPAGATE("000000000000000000000000e9568826", 6) +TEST_HASH128_PROPAGATE("00000000000000000000001e14278d47", 7) +TEST_HASH128_PROPAGATE("0000000000000000000003e099193688", 8) +TEST_HASH128_PROPAGATE("000000000000000000007ff3bc4007e9", 9) +TEST_HASH128_PROPAGATE("000000000000000000107e6b4441056a", 10) +TEST_HASH128_PROPAGATE("000000000000000002204bd3cc61b30b", 11) +TEST_HASH128_PROPAGATE("00000000000000004629c64d589814cc", 12) +// First test over a signle uint64 +TEST_HASH128_PROPAGATE("00000000000000090b628ff86b9aaead", 13) +TEST_HASH128_PROPAGATE("000000000000012a77b48f05def084ae", 14) +TEST_HASH128_PROPAGATE("00000000000026796e466fc1bd011acf", 15) +TEST_HASH128_PROPAGATE("000000000004f5a7371467f95d247510", 16) +TEST_HASH128_PROPAGATE("0000000000a3aa8e19a1672501b31771", 17) +TEST_HASH128_PROPAGATE("000000001518fc514dce4bc5381605f2", 18) +TEST_HASH128_PROPAGATE("00000002b838867b0797c46c3ad6c493", 19) +TEST_HASH128_PROPAGATE("00000059bf4955dbfa9051f395af5754", 20) +TEST_HASH128_PROPAGATE("00000b91a874115b4c9a90664b9a4235", 21) +TEST_HASH128_PROPAGATE("00017dc6b6f63cc4dfec9d2fbee28936", 22) +TEST_HASH128_PROPAGATE("0031369d95bdd560dd8043279b33b057", 23) +TEST_HASH128_PROPAGATE("06580a504d78817c8d88a81b01a9bb98", 24) +TEST_HASH128_PROPAGATE("d1595459fc88b10e3e9dab7b36e12ef9", 25) +// First overflow of 128bit +TEST_HASH128_PROPAGATE("fc83df998d9ed2d612531ae213070e7a", 26) + + +//////////////////////////////////////////////////////////////////////////////// +// These test cases were computed in python using the code. Python was chosen +// because it is able to handle large integers natively. +// +// ```python +// start = 0b01010110000011001111010000010011001111110101100111011011111001000000010010000001001101100111001011100111010110000100001101011110 +// for i in range(26): +// start = start*33 + 97 +// print('TEST_HASH128_PROPAGATE("' + '{:032x}'.format(start) + '", ' + str(i+1) + ")") +// ``` +//////////////////////////////////////////////////////////////////////////////// +#define TEST_HASH128_DEFAULT(EXPECTED_HASH, SIZE) \ + TEST_F(Hash128Test, Default##SIZE##Bytes) { \ + Hash128 hash; \ + hash.update(std::string(SIZE, 'a')); \ + EXPECT_EQ(hash.hex(), EXPECTED_HASH); \ + } +TEST_HASH128_DEFAULT("560cf4133f59dbe404813672e758435e", 0) +TEST_HASH128_DEFAULT("17ab767b2a95586494a804cfd260af7f", 1) +TEST_HASH128_DEFAULT("0d1a45e07d4064f729a89eca1e769fc0", 2) +TEST_HASH128_DEFAULT("b06301f0254d03dc5ebc780ded4a9821", 3) +TEST_HASH128_DEFAULT("bcc33ff4ceed7f68364b79cb969d9ca2", 4) +TEST_HASH128_DEFAULT("552b3e8eac9d6c6effbab33e6a513143", 5) +TEST_HASH128_DEFAULT("fa931064404afa4ef7111b0bb4775a04", 6) +TEST_HASH128_DEFAULT("4cf51cec49aa442dd9347c8243629ae5", 7) +TEST_HASH128_DEFAULT("eb98ba757ef2c9e8ffc40ccaafb5f7e6", 8) +TEST_HASH128_DEFAULT("5eb009255d4c0708f845a620a674f507", 9) +TEST_HASH128_DEFAULT("34b12dd106cce82800fa6a3575139648", 10) +TEST_HASH128_DEFAULT("cad6e7f1e069ed282047b0e417865fa9", 11) +TEST_HASH128_DEFAULT("25b3e62deda7922c293dcd670852552a", 12) +TEST_HASH128_DEFAULT("dc30abeba299d7b150f77a48129cfacb", 13) +TEST_HASH128_DEFAULT("6246295ff5d4cddb6fe6c34a663c548c", 14) +TEST_HASH128_DEFAULT("ab0b555eb06e89496cbf2c972dc6e66d", 15) +TEST_HASH128_DEFAULT("0c760134be3fb27704a4bf7ce6a3b46e", 16) +TEST_HASH128_DEFAULT("9b3627cc86360157993caf19bb1a428f", 17) +TEST_HASH128_DEFAULT("01fb215d4cf62c4ac0d292511e6294d0", 18) +TEST_HASH128_DEFAULT("415f4d06ebbbb5a2db24dc74eab52f31", 19) +TEST_HASH128_DEFAULT("6d48ede4633269fe3fc06b12415b15b2", 20) +TEST_HASH128_DEFAULT("1666aa70c97fa9c637cdcd5a6cbdcc53", 21) +TEST_HASH128_DEFAULT("e33bf889f974e28d318778a804775714", 22) +TEST_HASH128_DEFAULT("4abb09c92811343362768da8936239f5", 23) +TEST_HASH128_DEFAULT("a21c42ee2a37ba9fb14842baffa978f6", 24) +TEST_HASH128_DEFAULT("e5a4a0b3712f0e95da509a1af4d89817", 25) +TEST_HASH128_DEFAULT("9a38b7219710e1512463dd798feb9b58", 26) + + +class Hash64Test : public ::testing::Test {}; + +// These are copies of the 128 bit hash tests above trunkated to 64 bits +#define TEST_HASH64_PROPAGATE(EXPECTED_HASH, SIZE) \ + TEST_F(Hash64Test, Propagate##SIZE##Bytes) { \ + Hash64 hash(0); \ + hash.update(std::string(SIZE, 'a')); \ + EXPECT_EQ(hash.hex(), EXPECTED_HASH); \ + } +TEST_HASH64_PROPAGATE("0000000000000000", 0) +TEST_HASH64_PROPAGATE("0000000000000061", 1) +TEST_HASH64_PROPAGATE("0000000000000ce2", 2) +TEST_HASH64_PROPAGATE("000000000001a983", 3) +TEST_HASH64_PROPAGATE("000000000036da44", 4) +TEST_HASH64_PROPAGATE("0000000007122325", 5) +TEST_HASH64_PROPAGATE("00000000e9568826", 6) +TEST_HASH64_PROPAGATE("0000001e14278d47", 7) +TEST_HASH64_PROPAGATE("000003e099193688", 8) +TEST_HASH64_PROPAGATE("00007ff3bc4007e9", 9) +TEST_HASH64_PROPAGATE("00107e6b4441056a", 10) +TEST_HASH64_PROPAGATE("02204bd3cc61b30b", 11) +TEST_HASH64_PROPAGATE("4629c64d589814cc", 12) +TEST_HASH64_PROPAGATE("0b628ff86b9aaead", 13) +TEST_HASH64_PROPAGATE("77b48f05def084ae", 14) +TEST_HASH64_PROPAGATE("6e466fc1bd011acf", 15) +TEST_HASH64_PROPAGATE("371467f95d247510", 16) +TEST_HASH64_PROPAGATE("19a1672501b31771", 17) +TEST_HASH64_PROPAGATE("4dce4bc5381605f2", 18) +TEST_HASH64_PROPAGATE("0797c46c3ad6c493", 19) +TEST_HASH64_PROPAGATE("fa9051f395af5754", 20) +TEST_HASH64_PROPAGATE("4c9a90664b9a4235", 21) +TEST_HASH64_PROPAGATE("dfec9d2fbee28936", 22) +TEST_HASH64_PROPAGATE("dd8043279b33b057", 23) +TEST_HASH64_PROPAGATE("8d88a81b01a9bb98", 24) +TEST_HASH64_PROPAGATE("3e9dab7b36e12ef9", 25) +TEST_HASH64_PROPAGATE("12531ae213070e7a", 26) + + +#define TEST_HASH64_DEFAULT(EXPECTED_HASH, SIZE) \ + TEST_F(Hash64Test, Default##SIZE##Bytes) { \ + Hash64 hash; \ + hash.update(std::string(SIZE, 'a')); \ + EXPECT_EQ(hash.hex(), EXPECTED_HASH); \ + } +TEST_HASH64_DEFAULT("04813672e758435e", 0) +TEST_HASH64_DEFAULT("94a804cfd260af7f", 1) +TEST_HASH64_DEFAULT("29a89eca1e769fc0", 2) +TEST_HASH64_DEFAULT("5ebc780ded4a9821", 3) +TEST_HASH64_DEFAULT("364b79cb969d9ca2", 4) +TEST_HASH64_DEFAULT("ffbab33e6a513143", 5) +TEST_HASH64_DEFAULT("f7111b0bb4775a04", 6) +TEST_HASH64_DEFAULT("d9347c8243629ae5", 7) +TEST_HASH64_DEFAULT("ffc40ccaafb5f7e6", 8) +TEST_HASH64_DEFAULT("f845a620a674f507", 9) +TEST_HASH64_DEFAULT("00fa6a3575139648", 10) +TEST_HASH64_DEFAULT("2047b0e417865fa9", 11) +TEST_HASH64_DEFAULT("293dcd670852552a", 12) +TEST_HASH64_DEFAULT("50f77a48129cfacb", 13) +TEST_HASH64_DEFAULT("6fe6c34a663c548c", 14) +TEST_HASH64_DEFAULT("6cbf2c972dc6e66d", 15) +TEST_HASH64_DEFAULT("04a4bf7ce6a3b46e", 16) +TEST_HASH64_DEFAULT("993caf19bb1a428f", 17) +TEST_HASH64_DEFAULT("c0d292511e6294d0", 18) +TEST_HASH64_DEFAULT("db24dc74eab52f31", 19) +TEST_HASH64_DEFAULT("3fc06b12415b15b2", 20) +TEST_HASH64_DEFAULT("37cdcd5a6cbdcc53", 21) +TEST_HASH64_DEFAULT("318778a804775714", 22) +TEST_HASH64_DEFAULT("62768da8936239f5", 23) +TEST_HASH64_DEFAULT("b14842baffa978f6", 24) +TEST_HASH64_DEFAULT("da509a1af4d89817", 25) +TEST_HASH64_DEFAULT("2463dd798feb9b58", 26) \ No newline at end of file From 26907d1f17cf1e489f255ec275207afc9ccded37 Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Mon, 22 Jan 2024 01:14:41 -0600 Subject: [PATCH 06/18] Adding category id and auto-populating it if it is missing --- .../cpp_templates/class_template.hpp | 1 + .../output_proto/markers.bin | Bin 153 -> 163 bytes .../output_xml/xml_file.xml | 2 +- .../achievement_id/output_proto/markers.bin | 4 +- .../achievement_id/output_xml/xml_file.xml | 2 +- .../animation_speed/output_proto/markers.bin | Bin 642 -> 652 bytes .../animation_speed/output_xml/xml_file.xml | 2 +- .../canfade_invalid/output_proto/markers.bin | 4 +- .../canfade_invalid/output_xml/xml_file.xml | 2 +- .../canfade_valid/output_proto/markers.bin | 4 +- .../canfade_valid/output_xml/xml_file.xml | 2 +- .../category_name/output_proto/markers.bin | 4 +- .../category_name/output_xml/xml_file.xml | 2 +- .../output_xml/xml_file.xml | 4 +- .../cull_chirality/output_proto/markers.bin | 4 +- .../cull_chirality/output_xml/xml_file.xml | 2 +- .../fade_distance/output_proto/markers.bin | Bin 255 -> 265 bytes .../fade_distance/output_xml/xml_file.xml | 2 +- .../festival_filter/output_proto/markers.bin | 4 +- .../festival_filter/output_xml/xml_file.xml | 2 +- .../is_wall/output_proto/markers.bin | 4 +- .../is_wall/output_xml/xml_file.xml | 2 +- .../map_id/output_proto/markers.bin | 4 +- .../test_cases/map_id/output_xml/xml_file.xml | 2 +- .../map_type_filter/output_proto/markers.bin | 4 +- .../map_type_filter/output_xml/xml_file.xml | 2 +- .../output_proto/markers.bin | 4 +- .../output_xml/xml_file.xml | 2 +- .../output_proto/markers.bin | 4 +- .../mountfilter_valid/output_xml/xml_file.xml | 2 +- .../output_proto/markers.bin | 4 +- .../profession_filter/output_xml/xml_file.xml | 2 +- .../output_proto/markers.bin | 4 +- .../output_xml/xml_file.xml | 2 +- .../species_filter/output_proto/markers.bin | 4 +- .../species_filter/output_xml/xml_file.xml | 2 +- .../texture/output_proto/markers.bin | Bin 105 -> 115 bytes .../texture/output_xml/xml_file.xml | 2 +- xml_converter/proto/waypoint.proto | 1 + xml_converter/src/category_gen.cpp | 24 ++++++++++ xml_converter/src/category_gen.hpp | 4 ++ xml_converter/src/hash_helpers.cpp | 17 ++++++- xml_converter/src/hash_helpers.hpp | 3 +- xml_converter/src/packaging_xml.cpp | 43 ++++++++++++++++-- xml_converter/src/string_helper.cpp | 2 +- 45 files changed, 136 insertions(+), 55 deletions(-) diff --git a/xml_converter/generators/cpp_templates/class_template.hpp b/xml_converter/generators/cpp_templates/class_template.hpp index d509d9d7..f5294cc1 100644 --- a/xml_converter/generators/cpp_templates/class_template.hpp +++ b/xml_converter/generators/cpp_templates/class_template.hpp @@ -28,6 +28,7 @@ class {{cpp_class}} : public Parseable { std::map children; Icon default_icon; Trail default_trail; + Category* parent; void init_from_xml(rapidxml::xml_node<>* node, std::vector* errors, XMLReaderState* state); {% endif %} diff --git a/xml_converter/integration_tests/test_cases/achievement_bitmask_valid/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/achievement_bitmask_valid/output_proto/markers.bin index 6145a43afd1d9d981f575b7f3af3c14346c58450..a78bad0809d339dc9aa675ae823c39978ece2fd4 100644 GIT binary patch delta 21 dcmbQqxR{ZNYr#aO>0C}68ZXYU9hw|B4FE^_2b2H+ delta 10 RcmZ3?IFpfyYuZGn=>QNU0}B8E diff --git a/xml_converter/integration_tests/test_cases/achievement_bitmask_valid/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/achievement_bitmask_valid/output_xml/xml_file.xml index 7535e6e6..b07e3ef9 100644 --- a/xml_converter/integration_tests/test_cases/achievement_bitmask_valid/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/achievement_bitmask_valid/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/achievement_id/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/achievement_id/output_proto/markers.bin index a5b458eb..df6a9bb5 100644 --- a/xml_converter/integration_tests/test_cases/achievement_id/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/achievement_id/output_proto/markers.bin @@ -1,3 +1,3 @@ -µ - My Category 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWCˆ 2B \Ï)Cf¦RC{ÔWCˆ 2B \Ï)Cf¦RC{ÔWCˆÿÿÿÿ 2B \Ï)Cf¦RC{ÔWCˆ€€€€øÿÿÿÿ 2B \Ï)Cf¦RC{ÔWCˆûÿÿÿÿÿÿÿÿ"ˆ \ No newline at end of file +¿ + My Category 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWCˆ 2B \Ï)Cf¦RC{ÔWCˆ 2B \Ï)Cf¦RC{ÔWCˆÿÿÿÿ 2B \Ï)Cf¦RC{ÔWCˆ€€€€øÿÿÿÿ 2B \Ï)Cf¦RC{ÔWCˆûÿÿÿÿÿÿÿÿ"ˆB(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/achievement_id/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/achievement_id/output_xml/xml_file.xml index 00cfc8cc..7da09fb4 100644 --- a/xml_converter/integration_tests/test_cases/achievement_id/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/achievement_id/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/animation_speed/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/animation_speed/output_proto/markers.bin index 269c512cc66e9454650f74aeff886b3e17a900fa..6306612065dc28e9cf1ad665e9b4de791ebe57d3 100644 GIT binary patch delta 23 ecmZo-?O|o+>SW!>T+hVi#G&!x4BMf}ank@vSO;hT delta 12 TcmeBSZDM8S`p>eFxt<9C7EJ?Q diff --git a/xml_converter/integration_tests/test_cases/animation_speed/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/animation_speed/output_xml/xml_file.xml index d3c71cf6..ff5aa933 100644 --- a/xml_converter/integration_tests/test_cases/animation_speed/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/animation_speed/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/canfade_invalid/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/canfade_invalid/output_proto/markers.bin index c32cb0ef..9adc8734 100644 --- a/xml_converter/integration_tests/test_cases/canfade_invalid/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/canfade_invalid/output_proto/markers.bin @@ -1,3 +1,3 @@ -7 - My Category 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWC \ No newline at end of file +A + My Category 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWCB(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/canfade_invalid/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/canfade_invalid/output_xml/xml_file.xml index 56b79ea1..b164fa46 100644 --- a/xml_converter/integration_tests/test_cases/canfade_invalid/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/canfade_invalid/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/canfade_valid/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/canfade_valid/output_proto/markers.bin index a1e1c437..a900d117 100644 --- a/xml_converter/integration_tests/test_cases/canfade_valid/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/canfade_valid/output_proto/markers.bin @@ -1,3 +1,3 @@ -g - My Category 2B \Ï)Cf¦RC{ÔWC˜ 2B \Ï)Cf¦RC{ÔWC˜ 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWC \ No newline at end of file +q + My Category 2B \Ï)Cf¦RC{ÔWC˜ 2B \Ï)Cf¦RC{ÔWC˜ 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWCB(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/canfade_valid/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/canfade_valid/output_xml/xml_file.xml index 2850f7f7..6e16afe3 100644 --- a/xml_converter/integration_tests/test_cases/canfade_valid/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/canfade_valid/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/category_name/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/category_name/output_proto/markers.bin index a89a9d4a..27e2fe03 100644 --- a/xml_converter/integration_tests/test_cases/category_name/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/category_name/output_proto/markers.bin @@ -1,3 +1,3 @@ -L - My Category 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWC \ No newline at end of file +V + My Category 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWCB(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/category_name/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/category_name/output_xml/xml_file.xml index 0a23d2a0..daab7542 100644 --- a/xml_converter/integration_tests/test_cases/category_name/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/category_name/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/category_name_invalid/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/category_name_invalid/output_xml/xml_file.xml index d6de0503..e9f72087 100644 --- a/xml_converter/integration_tests/test_cases/category_name_invalid/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/category_name_invalid/output_xml/xml_file.xml @@ -1,8 +1,8 @@ - + - + diff --git a/xml_converter/integration_tests/test_cases/cull_chirality/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/cull_chirality/output_proto/markers.bin index 0c984e70..480cc9ab 100644 --- a/xml_converter/integration_tests/test_cases/cull_chirality/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/cull_chirality/output_proto/markers.bin @@ -1,3 +1,3 @@ -R - My Category 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWCˆ 2B \Ï)Cf¦RC{ÔWCˆ \ No newline at end of file +\ + My Category 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWCˆ 2B \Ï)Cf¦RC{ÔWCˆB(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/cull_chirality/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/cull_chirality/output_xml/xml_file.xml index d9a87c98..f9793d06 100644 --- a/xml_converter/integration_tests/test_cases/cull_chirality/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/cull_chirality/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/fade_distance/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/fade_distance/output_proto/markers.bin index 68ae59c38b05ed84d8f3f6628ed87c2e1c12a750..d69ff8710e4d62cd89e64b067e49d9225901ef70 100644 GIT binary patch delta 22 ecmey**vZ7q)y6cD`45*9hsKLDY= - + diff --git a/xml_converter/integration_tests/test_cases/festival_filter/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/festival_filter/output_proto/markers.bin index 57f60e15..ca65d1f0 100644 --- a/xml_converter/integration_tests/test_cases/festival_filter/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/festival_filter/output_proto/markers.bin @@ -1,3 +1,3 @@ -y - My Category 2B \Ï)Cf¦RC{ÔWCÚ 2B \Ï)Cf¦RC{ÔWCÚ( 2B \Ï)Cf¦RC{ÔWCÚ( 2B \Ï)Cf¦RC{ÔWCÚ  \ No newline at end of file +ƒ + My Category 2B \Ï)Cf¦RC{ÔWCÚ 2B \Ï)Cf¦RC{ÔWCÚ( 2B \Ï)Cf¦RC{ÔWCÚ( 2B \Ï)Cf¦RC{ÔWCÚ B(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/festival_filter/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/festival_filter/output_xml/xml_file.xml index 23d92fd3..70310c54 100644 --- a/xml_converter/integration_tests/test_cases/festival_filter/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/festival_filter/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/is_wall/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/is_wall/output_proto/markers.bin index 8984f382..da32a101 100644 --- a/xml_converter/integration_tests/test_cases/is_wall/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/is_wall/output_proto/markers.bin @@ -1,3 +1,3 @@ -# - My Category" 2 " 2 " 2" 2 \ No newline at end of file +- + My Category" 2 " 2 " 2" 2B(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/is_wall/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/is_wall/output_xml/xml_file.xml index caabb11a..5cbc4149 100644 --- a/xml_converter/integration_tests/test_cases/is_wall/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/is_wall/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/map_id/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/map_id/output_proto/markers.bin index cdc94a2a..24fdb7f4 100644 --- a/xml_converter/integration_tests/test_cases/map_id/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/map_id/output_proto/markers.bin @@ -1,3 +1,3 @@ -x - My CategoryB \Ï)Cf¦RC{ÔWC B \Ï)Cf¦RC{ÔWC B \Ï)Cf¦RC{ÔWC ÿÿÿÿB \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWC \ No newline at end of file +‚ + My CategoryB \Ï)Cf¦RC{ÔWC B \Ï)Cf¦RC{ÔWC B \Ï)Cf¦RC{ÔWC ÿÿÿÿB \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWCB(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/map_id/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/map_id/output_xml/xml_file.xml index 7cd7d10b..40133f47 100644 --- a/xml_converter/integration_tests/test_cases/map_id/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/map_id/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/map_type_filter/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/map_type_filter/output_proto/markers.bin index 416391e4..9cdd92bd 100644 --- a/xml_converter/integration_tests/test_cases/map_type_filter/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/map_type_filter/output_proto/markers.bin @@ -1,3 +1,3 @@ -Ì - My Category 2B \Ï)Cf¦RC{ÔWCâ 2B \Ï)Cf¦RC{ÔWCâ 2B \Ï)Cf¦RC{ÔWCâ 2B \Ï)Cf¦RC{ÔWCâO 2B \Ï)Cf¦RC{ÔWCâ9 (08@HPX`hpx€ˆ˜ ¨°¸À \ No newline at end of file +Ö + My Category 2B \Ï)Cf¦RC{ÔWCâ 2B \Ï)Cf¦RC{ÔWCâ 2B \Ï)Cf¦RC{ÔWCâ 2B \Ï)Cf¦RC{ÔWCâO 2B \Ï)Cf¦RC{ÔWCâ9 (08@HPX`hpx€ˆ˜ ¨°¸ÀB(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/map_type_filter/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/map_type_filter/output_xml/xml_file.xml index 41115909..71c21475 100644 --- a/xml_converter/integration_tests/test_cases/map_type_filter/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/map_type_filter/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/mount_filter_invalid/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/mount_filter_invalid/output_proto/markers.bin index 3e5a1112..0e68e64b 100644 --- a/xml_converter/integration_tests/test_cases/mount_filter_invalid/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/mount_filter_invalid/output_proto/markers.bin @@ -1,3 +1,3 @@ -o - My Category 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWCê 2B \Ï)Cf¦RC{ÔWCê \ No newline at end of file +y + My Category 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWC 2B \Ï)Cf¦RC{ÔWCê 2B \Ï)Cf¦RC{ÔWCêB(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/mount_filter_invalid/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/mount_filter_invalid/output_xml/xml_file.xml index 53b34efe..14caab92 100644 --- a/xml_converter/integration_tests/test_cases/mount_filter_invalid/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/mount_filter_invalid/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/mountfilter_valid/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/mountfilter_valid/output_proto/markers.bin index 4236a31f..7df59e89 100644 --- a/xml_converter/integration_tests/test_cases/mountfilter_valid/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/mountfilter_valid/output_proto/markers.bin @@ -1,3 +1,3 @@ -‹ - My Category 2B \Ï)Cf¦RC{ÔWCê 2B \Ï)Cf¦RC{ÔWCê 2B \Ï)Cf¦RC{ÔWCê* 2B \Ï)Cf¦RC{ÔWCê (08@HP \ No newline at end of file +• + My Category 2B \Ï)Cf¦RC{ÔWCê 2B \Ï)Cf¦RC{ÔWCê 2B \Ï)Cf¦RC{ÔWCê* 2B \Ï)Cf¦RC{ÔWCê (08@HPB(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/mountfilter_valid/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/mountfilter_valid/output_xml/xml_file.xml index 38abbed2..35527920 100644 --- a/xml_converter/integration_tests/test_cases/mountfilter_valid/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/mountfilter_valid/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/profession_filter/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/profession_filter/output_proto/markers.bin index 0847dc80..46fbad2c 100644 --- a/xml_converter/integration_tests/test_cases/profession_filter/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/profession_filter/output_proto/markers.bin @@ -1,3 +1,3 @@ -¥ - My Category 2B \Ï)Cf¦RC{ÔWCò 2B \Ï)Cf¦RC{ÔWCò 2B \Ï)Cf¦RC{ÔWCò 2B \Ï)Cf¦RC{ÔWCò( 2B \Ï)Cf¦RC{ÔWCò (08@H \ No newline at end of file +¯ + My Category 2B \Ï)Cf¦RC{ÔWCò 2B \Ï)Cf¦RC{ÔWCò 2B \Ï)Cf¦RC{ÔWCò 2B \Ï)Cf¦RC{ÔWCò( 2B \Ï)Cf¦RC{ÔWCò (08@HB(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/profession_filter/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/profession_filter/output_xml/xml_file.xml index ecf54043..a81f4c58 100644 --- a/xml_converter/integration_tests/test_cases/profession_filter/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/profession_filter/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/specialization_filter/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/specialization_filter/output_proto/markers.bin index 8fdc192e..cffd4543 100644 --- a/xml_converter/integration_tests/test_cases/specialization_filter/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/specialization_filter/output_proto/markers.bin @@ -1,3 +1,3 @@ -» - My Category 2B \Ï)Cf¦RC{ÔWCú` 2B \Ï)Cf¦RC{ÔWCúH 2B \Ï)Cf¦RC{ÔWCúX 2B \Ï)Cf¦RC{ÔWCú¨Øà 2B \Ï)Cf¦RC{ÔWCúÉ (08@HPX`hpx€ˆ˜ ¨°¸ÀÈÐØàèðø€ˆ˜ ¨°¸ÀÈÐØàèðø€ˆ˜ ¨°¸ÀÈÐØàèðø€ˆ˜ ¨°¸ÀX 2B \Ï)Cf¦RC{ÔWCúB (08@HPX`hpx€ˆ˜ ¨°¸ÀÈÐØ \ No newline at end of file +Å + My Category 2B \Ï)Cf¦RC{ÔWCú` 2B \Ï)Cf¦RC{ÔWCúH 2B \Ï)Cf¦RC{ÔWCúX 2B \Ï)Cf¦RC{ÔWCú¨Øà 2B \Ï)Cf¦RC{ÔWCúÉ (08@HPX`hpx€ˆ˜ ¨°¸ÀÈÐØàèðø€ˆ˜ ¨°¸ÀÈÐØàèðø€ˆ˜ ¨°¸ÀÈÐØàèðø€ˆ˜ ¨°¸ÀX 2B \Ï)Cf¦RC{ÔWCúB (08@HPX`hpx€ˆ˜ ¨°¸ÀÈÐØB(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/specialization_filter/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/specialization_filter/output_xml/xml_file.xml index 05f8f905..46415be0 100644 --- a/xml_converter/integration_tests/test_cases/specialization_filter/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/specialization_filter/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/species_filter/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/species_filter/output_proto/markers.bin index 15f18c1b..efe60a25 100644 --- a/xml_converter/integration_tests/test_cases/species_filter/output_proto/markers.bin +++ b/xml_converter/integration_tests/test_cases/species_filter/output_proto/markers.bin @@ -1,5 +1,5 @@ -­ +· My Category 2B \Ï)Cf¦RC{ÔWC‚ 2B \Ï)Cf¦RC{ÔWC‚ 2B \Ï)Cf¦RC{ÔWC‚ 2B \Ï)Cf¦RC{ÔWC‚  2B \Ï)Cf¦RC{ÔWC‚  ( 2B \Ï)Cf¦RC{ÔWC‚ 2B \Ï)Cf¦RC{ÔWC‚ 2B \Ï)Cf¦RC{ÔWC‚ 2B \Ï)Cf¦RC{ÔWC‚  2B \Ï)Cf¦RC{ÔWC‚ - ( \ No newline at end of file + (B(èÌ“^– \ No newline at end of file diff --git a/xml_converter/integration_tests/test_cases/species_filter/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/species_filter/output_xml/xml_file.xml index b2719c10..5d6e93c2 100644 --- a/xml_converter/integration_tests/test_cases/species_filter/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/species_filter/output_xml/xml_file.xml @@ -1,5 +1,5 @@ - + diff --git a/xml_converter/integration_tests/test_cases/texture/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/texture/output_proto/markers.bin index ef56f99965e4e270aadd3d20ff1d553c01503e9f..075d211766ee2275192b9b90f632d64e74d7c8e3 100644 GIT binary patch delta 22 ecmc~SX5!MH$fU~U#G&!x4BMf}anmNMI{^SlMh8g% delta 11 ScmXTUWa3ht$fP>a& - + diff --git a/xml_converter/proto/waypoint.proto b/xml_converter/proto/waypoint.proto index 71c50d16..53b50e79 100644 --- a/xml_converter/proto/waypoint.proto +++ b/xml_converter/proto/waypoint.proto @@ -23,6 +23,7 @@ message Category { bool is_separator = 5; bool default_visibility = 6; string tip_description = 7; + bytes id = 8; } message Icon { diff --git a/xml_converter/src/category_gen.cpp b/xml_converter/src/category_gen.cpp index 39495ffc..c2674d65 100644 --- a/xml_converter/src/category_gen.cpp +++ b/xml_converter/src/category_gen.cpp @@ -45,6 +45,12 @@ bool Category::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vectoris_separator), &(this->is_separator_is_set)); } + else if (attributename == "id") { + xml_attribute_to_unique_id(attribute, errors, state, &(this->menu_id), &(this->menu_id_is_set)); + } + else if (attributename == "menuid") { + xml_attribute_to_unique_id(attribute, errors, state, &(this->menu_id), &(this->menu_id_is_set)); + } else if (attributename == "name") { xml_attribute_to_string(attribute, errors, state, &(this->name), &(this->name_is_set)); } @@ -69,6 +75,9 @@ vector Category::as_xml(XMLWriterState* state) const { if (this->is_separator_is_set) { xml_node_contents.push_back(bool_to_xml_attribute("IsSeparator", state, &this->is_separator)); } + if (this->menu_id_is_set) { + xml_node_contents.push_back(unique_id_to_xml_attribute("ID", state, &this->menu_id)); + } if (this->name_is_set) { xml_node_contents.push_back(string_to_xml_attribute("Name", state, &this->name)); } @@ -104,6 +113,10 @@ waypoint::Category Category::as_protobuf(ProtoWriterState* state) const { std::function setter = [&proto_category](bool val) { proto_category.set_is_separator(val); }; bool_to_proto(this->is_separator, state, setter); } + if (this->menu_id_is_set) { + std::function setter = [&proto_category](std::string val) { proto_category.set_id(val); }; + unique_id_to_proto(this->menu_id, state, setter); + } if (this->name_is_set) { std::function setter = [&proto_category](std::string val) { proto_category.set_name(val); }; do_nothing(this->name, state, setter); @@ -125,6 +138,9 @@ void Category::parse_protobuf(waypoint::Category proto_category, ProtoReaderStat if (proto_category.is_separator() != 0) { proto_to_bool(proto_category.is_separator(), state, &(this->is_separator), &(this->is_separator_is_set)); } + if (proto_category.id() != "") { + proto_to_unique_id(proto_category.id(), state, &(this->menu_id), &(this->menu_id_is_set)); + } if (proto_category.name() != "") { do_nothing(proto_category.name(), state, &(this->name), &(this->name_is_set)); } @@ -152,6 +168,10 @@ void Category::apply_underlay(const Category& underlay) { this->is_separator = underlay.is_separator; this->is_separator_is_set = true; } + if (!this->menu_id_is_set && underlay.menu_id_is_set) { + this->menu_id = underlay.menu_id; + this->menu_id_is_set = true; + } if (!this->name_is_set && underlay.name_is_set) { this->name = underlay.name; this->name_is_set = true; @@ -184,6 +204,10 @@ void Category::apply_overlay(const Category& overlay) { this->is_separator = overlay.is_separator; this->is_separator_is_set = true; } + if (overlay.menu_id_is_set) { + this->menu_id = overlay.menu_id; + this->menu_id_is_set = true; + } if (overlay.name_is_set) { this->name = overlay.name; this->name_is_set = true; diff --git a/xml_converter/src/category_gen.hpp b/xml_converter/src/category_gen.hpp index 4a6ecf91..840ee16a 100644 --- a/xml_converter/src/category_gen.hpp +++ b/xml_converter/src/category_gen.hpp @@ -5,6 +5,7 @@ #include #include +#include "attribute/unique_id.hpp" #include "icon_gen.hpp" #include "parseable.hpp" #include "rapidxml-1.13/rapidxml.hpp" @@ -19,16 +20,19 @@ class Category : public Parseable { bool default_visibility; std::string display_name; bool is_separator; + UniqueId menu_id; std::string name; std::string tooltip_description; bool default_visibility_is_set = false; bool display_name_is_set = false; bool is_separator_is_set = false; + bool menu_id_is_set = false; bool name_is_set = false; bool tooltip_description_is_set = false; std::map children; Icon default_icon; Trail default_trail; + Category* parent; void init_from_xml(rapidxml::xml_node<>* node, std::vector* errors, XMLReaderState* state); virtual std::vector as_xml(XMLWriterState* state) const; diff --git a/xml_converter/src/hash_helpers.cpp b/xml_converter/src/hash_helpers.cpp index 1c7ad3b9..7e54317e 100644 --- a/xml_converter/src/hash_helpers.cpp +++ b/xml_converter/src/hash_helpers.cpp @@ -1,7 +1,7 @@ // Hashing #include "hash_helpers.hpp" -const char* hex_chars = "0123456789abcdef"; +static const char* hex_chars = "0123456789abcdef"; Hash64::Hash64() { this->hash = 0b0000010010000001001101100111001011100111010110000100001101011110; @@ -81,3 +81,18 @@ std::string Hash128::hex() const { return hex_string; } + +UniqueId Hash128::unique_id() const { + UniqueId unique_id; + unique_id.guid = { + (unsigned char)((this->upper >> 0) & 0xFF), + (unsigned char)((this->upper >> 8) & 0xFF), + (unsigned char)((this->upper >> 16) & 0xFF), + (unsigned char)((this->upper >> 24) & 0xFF), + (unsigned char)((this->lower >> 0) & 0xFF), + (unsigned char)((this->lower >> 8) & 0xFF), + (unsigned char)((this->lower >> 16) & 0xFF), + (unsigned char)((this->lower >> 24) & 0xFF), + }; + return unique_id; +} \ No newline at end of file diff --git a/xml_converter/src/hash_helpers.hpp b/xml_converter/src/hash_helpers.hpp index 6ce2c40c..82e4af6c 100644 --- a/xml_converter/src/hash_helpers.hpp +++ b/xml_converter/src/hash_helpers.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include "attribute/unique_id.hpp" class Hash64 { private: @@ -25,5 +26,5 @@ class Hash128 { void update(const unsigned char* str, size_t length); void update(const std::string& str); std::string hex() const; - std::string base64() const; + UniqueId unique_id() const; }; diff --git a/xml_converter/src/packaging_xml.cpp b/xml_converter/src/packaging_xml.cpp index b5dddf16..945cbe3d 100644 --- a/xml_converter/src/packaging_xml.cpp +++ b/xml_converter/src/packaging_xml.cpp @@ -6,6 +6,7 @@ #include "rapidxml-1.13/rapidxml.hpp" #include "rapidxml-1.13/rapidxml_utils.hpp" #include "string_helper.hpp" +#include "hash_helpers.hpp" using namespace std; @@ -14,7 +15,13 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// unsigned int UNKNOWN_CATEGORY_COUNTER = 0; -void parse_marker_categories(rapidxml::xml_node<>* node, map* marker_categories, vector* errors, string base_dir, int depth = 0) { +void parse_marker_categories( + rapidxml::xml_node<>* node, + map* marker_categories, + Category* parent, + vector* errors, + string base_dir, + int depth = 0) { if (get_node_name(node) == "MarkerCategory") { XMLReaderState state = { base_dir, @@ -41,11 +48,39 @@ void parse_marker_categories(rapidxml::xml_node<>* node, map* name = lowercase(new_category.name); } - Category* existing_category = &(*marker_categories)[name]; + // If this category itself, without any cascading values, does not have + // an id then create a new one for it based on the hashes of its name + // and its parents names. + if (!new_category.menu_id_is_set) { + Hash128 new_id; + new_id.update(name); + + Category* next_node = parent; + while (next_node != nullptr) { + new_id.update(next_node->name); + next_node = next_node->parent; + } + new_category.menu_id = new_id.unique_id(); + new_category.menu_id_is_set = true; + } + + // Create and initialize a new category if this one does not exist + Category* existing_category; + auto existing_category_search = marker_categories->find(name); + if (existing_category_search == marker_categories->end()) { + existing_category = &(*marker_categories)[name]; + existing_category->parent = parent; + } + else { + existing_category = &existing_category_search->second; + if (existing_category->parent != parent) { + errors->push_back(new XMLNodeNameError("Category somehow has a different parent then it used to. This might be a bug in xml_converter", node)); + } + } existing_category->apply_overlay(new_category); for (rapidxml::xml_node<>* child_node = node->first_node(); child_node; child_node = child_node->next_sibling()) { - parse_marker_categories(child_node, &(existing_category->children), errors, base_dir, depth + 1); + parse_marker_categories(child_node, &(existing_category->children), existing_category, errors, base_dir, depth + 1); } } else { @@ -161,7 +196,7 @@ void parse_xml_file(string xml_filepath, map* marker_categorie for (rapidxml::xml_node<>* node = root_node->first_node(); node; node = node->next_sibling()) { if (get_node_name(node) == "MarkerCategory") { - parse_marker_categories(node, marker_categories, &errors, base_dir); + parse_marker_categories(node, marker_categories, nullptr, &errors, base_dir); } else if (get_node_name(node) == "POIs") { vector temp_vector = parse_pois(node, marker_categories, &errors, base_dir); diff --git a/xml_converter/src/string_helper.cpp b/xml_converter/src/string_helper.cpp index e6b082e5..a8c7ca32 100644 --- a/xml_converter/src/string_helper.cpp +++ b/xml_converter/src/string_helper.cpp @@ -301,7 +301,7 @@ string join_file_paths(const string& path_a, const string& path_b) { // // A helper function that converts an 8 byte long into a 16 byte hex string. //////////////////////////////////////////////////////////////////////////////// -const char* hex_chars = "0123456789abcdef"; +static const char* hex_chars = "0123456789abcdef"; std::string long_to_hex_string(uint64_t number) { std::string hex_string(16, '0'); From b8862df0349a8c701a3864a5fef421f7db00b4d9 Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Mon, 22 Jan 2024 01:17:34 -0600 Subject: [PATCH 07/18] linter fixes --- xml_converter/src/hash_helpers.cpp | 2 +- xml_converter/src/hash_helpers.hpp | 1 + xml_converter/src/packaging_xml.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/xml_converter/src/hash_helpers.cpp b/xml_converter/src/hash_helpers.cpp index 7e54317e..2401d204 100644 --- a/xml_converter/src/hash_helpers.cpp +++ b/xml_converter/src/hash_helpers.cpp @@ -95,4 +95,4 @@ UniqueId Hash128::unique_id() const { (unsigned char)((this->lower >> 24) & 0xFF), }; return unique_id; -} \ No newline at end of file +} diff --git a/xml_converter/src/hash_helpers.hpp b/xml_converter/src/hash_helpers.hpp index 82e4af6c..9f982918 100644 --- a/xml_converter/src/hash_helpers.hpp +++ b/xml_converter/src/hash_helpers.hpp @@ -1,6 +1,7 @@ #pragma once #include + #include "attribute/unique_id.hpp" class Hash64 { diff --git a/xml_converter/src/packaging_xml.cpp b/xml_converter/src/packaging_xml.cpp index 945cbe3d..56b0e68e 100644 --- a/xml_converter/src/packaging_xml.cpp +++ b/xml_converter/src/packaging_xml.cpp @@ -2,11 +2,11 @@ #include +#include "hash_helpers.hpp" #include "rapid_helpers.hpp" #include "rapidxml-1.13/rapidxml.hpp" #include "rapidxml-1.13/rapidxml_utils.hpp" #include "string_helper.hpp" -#include "hash_helpers.hpp" using namespace std; From 886a0dc83cc20c4680ba93f317cb6b851b3d5b8e Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Mon, 22 Jan 2024 01:37:02 -0600 Subject: [PATCH 08/18] Adding a couple of sanity tests and making base64 logic more readable --- xml_converter/src/string_helper.cpp | 50 ++++++++++----------- xml_converter/tests/test_base64.cpp | 67 +++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 xml_converter/tests/test_base64.cpp diff --git a/xml_converter/src/string_helper.cpp b/xml_converter/src/string_helper.cpp index a8c7ca32..3f0056f2 100644 --- a/xml_converter/src/string_helper.cpp +++ b/xml_converter/src/string_helper.cpp @@ -144,41 +144,41 @@ static const char base64_chars[] = std::string base64_encode(uint8_t const* buf, unsigned int bufLen) { std::string ret; - int i = 0; - int j = 0; - uint8_t char_array_3[3]; - uint8_t char_array_4[4]; + int input_chunk_index = 0; + int output_chunk_index = 0; + uint8_t input_chunk[3]; + uint8_t output_chunk[4]; while (bufLen--) { - char_array_3[i++] = *(buf++); - if (i == 3) { - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; - - for (i = 0; (i < 4); i++) { - ret += base64_chars[char_array_4[i]]; + input_chunk[input_chunk_index++] = *(buf++); + if (input_chunk_index == 3) { + output_chunk[0] = (input_chunk[0] & 0xfc) >> 2; + output_chunk[1] = ((input_chunk[0] & 0x03) << 4) + ((input_chunk[1] & 0xf0) >> 4); + output_chunk[2] = ((input_chunk[1] & 0x0f) << 2) + ((input_chunk[2] & 0xc0) >> 6); + output_chunk[3] = input_chunk[2] & 0x3f; + + for (output_chunk_index = 0; output_chunk_index < 4; output_chunk_index++) { + ret += base64_chars[output_chunk[output_chunk_index]]; } - i = 0; + input_chunk_index = 0; } } - if (i) { - for (j = i; j < 3; j++) { - char_array_3[j] = '\0'; + if (input_chunk_index > 0) { + for (output_chunk_index = input_chunk_index; output_chunk_index < 3; output_chunk_index++) { + input_chunk[output_chunk_index] = 0; } - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; + output_chunk[0] = (input_chunk[0] & 0xfc) >> 2; + output_chunk[1] = ((input_chunk[0] & 0x03) << 4) + ((input_chunk[1] & 0xf0) >> 4); + output_chunk[2] = ((input_chunk[1] & 0x0f) << 2) + ((input_chunk[2] & 0xc0) >> 6); + output_chunk[3] = input_chunk[2] & 0x3f; - for (j = 0; (j < i + 1); j++) { - ret += base64_chars[char_array_4[j]]; + for (output_chunk_index = 0; (output_chunk_index < input_chunk_index + 1); output_chunk_index++) { + ret += base64_chars[output_chunk[output_chunk_index]]; } - while (i++ < 3) { + while (input_chunk_index++ < 3) { ret += '='; } } @@ -239,6 +239,7 @@ std::vector base64_decode(std::string const& encoded_string) { if (char_array_4[i] == 255) { // TODO: Throw an error or something + std::cerr << "Found an invalid letter when decoding base64" << std::endl; return std::vector(); } } @@ -259,6 +260,7 @@ std::vector base64_decode(std::string const& encoded_string) { if (char_array_4[i] == 255) { // TODO: Throw an error or something + std::cerr << "Found an invalid letter when decoding base64" << std::endl; return std::vector(); } } diff --git a/xml_converter/tests/test_base64.cpp b/xml_converter/tests/test_base64.cpp new file mode 100644 index 00000000..a7a996b5 --- /dev/null +++ b/xml_converter/tests/test_base64.cpp @@ -0,0 +1,67 @@ +#include "../src/string_helper.hpp" +#include + +class Base64Test : public ::testing::Test {}; + +// Test Strip Bits + +//////////////////////////////////////////////////////////////////////////////// +// Test Double Strip Bits +// +// When there are `len%4 = 2` there are 4 extra bits stored in the base64 string +// This means that decoding and encoding that data will result in slightly +// different data bsecause those 4 extra bits get stripped off. This tests all +// of those different values so that we can be sure everything is happening +// deterministically. +//////////////////////////////////////////////////////////////////////////////// +TEST_F(Base64Test, DoubleStripBits00) { + // These are all of the base 64 characters which start with the binary + // digits 00 and end with nonzero digits. + std::string b64_00_characters = "BCDEFGHIJKLMNOP"; + + for (size_t i = 0; i < b64_00_characters.size(); i++) { + std::string input = "A_"; + input[1] = b64_00_characters[i]; + std::vector decoded_value = base64_decode(input); + std::string output = base64_encode(&decoded_value[0], decoded_value.size()); + EXPECT_EQ(output, "AA=="); + } +} +TEST_F(Base64Test, DoubleStripBits01) { + // These are all of the base 64 characters which start with the binary + // digits 01 and end with nonzero digits. + std::string b64_00_characters = "RSTUVWXYZabcdef"; + + for (size_t i = 0; i < b64_00_characters.size(); i++) { + std::string input = "A_"; + input[1] = b64_00_characters[i]; + std::vector decoded_value = base64_decode(input); + std::string output = base64_encode(&decoded_value[0], decoded_value.size()); + EXPECT_EQ(output, "AQ=="); + } +} +TEST_F(Base64Test, DoubleStripBits10) { + // These are all of the base 64 characters which start with the binary + // digits 10 and end with nonzero digits. + std::string b64_00_characters = "hijklmnopqrstuv"; + + for (size_t i = 0; i < b64_00_characters.size(); i++) { + std::string input = "A_"; + input[1] = b64_00_characters[i]; + std::vector decoded_value = base64_decode(input); + std::string output = base64_encode(&decoded_value[0], decoded_value.size()); + EXPECT_EQ(output, "Ag=="); + } +} +TEST_F(Base64Test, DoubleStripBits11) { + // These are all of the base 64 characters which start with the binary + // digits 11 and end with nonzero digits. + std::string b64_00_characters = "xyz0123456789+/"; + for (size_t i = 0; i < b64_00_characters.size(); i++) { + std::string input = "A_"; + input[1] = b64_00_characters[i]; + std::vector decoded_value = base64_decode(input); + std::string output = base64_encode(&decoded_value[0], decoded_value.size()); + EXPECT_EQ(output, "Aw=="); + } +} From 22b824ccfb58b6ca8f7aa794c8e1524f241fed3d Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Mon, 22 Jan 2024 03:47:20 -0600 Subject: [PATCH 09/18] removing unused "state" warnings to highlight more important warnings --- .../attribute_template_compoundvalue.cpp | 10 +++++----- .../cpp_templates/attribute_template_enum.cpp | 8 ++++---- .../attribute_template_multiflagvalue.cpp | 8 ++++---- xml_converter/src/attribute/bool.cpp | 12 ++++++------ xml_converter/src/attribute/color.cpp | 8 ++++---- xml_converter/src/attribute/cull_chirality_gen.cpp | 8 ++++---- xml_converter/src/attribute/euler_rotation_gen.cpp | 10 +++++----- .../src/attribute/festival_filter_gen.cpp | 8 ++++---- xml_converter/src/attribute/float.cpp | 10 +++++----- xml_converter/src/attribute/image.cpp | 4 ++-- xml_converter/src/attribute/int.cpp | 8 ++++---- .../src/attribute/map_type_filter_gen.cpp | 8 ++++---- xml_converter/src/attribute/marker_category.cpp | 10 +++++----- xml_converter/src/attribute/mount_filter_gen.cpp | 8 ++++---- xml_converter/src/attribute/position_gen.cpp | 8 ++++---- .../src/attribute/profession_filter_gen.cpp | 8 ++++---- xml_converter/src/attribute/reset_behavior_gen.cpp | 8 ++++---- .../src/attribute/specialization_filter_gen.cpp | 8 ++++---- xml_converter/src/attribute/species_filter_gen.cpp | 8 ++++---- xml_converter/src/attribute/string.cpp | 14 +++++++------- xml_converter/src/attribute/trail_data.cpp | 4 ++-- xml_converter/src/attribute/unique_id.cpp | 10 +++++----- 22 files changed, 94 insertions(+), 94 deletions(-) diff --git a/xml_converter/generators/cpp_templates/attribute_template_compoundvalue.cpp b/xml_converter/generators/cpp_templates/attribute_template_compoundvalue.cpp index d70e79bc..214a7a8c 100644 --- a/xml_converter/generators/cpp_templates/attribute_template_compoundvalue.cpp +++ b/xml_converter/generators/cpp_templates/attribute_template_compoundvalue.cpp @@ -13,8 +13,8 @@ using namespace std; void xml_attribute_to_{{attribute_name}}( rapidxml::xml_attribute<>* input, - std::vector* errors, - XMLReaderState* state, + std::vector*, + XMLReaderState*, {{class_name}}* value, bool* is_set) { {{class_name}} {{attribute_name}}; @@ -36,7 +36,7 @@ void xml_attribute_to_{{attribute_name}}( {% if xml_bundled_components != [] %} string {{attribute_name}}_to_xml_attribute( const std::string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const {{class_name}}* value) { string output; {% for n, attribute_component in enumerate(attribute_components) %} @@ -54,7 +54,7 @@ void xml_attribute_to_{{attribute_name}}( void proto_to_{{attribute_name}}( {{proto_field_cpp_type}} input, - ProtoReaderState* state, + ProtoReaderState*, {{class_name}}* value, bool* is_set) { {{class_name}} {{attribute_name}}; @@ -67,7 +67,7 @@ void proto_to_{{attribute_name}}( void {{attribute_name}}_to_proto( {{class_name}} value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { {{proto_field_cpp_type}}* proto_{{attribute_name}} = new {{proto_field_cpp_type}}(); {% for attribute_component in attribute_components %} diff --git a/xml_converter/generators/cpp_templates/attribute_template_enum.cpp b/xml_converter/generators/cpp_templates/attribute_template_enum.cpp index a842c843..bbf8195e 100644 --- a/xml_converter/generators/cpp_templates/attribute_template_enum.cpp +++ b/xml_converter/generators/cpp_templates/attribute_template_enum.cpp @@ -15,7 +15,7 @@ using namespace std; void xml_attribute_to_{{attribute_name}}( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, {{class_name}}* value, bool* is_set) { {{class_name}} {{attribute_name}}; @@ -43,7 +43,7 @@ void xml_attribute_to_{{attribute_name}}( string {{attribute_name}}_to_xml_attribute( const std::string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const {{class_name}}* value) { {% for n, attribute_component in enumerate(attribute_components) %} {% for i, value in enumerate(attribute_component.xml_fields) %} @@ -63,7 +63,7 @@ string {{attribute_name}}_to_xml_attribute( void proto_to_{{attribute_name}}( {{proto_field_cpp_type}} input, - ProtoReaderState* state, + ProtoReaderState*, {{class_name}}* value, bool* is_set) { switch (input) { @@ -82,7 +82,7 @@ void proto_to_{{attribute_name}}( void {{attribute_name}}_to_proto( {{class_name}} value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { switch (value) { {% for attribute_component in attribute_components %} diff --git a/xml_converter/generators/cpp_templates/attribute_template_multiflagvalue.cpp b/xml_converter/generators/cpp_templates/attribute_template_multiflagvalue.cpp index ced609f7..b45c65c2 100644 --- a/xml_converter/generators/cpp_templates/attribute_template_multiflagvalue.cpp +++ b/xml_converter/generators/cpp_templates/attribute_template_multiflagvalue.cpp @@ -15,7 +15,7 @@ using namespace std; void xml_attribute_to_{{attribute_name}}( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, {{class_name}}* value, bool* is_set) { {{class_name}} {{attribute_name}}; @@ -51,7 +51,7 @@ void xml_attribute_to_{{attribute_name}}( string {{attribute_name}}_to_xml_attribute( const std::string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const {{class_name}}* value) { vector flag_values; {% for n, attribute_component in enumerate(attribute_components) %} @@ -65,7 +65,7 @@ string {{attribute_name}}_to_xml_attribute( void proto_to_{{attribute_name}}( {{proto_field_cpp_type}} input, - ProtoReaderState* state, + ProtoReaderState*, {{class_name}}* value, bool* is_set) { {{class_name}} {{attribute_name}}; @@ -78,7 +78,7 @@ void proto_to_{{attribute_name}}( void {{attribute_name}}_to_proto( {{class_name}} value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { {{proto_field_cpp_type}}* proto_{{attribute_name}} = new {{proto_field_cpp_type}}(); bool should_write = false; diff --git a/xml_converter/src/attribute/bool.cpp b/xml_converter/src/attribute/bool.cpp index 3349cba9..d680bfb0 100644 --- a/xml_converter/src/attribute/bool.cpp +++ b/xml_converter/src/attribute/bool.cpp @@ -19,7 +19,7 @@ using namespace std; void xml_attribute_to_bool( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, bool* value, bool* is_set) { if (get_attribute_value(input) == "0" || get_attribute_value(input) == "false") { @@ -42,7 +42,7 @@ void xml_attribute_to_bool( //////////////////////////////////////////////////////////////////////////////// string bool_to_xml_attribute( const string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const bool* value) { if (*value) { return " " + attribute_name + "=\"true\""; @@ -62,7 +62,7 @@ string bool_to_xml_attribute( void inverted_xml_attribute_to_bool( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, bool* value, bool* is_set) { if (get_attribute_value(input) == "0" || get_attribute_value(input) == "false") { @@ -85,7 +85,7 @@ void inverted_xml_attribute_to_bool( //////////////////////////////////////////////////////////////////////////////// string bool_to_inverted_xml_attribute( const string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const bool* value) { if (*value) { return " " + attribute_name + "=\"false\""; @@ -102,7 +102,7 @@ string bool_to_inverted_xml_attribute( //////////////////////////////////////////////////////////////////////////////// void proto_to_bool( bool input, - ProtoReaderState* state, + ProtoReaderState*, bool* value, bool* is_set) { *value = input; @@ -116,7 +116,7 @@ void proto_to_bool( //////////////////////////////////////////////////////////////////////////////// void bool_to_proto( bool value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { setter(value); } diff --git a/xml_converter/src/attribute/color.cpp b/xml_converter/src/attribute/color.cpp index 82713096..feb9c4ee 100644 --- a/xml_converter/src/attribute/color.cpp +++ b/xml_converter/src/attribute/color.cpp @@ -51,7 +51,7 @@ int convert_color_channel_float_to_int(float input) { void xml_attribute_to_color( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, Color* value, bool* is_set) { Color color; @@ -98,7 +98,7 @@ void xml_attribute_to_color( //////////////////////////////////////////////////////////////////////////////// string color_to_xml_attribute( const string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const Color* value) { std::stringstream stream; std::string hex_string = "#"; @@ -124,7 +124,7 @@ string color_to_xml_attribute( //////////////////////////////////////////////////////////////////////////////// void proto_to_color( waypoint::RGBAColor input, - ProtoReaderState* state, + ProtoReaderState*, Color* value, bool* is_set) { Color color; @@ -147,7 +147,7 @@ void proto_to_color( //////////////////////////////////////////////////////////////////////////////// void color_to_proto( Color value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { waypoint::RGBAColor* color = new waypoint::RGBAColor(); // The default RGB in burrito will be 000000 (i.e. black) diff --git a/xml_converter/src/attribute/cull_chirality_gen.cpp b/xml_converter/src/attribute/cull_chirality_gen.cpp index 1decb63c..9d2c9243 100644 --- a/xml_converter/src/attribute/cull_chirality_gen.cpp +++ b/xml_converter/src/attribute/cull_chirality_gen.cpp @@ -15,7 +15,7 @@ using namespace std; void xml_attribute_to_cull_chirality( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, CullChirality* value, bool* is_set) { CullChirality cull_chirality; @@ -39,7 +39,7 @@ void xml_attribute_to_cull_chirality( string cull_chirality_to_xml_attribute( const std::string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const CullChirality* value) { if (*value == CullChirality::none) { return " " + attribute_name + "=\"" + "none" + "\""; @@ -57,7 +57,7 @@ string cull_chirality_to_xml_attribute( void proto_to_cull_chirality( waypoint::CullChirality input, - ProtoReaderState* state, + ProtoReaderState*, CullChirality* value, bool* is_set) { switch (input) { @@ -82,7 +82,7 @@ void proto_to_cull_chirality( void cull_chirality_to_proto( CullChirality value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { switch (value) { case CullChirality::none: diff --git a/xml_converter/src/attribute/euler_rotation_gen.cpp b/xml_converter/src/attribute/euler_rotation_gen.cpp index e2cece3c..8e4a311e 100644 --- a/xml_converter/src/attribute/euler_rotation_gen.cpp +++ b/xml_converter/src/attribute/euler_rotation_gen.cpp @@ -13,8 +13,8 @@ using namespace std; void xml_attribute_to_euler_rotation( rapidxml::xml_attribute<>* input, - std::vector* errors, - XMLReaderState* state, + std::vector*, + XMLReaderState*, EulerRotation* value, bool* is_set) { EulerRotation euler_rotation; @@ -35,7 +35,7 @@ void xml_attribute_to_euler_rotation( } string euler_rotation_to_xml_attribute( const std::string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const EulerRotation* value) { string output; output = to_string(value->x_rotation); @@ -46,7 +46,7 @@ string euler_rotation_to_xml_attribute( void proto_to_euler_rotation( waypoint::EulerRotation input, - ProtoReaderState* state, + ProtoReaderState*, EulerRotation* value, bool* is_set) { EulerRotation euler_rotation; @@ -59,7 +59,7 @@ void proto_to_euler_rotation( void euler_rotation_to_proto( EulerRotation value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { waypoint::EulerRotation* proto_euler_rotation = new waypoint::EulerRotation(); proto_euler_rotation->set_x(value.x_rotation); diff --git a/xml_converter/src/attribute/festival_filter_gen.cpp b/xml_converter/src/attribute/festival_filter_gen.cpp index 79fe6435..86e44ec3 100644 --- a/xml_converter/src/attribute/festival_filter_gen.cpp +++ b/xml_converter/src/attribute/festival_filter_gen.cpp @@ -15,7 +15,7 @@ using namespace std; void xml_attribute_to_festival_filter( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, FestivalFilter* value, bool* is_set) { FestivalFilter festival_filter; @@ -66,7 +66,7 @@ void xml_attribute_to_festival_filter( string festival_filter_to_xml_attribute( const std::string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const FestivalFilter* value) { vector flag_values; if (value->dragonbash == true) { @@ -96,7 +96,7 @@ string festival_filter_to_xml_attribute( void proto_to_festival_filter( waypoint::FestivalFilter input, - ProtoReaderState* state, + ProtoReaderState*, FestivalFilter* value, bool* is_set) { FestivalFilter festival_filter; @@ -113,7 +113,7 @@ void proto_to_festival_filter( void festival_filter_to_proto( FestivalFilter value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { waypoint::FestivalFilter* proto_festival_filter = new waypoint::FestivalFilter(); bool should_write = false; diff --git a/xml_converter/src/attribute/float.cpp b/xml_converter/src/attribute/float.cpp index aa76a7b7..42d152cb 100644 --- a/xml_converter/src/attribute/float.cpp +++ b/xml_converter/src/attribute/float.cpp @@ -14,8 +14,8 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// void xml_attribute_to_float( rapidxml::xml_attribute<>* input, - std::vector* errors, - XMLReaderState* state, + std::vector*, + XMLReaderState*, float* value, bool* is_set) { *value = std::stof(get_attribute_value(input)); @@ -29,7 +29,7 @@ void xml_attribute_to_float( //////////////////////////////////////////////////////////////////////////////// string float_to_xml_attribute( const string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const float* value) { return " " + attribute_name + "=\"" + to_string(*value) + "\""; } @@ -41,7 +41,7 @@ string float_to_xml_attribute( //////////////////////////////////////////////////////////////////////////////// void proto_to_float( float input, - ProtoReaderState* state, + ProtoReaderState*, float* value, bool* is_set) { *value = input; @@ -55,7 +55,7 @@ void proto_to_float( //////////////////////////////////////////////////////////////////////////////// void float_to_proto( float value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { setter(value); } diff --git a/xml_converter/src/attribute/image.cpp b/xml_converter/src/attribute/image.cpp index 6c0f179e..dcbe677d 100644 --- a/xml_converter/src/attribute/image.cpp +++ b/xml_converter/src/attribute/image.cpp @@ -17,7 +17,7 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// void xml_attribute_to_image( rapidxml::xml_attribute<>* input, - std::vector* errors, + std::vector*, XMLReaderState* state, Image* value, bool* is_set) { @@ -33,7 +33,7 @@ void xml_attribute_to_image( //////////////////////////////////////////////////////////////////////////////// string image_to_xml_attribute( const string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const Image* value) { return " " + attribute_name + "=\"" + value->filename + "\""; } diff --git a/xml_converter/src/attribute/int.cpp b/xml_converter/src/attribute/int.cpp index 62d769c3..46466f7e 100644 --- a/xml_converter/src/attribute/int.cpp +++ b/xml_converter/src/attribute/int.cpp @@ -19,7 +19,7 @@ using namespace std; void xml_attribute_to_int( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, int* value, bool* is_set) { try { @@ -44,7 +44,7 @@ void xml_attribute_to_int( //////////////////////////////////////////////////////////////////////////////// string int_to_xml_attribute( const string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const int* value) { return " " + attribute_name + "=\"" + to_string(*value) + "\""; } @@ -56,7 +56,7 @@ string int_to_xml_attribute( //////////////////////////////////////////////////////////////////////////////// void proto_to_int( int input, - ProtoReaderState* state, + ProtoReaderState*, int* value, bool* is_set) { *value = input; @@ -70,7 +70,7 @@ void proto_to_int( //////////////////////////////////////////////////////////////////////////////// void int_to_proto( int value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { setter(value); } diff --git a/xml_converter/src/attribute/map_type_filter_gen.cpp b/xml_converter/src/attribute/map_type_filter_gen.cpp index 6d3331aa..15621c57 100644 --- a/xml_converter/src/attribute/map_type_filter_gen.cpp +++ b/xml_converter/src/attribute/map_type_filter_gen.cpp @@ -15,7 +15,7 @@ using namespace std; void xml_attribute_to_map_type_filter( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, MapTypeFilter* value, bool* is_set) { MapTypeFilter map_type_filter; @@ -131,7 +131,7 @@ void xml_attribute_to_map_type_filter( string map_type_filter_to_xml_attribute( const std::string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const MapTypeFilter* value) { vector flag_values; if (value->unknown_map == true) { @@ -212,7 +212,7 @@ string map_type_filter_to_xml_attribute( void proto_to_map_type_filter( waypoint::MapTypeFilter input, - ProtoReaderState* state, + ProtoReaderState*, MapTypeFilter* value, bool* is_set) { MapTypeFilter map_type_filter; @@ -246,7 +246,7 @@ void proto_to_map_type_filter( void map_type_filter_to_proto( MapTypeFilter value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { waypoint::MapTypeFilter* proto_map_type_filter = new waypoint::MapTypeFilter(); bool should_write = false; diff --git a/xml_converter/src/attribute/marker_category.cpp b/xml_converter/src/attribute/marker_category.cpp index e47f8098..36da71e0 100644 --- a/xml_converter/src/attribute/marker_category.cpp +++ b/xml_converter/src/attribute/marker_category.cpp @@ -14,8 +14,8 @@ //////////////////////////////////////////////////////////////////////////////// void xml_attribute_to_marker_category( rapidxml::xml_attribute<>* input, - std::vector* errors, - XMLReaderState* state, + std::vector*, + XMLReaderState*, MarkerCategory* value, bool* is_set) { value->category = get_attribute_value(input); @@ -29,7 +29,7 @@ void xml_attribute_to_marker_category( //////////////////////////////////////////////////////////////////////////////// std::string marker_category_to_xml_attribute( const std::string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const MarkerCategory* value) { return " " + attribute_name + "=\"" + value->category + "\""; } @@ -41,7 +41,7 @@ std::string marker_category_to_xml_attribute( //////////////////////////////////////////////////////////////////////////////// void proto_to_marker_category( waypoint::Category input, - ProtoReaderState* state, + ProtoReaderState*, MarkerCategory* value, bool* is_set) { MarkerCategory marker_category; @@ -57,7 +57,7 @@ void proto_to_marker_category( //////////////////////////////////////////////////////////////////////////////// void marker_category_to_proto( MarkerCategory value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { waypoint::Category* category = new waypoint::Category(); category->set_name(value.category); diff --git a/xml_converter/src/attribute/mount_filter_gen.cpp b/xml_converter/src/attribute/mount_filter_gen.cpp index 8dc824b6..5366b4db 100644 --- a/xml_converter/src/attribute/mount_filter_gen.cpp +++ b/xml_converter/src/attribute/mount_filter_gen.cpp @@ -15,7 +15,7 @@ using namespace std; void xml_attribute_to_mount_filter( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, MountFilter* value, bool* is_set) { MountFilter mount_filter; @@ -75,7 +75,7 @@ void xml_attribute_to_mount_filter( string mount_filter_to_xml_attribute( const std::string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const MountFilter* value) { vector flag_values; if (value->raptor == true) { @@ -114,7 +114,7 @@ string mount_filter_to_xml_attribute( void proto_to_mount_filter( waypoint::MountFilter input, - ProtoReaderState* state, + ProtoReaderState*, MountFilter* value, bool* is_set) { MountFilter mount_filter; @@ -134,7 +134,7 @@ void proto_to_mount_filter( void mount_filter_to_proto( MountFilter value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { waypoint::MountFilter* proto_mount_filter = new waypoint::MountFilter(); bool should_write = false; diff --git a/xml_converter/src/attribute/position_gen.cpp b/xml_converter/src/attribute/position_gen.cpp index 40d284e0..cf949a23 100644 --- a/xml_converter/src/attribute/position_gen.cpp +++ b/xml_converter/src/attribute/position_gen.cpp @@ -13,8 +13,8 @@ using namespace std; void xml_attribute_to_position( rapidxml::xml_attribute<>* input, - std::vector* errors, - XMLReaderState* state, + std::vector*, + XMLReaderState*, Position* value, bool* is_set) { Position position; @@ -36,7 +36,7 @@ void xml_attribute_to_position( void proto_to_position( waypoint::Position input, - ProtoReaderState* state, + ProtoReaderState*, Position* value, bool* is_set) { Position position; @@ -49,7 +49,7 @@ void proto_to_position( void position_to_proto( Position value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { waypoint::Position* proto_position = new waypoint::Position(); proto_position->set_x(value.x_position); diff --git a/xml_converter/src/attribute/profession_filter_gen.cpp b/xml_converter/src/attribute/profession_filter_gen.cpp index 32ec9329..2f8e9eaf 100644 --- a/xml_converter/src/attribute/profession_filter_gen.cpp +++ b/xml_converter/src/attribute/profession_filter_gen.cpp @@ -15,7 +15,7 @@ using namespace std; void xml_attribute_to_profession_filter( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, ProfessionFilter* value, bool* is_set) { ProfessionFilter profession_filter; @@ -71,7 +71,7 @@ void xml_attribute_to_profession_filter( string profession_filter_to_xml_attribute( const std::string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const ProfessionFilter* value) { vector flag_values; if (value->guardian == true) { @@ -107,7 +107,7 @@ string profession_filter_to_xml_attribute( void proto_to_profession_filter( waypoint::ProfessionFilter input, - ProtoReaderState* state, + ProtoReaderState*, ProfessionFilter* value, bool* is_set) { ProfessionFilter profession_filter; @@ -126,7 +126,7 @@ void proto_to_profession_filter( void profession_filter_to_proto( ProfessionFilter value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { waypoint::ProfessionFilter* proto_profession_filter = new waypoint::ProfessionFilter(); bool should_write = false; diff --git a/xml_converter/src/attribute/reset_behavior_gen.cpp b/xml_converter/src/attribute/reset_behavior_gen.cpp index 47730fc3..ec186d1f 100644 --- a/xml_converter/src/attribute/reset_behavior_gen.cpp +++ b/xml_converter/src/attribute/reset_behavior_gen.cpp @@ -15,7 +15,7 @@ using namespace std; void xml_attribute_to_reset_behavior( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, ResetBehavior* value, bool* is_set) { ResetBehavior reset_behavior; @@ -84,7 +84,7 @@ void xml_attribute_to_reset_behavior( string reset_behavior_to_xml_attribute( const std::string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const ResetBehavior* value) { if (*value == ResetBehavior::always_visible) { return " " + attribute_name + "=\"" + "0" + "\""; @@ -147,7 +147,7 @@ string reset_behavior_to_xml_attribute( void proto_to_reset_behavior( waypoint::ResetBehavior input, - ProtoReaderState* state, + ProtoReaderState*, ResetBehavior* value, bool* is_set) { switch (input) { @@ -196,7 +196,7 @@ void proto_to_reset_behavior( void reset_behavior_to_proto( ResetBehavior value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { switch (value) { case ResetBehavior::always_visible: diff --git a/xml_converter/src/attribute/specialization_filter_gen.cpp b/xml_converter/src/attribute/specialization_filter_gen.cpp index 4849a8d0..ffb25509 100644 --- a/xml_converter/src/attribute/specialization_filter_gen.cpp +++ b/xml_converter/src/attribute/specialization_filter_gen.cpp @@ -15,7 +15,7 @@ using namespace std; void xml_attribute_to_specialization_filter( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, SpecializationFilter* value, bool* is_set) { SpecializationFilter specialization_filter; @@ -404,7 +404,7 @@ void xml_attribute_to_specialization_filter( string specialization_filter_to_xml_attribute( const std::string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const SpecializationFilter* value) { vector flag_values; if (value->elementalist_tempest == true) { @@ -629,7 +629,7 @@ string specialization_filter_to_xml_attribute( void proto_to_specialization_filter( waypoint::SpecializationFilter input, - ProtoReaderState* state, + ProtoReaderState*, SpecializationFilter* value, bool* is_set) { SpecializationFilter specialization_filter; @@ -711,7 +711,7 @@ void proto_to_specialization_filter( void specialization_filter_to_proto( SpecializationFilter value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { waypoint::SpecializationFilter* proto_specialization_filter = new waypoint::SpecializationFilter(); bool should_write = false; diff --git a/xml_converter/src/attribute/species_filter_gen.cpp b/xml_converter/src/attribute/species_filter_gen.cpp index b032771c..1a9f79b3 100644 --- a/xml_converter/src/attribute/species_filter_gen.cpp +++ b/xml_converter/src/attribute/species_filter_gen.cpp @@ -15,7 +15,7 @@ using namespace std; void xml_attribute_to_species_filter( rapidxml::xml_attribute<>* input, std::vector* errors, - XMLReaderState* state, + XMLReaderState*, SpeciesFilter* value, bool* is_set) { SpeciesFilter species_filter; @@ -55,7 +55,7 @@ void xml_attribute_to_species_filter( string species_filter_to_xml_attribute( const std::string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const SpeciesFilter* value) { vector flag_values; if (value->asura == true) { @@ -79,7 +79,7 @@ string species_filter_to_xml_attribute( void proto_to_species_filter( waypoint::SpeciesFilter input, - ProtoReaderState* state, + ProtoReaderState*, SpeciesFilter* value, bool* is_set) { SpeciesFilter species_filter; @@ -94,7 +94,7 @@ void proto_to_species_filter( void species_filter_to_proto( SpeciesFilter value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { waypoint::SpeciesFilter* proto_species_filter = new waypoint::SpeciesFilter(); bool should_write = false; diff --git a/xml_converter/src/attribute/string.cpp b/xml_converter/src/attribute/string.cpp index 910c69b7..f3845609 100644 --- a/xml_converter/src/attribute/string.cpp +++ b/xml_converter/src/attribute/string.cpp @@ -17,8 +17,8 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// void xml_attribute_to_string( rapidxml::xml_attribute<>* input, - std::vector* errors, - XMLReaderState* state, + std::vector*, + XMLReaderState*, string* value, bool* is_set) { *value = get_attribute_value(input); @@ -32,7 +32,7 @@ void xml_attribute_to_string( //////////////////////////////////////////////////////////////////////////////// string string_to_xml_attribute( const string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const string* value) { return " " + attribute_name + "=\"" + *value + "\""; } @@ -44,7 +44,7 @@ string string_to_xml_attribute( //////////////////////////////////////////////////////////////////////////////// void proto_to_string( string input, - ProtoReaderState* state, + ProtoReaderState*, string* value, bool* is_set) { *value = input; @@ -58,14 +58,14 @@ void proto_to_string( //////////////////////////////////////////////////////////////////////////////// void string_to_proto( std::string value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { setter(value); } void proto_display_name_to_display_name_and_name( std::string input, - ProtoReaderState* state, + ProtoReaderState*, std::string* display_name, bool* is_display_name_set, std::string* name, @@ -78,7 +78,7 @@ void proto_display_name_to_display_name_and_name( void display_name_and_name_to_proto_display_name( std::string value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter, const std::string* name, const bool* is_name_set) { diff --git a/xml_converter/src/attribute/trail_data.cpp b/xml_converter/src/attribute/trail_data.cpp index b3f19690..c6fd8c26 100644 --- a/xml_converter/src/attribute/trail_data.cpp +++ b/xml_converter/src/attribute/trail_data.cpp @@ -153,7 +153,7 @@ string trail_data_to_xml_attribute( //////////////////////////////////////////////////////////////////////////////// void proto_to_trail_data( waypoint::TrailData input, - ProtoReaderState* state, + ProtoReaderState*, TrailData* value, bool* is_set) { TrailData trail_data; @@ -171,7 +171,7 @@ void proto_to_trail_data( //////////////////////////////////////////////////////////////////////////////// void trail_data_to_proto( TrailData value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { waypoint::TrailData* trail_data = new waypoint::TrailData(); *trail_data->mutable_points_x() = {value.points_x.begin(), value.points_x.end()}; diff --git a/xml_converter/src/attribute/unique_id.cpp b/xml_converter/src/attribute/unique_id.cpp index 70dc953d..107ec2f8 100644 --- a/xml_converter/src/attribute/unique_id.cpp +++ b/xml_converter/src/attribute/unique_id.cpp @@ -14,8 +14,8 @@ using namespace std; void xml_attribute_to_unique_id( rapidxml::xml_attribute<>* input, - std::vector* errors, - XMLReaderState* state, + std::vector*, + XMLReaderState*, UniqueId* value, bool* is_set) { string base64; @@ -32,7 +32,7 @@ void xml_attribute_to_unique_id( //////////////////////////////////////////////////////////////////////////////// string unique_id_to_xml_attribute( const string& attribute_name, - XMLWriterState* state, + XMLWriterState*, const UniqueId* value) { return " " + attribute_name + "=\"" + base64_encode(&(value->guid[0]), value->guid.size()) + "\""; } @@ -44,7 +44,7 @@ string unique_id_to_xml_attribute( //////////////////////////////////////////////////////////////////////////////// void proto_to_unique_id( std::string input, - ProtoReaderState* state, + ProtoReaderState*, UniqueId* value, bool* is_set) { UniqueId unique_id; @@ -61,7 +61,7 @@ void proto_to_unique_id( //////////////////////////////////////////////////////////////////////////////// void unique_id_to_proto( UniqueId value, - ProtoWriterState* state, + ProtoWriterState*, std::function setter) { setter(std::string(value.guid.begin(), value.guid.end())); } From 540152d546f6b2d541f3bbb0e0139ced90c5cb4a Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Tue, 23 Jan 2024 01:51:17 -0600 Subject: [PATCH 10/18] adding doc file --- xml_converter/doc/menu/menu_id.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 xml_converter/doc/menu/menu_id.md diff --git a/xml_converter/doc/menu/menu_id.md b/xml_converter/doc/menu/menu_id.md new file mode 100644 index 00000000..ae312b8a --- /dev/null +++ b/xml_converter/doc/menu/menu_id.md @@ -0,0 +1,15 @@ +--- +name: Menu ID +type: Custom +class: UniqueId +xml_fields: [ID, MenuID] +applies_to: [Category] +protobuf_field: id +--- + +Notes +===== + +A 128bit long Unique ID. + +If the ID is not present when converting from XML, the ID is created as a hash of the category's "name" and the names of the categories parents. From 8ff0e4d9a106b60936d112a86778ded9792f51d5 Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Sat, 3 Feb 2024 16:02:33 -0600 Subject: [PATCH 11/18] Preventing xml node classes from forcing rebuilds when nothing changes --- xml_converter/generators/generate_cpp.py | 26 +++++++++++++++++------- xml_converter/generators/main.py | 5 +++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/xml_converter/generators/generate_cpp.py b/xml_converter/generators/generate_cpp.py index 9f0a6934..2f483555 100644 --- a/xml_converter/generators/generate_cpp.py +++ b/xml_converter/generators/generate_cpp.py @@ -146,8 +146,11 @@ def sorted_cpp_forward_declarations(self) -> List[str]: def write_cpp_classes( output_directory: str, data: Dict[str, Document], -) -> None: +) -> List[str]: print("Writing XML Node Cpp Classes") + + written_files: List[str] = [] + file_loader = FileSystemLoader('cpp_templates') env = Environment( loader=file_loader, @@ -175,17 +178,23 @@ def write_cpp_classes( if attribute_variable.class_name == "marker_category": attributes_of_type_marker_category.append(attribute_variable.attribute_name) - with open(os.path.join(output_directory, lowercase(cpp_class) + "_gen.hpp"), 'w') as f: - f.write(header_template.render( + hpp_filepath = os.path.join(output_directory, lowercase(cpp_class) + "_gen.hpp") + write_if_different( + path=hpp_filepath, + contents=header_template.render( cpp_class=cpp_class, attribute_variables=sorted(attribute_variables, key=get_attribute_variable_key), cpp_includes=cpp_includes, cpp_class_header=lowercase(cpp_class), attributes_of_type_marker_category=attributes_of_type_marker_category, - )) + ), + ) + written_files.append(hpp_filepath) - with open(os.path.join(output_directory, lowercase(cpp_class) + "_gen.cpp"), 'w') as f: - f.write(code_template.render( + cpp_filepath = os.path.join(output_directory, lowercase(cpp_class) + "_gen.cpp") + write_if_different( + path=cpp_filepath, + contents=code_template.render( cpp_class=cpp_class, cpp_includes=cpp_includes, cpp_class_header=lowercase(cpp_class), @@ -193,8 +202,11 @@ def write_cpp_classes( attribute_variables=sorted(attribute_variables, key=get_attribute_variable_key), enumerate=enumerate, attributes_of_type_marker_category=attributes_of_type_marker_category, - )) + ), + ) + written_files.append(cpp_filepath) + return written_files def build_custom_function_data(config: Dict[str, Any]) -> Tuple[str, List[str]]: function = config["function"] diff --git a/xml_converter/generators/main.py b/xml_converter/generators/main.py index 4c9fb7d7..271a45a9 100644 --- a/xml_converter/generators/main.py +++ b/xml_converter/generators/main.py @@ -373,9 +373,10 @@ def main() -> None: generator.load_input_doc(full_markdown_doc_directory) generator.delete_generated_docs("../web_docs") - generator.delete_generated_docs("../src/") generator.write_webdocs("../web_docs/") - write_cpp_classes("../src/", generator.data) + + written_classes = write_cpp_classes("../src/", generator.data) + generator.delete_generated_docs("../src/", skip=written_classes) written_attributes = write_attribute("../src/attribute", generator.data) generator.delete_generated_docs("../src/attribute", skip=written_attributes) From e9c96509c5e2d1564854a9505fdbb031d863afcf Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Sat, 3 Feb 2024 16:05:16 -0600 Subject: [PATCH 12/18] fixing linter --- xml_converter/generators/generate_cpp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xml_converter/generators/generate_cpp.py b/xml_converter/generators/generate_cpp.py index 2f483555..5534ca13 100644 --- a/xml_converter/generators/generate_cpp.py +++ b/xml_converter/generators/generate_cpp.py @@ -208,6 +208,7 @@ def write_cpp_classes( return written_files + def build_custom_function_data(config: Dict[str, Any]) -> Tuple[str, List[str]]: function = config["function"] side_effects = [] From b0cb07b39f46f175e786a2582963e1be4265acff Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Sat, 3 Feb 2024 18:15:01 -0600 Subject: [PATCH 13/18] adding arguments to the generator command --- xml_converter/generators/main.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/xml_converter/generators/main.py b/xml_converter/generators/main.py index 271a45a9..468f7eaf 100644 --- a/xml_converter/generators/main.py +++ b/xml_converter/generators/main.py @@ -10,6 +10,8 @@ from protobuf_types import get_proto_field_type from util import capitalize, SchemaType, Document from generate_cpp import write_cpp_classes, write_attribute +import argparse +import sys XML_ATTRIBUTE_REGEX: Final[str] = "^[A-Za-z]+$" PROTO_FIELD_REGEX: Final[str] = "^[a-z_.]+$" @@ -364,6 +366,14 @@ def generate_auto_docs(self, metadata: Dict[str, SchemaType], content: Dict[str, # markdown files, and then creating the desired output files. ################################################################################ def main() -> None: + parser = argparse.ArgumentParser(description='Process some flags.') + parser.add_argument('--cpp-nodes', help='Generate the XML Node Classes.', action='store_true') + parser.add_argument('--cpp-attributes', help='Generate the XML Attribute functions.', action='store_true') + parser.add_argument('--documentation', help='Generate the HTML documentation.', action='store_true') + args = parser.parse_args() + + generate_all: bool = not args.cpp_nodes and not args.cpp_attributes and not args.documentation + generator = Generator() markdown_doc_directory = "../doc" @@ -372,14 +382,17 @@ def main() -> None: if os.path.isdir(full_markdown_doc_directory): generator.load_input_doc(full_markdown_doc_directory) - generator.delete_generated_docs("../web_docs") - generator.write_webdocs("../web_docs/") + if generate_all or args.documentation: + generator.delete_generated_docs("../web_docs") + generator.write_webdocs("../web_docs/") - written_classes = write_cpp_classes("../src/", generator.data) - generator.delete_generated_docs("../src/", skip=written_classes) + if generate_all or args.cpp_nodes: + written_classes = write_cpp_classes("../src/", generator.data) + generator.delete_generated_docs("../src/", skip=written_classes) - written_attributes = write_attribute("../src/attribute", generator.data) - generator.delete_generated_docs("../src/attribute", skip=written_attributes) + if generate_all or args.cpp_attributes: + written_attributes = write_attribute("../src/attribute", generator.data) + generator.delete_generated_docs("../src/attribute", skip=written_attributes) main() From 43d8f7d851cf61489402e353e1de7c6ca7ae1eb9 Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Sat, 3 Feb 2024 18:17:55 -0600 Subject: [PATCH 14/18] removing sys import --- xml_converter/generators/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml_converter/generators/main.py b/xml_converter/generators/main.py index 468f7eaf..4e8464c3 100644 --- a/xml_converter/generators/main.py +++ b/xml_converter/generators/main.py @@ -11,7 +11,7 @@ from util import capitalize, SchemaType, Document from generate_cpp import write_cpp_classes, write_attribute import argparse -import sys + XML_ATTRIBUTE_REGEX: Final[str] = "^[A-Za-z]+$" PROTO_FIELD_REGEX: Final[str] = "^[a-z_.]+$" From 1869833570fffe09854014482fa06c639100e28a Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Sat, 3 Feb 2024 18:59:38 -0600 Subject: [PATCH 15/18] Fixing some minor issues in the integration tests harness --- xml_converter/integration_tests/run_tests.py | 2 +- xml_converter/integration_tests/src/proto_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xml_converter/integration_tests/run_tests.py b/xml_converter/integration_tests/run_tests.py index c3a5d8a5..99b2bc0d 100755 --- a/xml_converter/integration_tests/run_tests.py +++ b/xml_converter/integration_tests/run_tests.py @@ -263,7 +263,7 @@ def diff_dirs(actual_output_dir: str, expected_output_dir: str) -> bool: if len_diff(diff) != 0: diff_found = True - print("XML output was incorrect for test") + print("Output was incorrect for test") for line in diff: print(line) diff --git a/xml_converter/integration_tests/src/proto_utils.py b/xml_converter/integration_tests/src/proto_utils.py index 38e937e7..115689b1 100644 --- a/xml_converter/integration_tests/src/proto_utils.py +++ b/xml_converter/integration_tests/src/proto_utils.py @@ -16,7 +16,7 @@ def compare_protos( expected_textproto = get_waypoint_textproto(expected_proto_path) actual_textproto = get_waypoint_textproto(actual_proto_path) - diff = list(difflib.unified_diff(expected_textproto.split("\n"), actual_textproto.split("\n"), fromfile=expected_proto_path, tofile=actual_proto_path, lineterm="")) + diff = list(difflib.unified_diff(actual_textproto.split("\n"), expected_textproto.split("\n"), fromfile=actual_proto_path, tofile=expected_proto_path, lineterm="")) if len(diff) == 0: diff = ["Something went wrong diffing {} and {}.".format(expected_proto_path, actual_proto_path)] From 82aa086b7fe85d347916c79017fe92981dcfd199 Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Sat, 3 Feb 2024 19:01:45 -0600 Subject: [PATCH 16/18] Adding a specific test for trail data --- .../test_cases/trail_data/input/pack/trail.trl | Bin 0 -> 44 bytes .../test_cases/trail_data/input/pack/xml_file.xml | 8 ++++++++ .../test_cases/trail_data/output_proto/markers.bin | Bin 0 -> 73 bytes .../trail_data/output_xml/037aa160e392f1c8.trl | Bin 0 -> 44 bytes .../test_cases/trail_data/output_xml/xml_file.xml | 8 ++++++++ .../test_cases/trail_data/testcase.yaml | 5 +++++ 6 files changed, 21 insertions(+) create mode 100644 xml_converter/integration_tests/test_cases/trail_data/input/pack/trail.trl create mode 100644 xml_converter/integration_tests/test_cases/trail_data/input/pack/xml_file.xml create mode 100644 xml_converter/integration_tests/test_cases/trail_data/output_proto/markers.bin create mode 100644 xml_converter/integration_tests/test_cases/trail_data/output_xml/037aa160e392f1c8.trl create mode 100644 xml_converter/integration_tests/test_cases/trail_data/output_xml/xml_file.xml create mode 100644 xml_converter/integration_tests/test_cases/trail_data/testcase.yaml diff --git a/xml_converter/integration_tests/test_cases/trail_data/input/pack/trail.trl b/xml_converter/integration_tests/test_cases/trail_data/input/pack/trail.trl new file mode 100644 index 0000000000000000000000000000000000000000..201ab83c8671d0e579b91b4f4f911c933b6a9de9 GIT binary patch literal 44 ncmZQzU|=u;Vg`l=dmwgTV0Zw;3_!d9L^}eRK>7d>3pfG*cS!~W literal 0 HcmV?d00001 diff --git a/xml_converter/integration_tests/test_cases/trail_data/input/pack/xml_file.xml b/xml_converter/integration_tests/test_cases/trail_data/input/pack/xml_file.xml new file mode 100644 index 00000000..a32e0e53 --- /dev/null +++ b/xml_converter/integration_tests/test_cases/trail_data/input/pack/xml_file.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/xml_converter/integration_tests/test_cases/trail_data/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/trail_data/output_proto/markers.bin new file mode 100644 index 0000000000000000000000000000000000000000..b31d3169e3883e29097b4d446ac637e7ba550115 GIT binary patch literal 73 zcmd;b=i>IQRB%o#Nlni$s#MZbFtXAT;$dKDuxDUkZ~!6)DG(3HS^&fc9F%~(2S65s UBLjngqZ5b5i!*G8CdW+!04}BwNdN!< literal 0 HcmV?d00001 diff --git a/xml_converter/integration_tests/test_cases/trail_data/output_xml/037aa160e392f1c8.trl b/xml_converter/integration_tests/test_cases/trail_data/output_xml/037aa160e392f1c8.trl new file mode 100644 index 0000000000000000000000000000000000000000..201ab83c8671d0e579b91b4f4f911c933b6a9de9 GIT binary patch literal 44 ncmZQzU|=u;Vg`l=dmwgTV0Zw;3_!d9L^}eRK>7d>3pfG*cS!~W literal 0 HcmV?d00001 diff --git a/xml_converter/integration_tests/test_cases/trail_data/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/trail_data/output_xml/xml_file.xml new file mode 100644 index 00000000..87532cf9 --- /dev/null +++ b/xml_converter/integration_tests/test_cases/trail_data/output_xml/xml_file.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/xml_converter/integration_tests/test_cases/trail_data/testcase.yaml b/xml_converter/integration_tests/test_cases/trail_data/testcase.yaml new file mode 100644 index 00000000..9510c793 --- /dev/null +++ b/xml_converter/integration_tests/test_cases/trail_data/testcase.yaml @@ -0,0 +1,5 @@ +input_paths: + "pack": "xml" +expected_stdout: | +expected_stderr: | +expected_returncode: 0 From 8d77e2a23d6fa98d801de7586cb7d408daf68f1d Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Sat, 3 Feb 2024 19:21:58 -0600 Subject: [PATCH 17/18] adding a filter for the integration test harness --- xml_converter/integration_tests/run_tests.py | 44 ++++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/xml_converter/integration_tests/run_tests.py b/xml_converter/integration_tests/run_tests.py index 99b2bc0d..dd4ad715 100755 --- a/xml_converter/integration_tests/run_tests.py +++ b/xml_converter/integration_tests/run_tests.py @@ -5,7 +5,7 @@ import subprocess import re import os -from typing import List, Optional, Final, Tuple +from typing import List, Optional, Tuple from src.testcase_loader import load_testcases import shutil from src.proto_utils import compare_protos, compare_binary_file @@ -13,12 +13,6 @@ # Path to compiled C++ executable xml_converter_binary_path: str = "../build/xml_converter" -arg_input_xml: Final[str] = "--input-taco-path" -arg_output_xml: Final[str] = "--output-taco-path" -arg_input_proto: Final[str] = "--input-waypoint-path" -arg_output_proto: Final[str] = "--output-waypoint-path" -arg_split_proto: Final[str] = "--output-split-waypoint-path" - def run_xml_converter( input_xml: Optional[List[str]] = None, @@ -32,15 +26,15 @@ def run_xml_converter( cmd: List[str] = [xml_converter_binary_path] if input_xml: - cmd += [arg_input_xml] + input_xml + cmd += ["--input-taco-path"] + input_xml if output_xml: - cmd += [arg_output_xml] + output_xml + cmd += ["--output-taco-path"] + output_xml if input_proto: - cmd += [arg_input_proto] + input_proto + cmd += ["--input-waypoint-path"] + input_proto if output_proto: - cmd += [arg_output_proto] + output_proto + cmd += ["--output-waypoint-path"] + output_proto if split_output_proto: - cmd += [arg_split_proto] + [split_output_proto] + cmd += ["--output-split-waypoint-path"] + [split_output_proto] # Run the C++ program and capture its output result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) @@ -89,6 +83,7 @@ def remove_ansii_color_escapecodes(lines: List[str]) -> List[str]: # then this function throws an error ################################################################################ def rebuild_xml_converter_binary() -> None: + print("Building XML Converter Binary") cmake_build_directory = "../build" # Store the current working directory @@ -112,6 +107,8 @@ def rebuild_xml_converter_binary() -> None: else: print(f"Directory '{cmake_build_directory}' does not exist.") + print() + ################################################################################ # remove_ignored_lines @@ -143,8 +140,9 @@ def remove_ignored_lines(lines: List[str]) -> List[str]: def main() -> bool: - parser = argparse.ArgumentParser(description="A test harness for evaluating the output of the xmlconverter program") - parser.add_argument("-v", "--verbose", help="Prints the results from xmlconverter in JSON format", action="store_true") + parser = argparse.ArgumentParser(description="A test harness for evaluating the output of the xmlconverter program.") + parser.add_argument("-v", "--verbose", help="Prints the results from xmlconverter in JSON format.", action="store_true") + parser.add_argument("--filter", help="Filter which tests to run by a regex pattern.", type=str) args = parser.parse_args() output_parent_dirpath = "./outputs" @@ -157,7 +155,13 @@ def main() -> bool: rebuild_xml_converter_binary() + test_run_count = 0 + for testcase in load_testcases(): + if args.filter is not None: + if not re.match(args.filter, testcase.name): + continue + xml_output_dir_path = os.path.join(output_parent_dirpath, "xml", testcase.name) proto_output_dir_path = os.path.join(output_parent_dirpath, "proto", testcase.name) @@ -207,6 +211,11 @@ def main() -> bool: print(f"Success: test {testcase.name}") all_tests_passed &= testcase_passed + test_run_count += 1 + + if test_run_count == 0: + print("No Tests Were Run") + return False return all_tests_passed @@ -295,9 +304,8 @@ def get_paths(directory: str) -> Tuple[List[str], List[str]]: if __name__ == "__main__": - returncode = main() + all_tests_passed = main() - if returncode: - exit(0) - else: + # Exit with an error if not all the tests passed so we can catch it in CI + if not all_tests_passed: exit(1) From b8bfebabfaa6d81fe50c6beee812dd292ae26834 Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Mon, 5 Feb 2024 11:25:41 -0600 Subject: [PATCH 18/18] Beginning to flesh out the html docs --- xml_converter/doc/map_id/map_id.md | 33 ++++++++++++++++--- xml_converter/generators/main.py | 3 ++ .../web_templates/documentation.html | 17 ++++++++++ .../generators/web_templates/infotable.html | 2 +- xml_converter/requirements.txt | 1 + 5 files changed, 51 insertions(+), 5 deletions(-) diff --git a/xml_converter/doc/map_id/map_id.md b/xml_converter/doc/map_id/map_id.md index b7d6c259..fe64cc21 100644 --- a/xml_converter/doc/map_id/map_id.md +++ b/xml_converter/doc/map_id/map_id.md @@ -5,8 +5,33 @@ applies_to: [Icon, Trail] xml_fields: [MapID] protobuf_field: map_id --- -The ID of the map that this object should be displayed on. +The Map which this marker should be displayed on. -Notes -===== -https://blishhud.com/docs/markers/attributes/mapid +Finding the Map ID +================== +Method 1: GameInfo Plugin +--- +The GameInfo plugin displays some useful game information on your screen about the character. One of those is the map the character is currently on + +Method 2: [Guild Wars 2 Wiki][2] infobox +--- +the InfoBox on the right hand side of map wiki pages has a field titled API followed by a number. + +For example, the [Gendarran Fields][1] wiki page has the API value of `24`. Gendarran Fields' Map ID is `24`. + +![Gendarran Fields InfoBox](./gendarran_fields_infobox.png) + + +Quirks +====== +* Map ID is also stored within the `.trl` files and may overwrite any other Map IDs set earlier in the node. + + +References +========= +* [BlishHUD MapID Marker Docs](https://blishhud.com/docs/markers/attributes/mapid) +* [TacO Marker Pack Guide](https://www.gw2taco.com/2016/01/how-to-create-your-own-marker-pack.html) + + +[1]: https://wiki.guildwars2.com/wiki/Gendarran_Fields +[2]: https://wiki.guildwars2.com \ No newline at end of file diff --git a/xml_converter/generators/main.py b/xml_converter/generators/main.py index 271a45a9..1fdaf1e9 100644 --- a/xml_converter/generators/main.py +++ b/xml_converter/generators/main.py @@ -123,6 +123,9 @@ def delete_generated_docs(self, dir_path: str, skip: List[str] = []) -> None: def load_input_doc(self, dir_path: str) -> None: for filepath in os.listdir(dir_path): + if not filepath.endswith(".md"): + continue + filepath = os.path.join(dir_path, filepath) try: document = frontmatter.load(filepath) diff --git a/xml_converter/generators/web_templates/documentation.html b/xml_converter/generators/web_templates/documentation.html index 8230ca97..db2d6add 100644 --- a/xml_converter/generators/web_templates/documentation.html +++ b/xml_converter/generators/web_templates/documentation.html @@ -30,6 +30,18 @@ border-radius: 3px; margin: 10px 30px; } + code { + display: inline-block; + background: #DDD; + padding: 1px 3px 0px 3px; + border: 1px solid #888; + border-radius: 3px; + } + + .codehilite code { + width: 100%; + box-sizing: border-box; + } table.flagbox { margin-top: -1em; @@ -87,7 +99,12 @@ text-align: center; margin: 10px; } + + .field_wrapper h1 { + border-bottom: 1px solid #777; + } +
Hello world
diff --git a/xml_converter/generators/web_templates/infotable.html b/xml_converter/generators/web_templates/infotable.html index 635e2f28..4063fd4f 100644 --- a/xml_converter/generators/web_templates/infotable.html +++ b/xml_converter/generators/web_templates/infotable.html @@ -43,7 +43,7 @@

Examples

{{field_row.example}}

Valid XML Values

{{field_row.valid_values_html}}
-

Description

{{field_row.description}}
+

Description

{{field_row.description}}
{% endfor %} diff --git a/xml_converter/requirements.txt b/xml_converter/requirements.txt index da2e2c05..30748836 100644 --- a/xml_converter/requirements.txt +++ b/xml_converter/requirements.txt @@ -9,6 +9,7 @@ mypy==1.5.1 pyaml==21.10.1 pycodestyle==2.8.0 pyflakes==2.4.0 +Pygments==2.17.2 pyrsistent==0.18.1 python-frontmatter==1.0.0 PyYAML==5.1