From 75bf1e1b5f57f3fe1a907b890bc73bfd0324052d Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Mon, 9 Oct 2023 04:15:28 -0500 Subject: [PATCH 1/4] Converting GUID to be a scalar string value in protobuf --- xml_converter/doc/trigger/guid.md | 1 + xml_converter/generators/code_generator.py | 10 ++++++++++ .../generators/cpp_templates/class_template.cpp | 8 ++++---- xml_converter/proto/waypoint.proto | 8 ++------ xml_converter/src/attribute/unique_id.cpp | 12 ++++-------- xml_converter/src/attribute/unique_id.hpp | 4 ++-- xml_converter/src/icon_gen.cpp | 4 ++-- xml_converter/src/trail_gen.cpp | 4 ++-- 8 files changed, 27 insertions(+), 24 deletions(-) diff --git a/xml_converter/doc/trigger/guid.md b/xml_converter/doc/trigger/guid.md index ad4a8094..13f5e881 100644 --- a/xml_converter/doc/trigger/guid.md +++ b/xml_converter/doc/trigger/guid.md @@ -5,6 +5,7 @@ class: UniqueId xml_fields: ["GUID"] applies_to: ["Icon", "Trail"] protobuf_field: guid +ptotobuf_type: "String" --- A globally unique identifier value to make sure this maker's trigger reset data is always assocaited with this marker and never lost or confused with other markers. diff --git a/xml_converter/generators/code_generator.py b/xml_converter/generators/code_generator.py index 0c814949..1922da6f 100644 --- a/xml_converter/generators/code_generator.py +++ b/xml_converter/generators/code_generator.py @@ -70,6 +70,7 @@ optional={ "side_effects": array_t(string_t()), "uses_file_path": boolean_t(), + "ptotobuf_type": enum_t(["Int32", "Fixed32", "Float32", "String"]), } ), }) @@ -167,6 +168,9 @@ class AttributeVariable: uses_file_path: bool = False is_component: bool = False + # A flag to override the type that should be used when writing or reading from a protobuf + ptotobuf_type: Optional[str] = None + XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS: Final[List[str]] = ["attribute", "errors"] @@ -413,6 +417,11 @@ def generate_cpp_variable_data( if fieldval['xml_bundled_components'] == []: write_to_xml = False + ptotobuf_type = None + if "ptotobuf_type" in fieldval: + ptotobuf_type = fieldval["ptotobuf_type"] + + attribute_variable = AttributeVariable( attribute_name=attribute_name, attribute_type=fieldval["type"], @@ -427,6 +436,7 @@ def generate_cpp_variable_data( write_to_xml=write_to_xml, attribute_flag_name=attribute_name + "_is_set", side_effects=side_effects, + ptotobuf_type=ptotobuf_type ) attribute_variables.append(attribute_variable) diff --git a/xml_converter/generators/cpp_templates/class_template.cpp b/xml_converter/generators/cpp_templates/class_template.cpp index 1c01c3ed..8c98652c 100644 --- a/xml_converter/generators/cpp_templates/class_template.cpp +++ b/xml_converter/generators/cpp_templates/class_template.cpp @@ -98,7 +98,7 @@ waypoint::{{cpp_class}} {{cpp_class}}::as_protobuf() const { {% for attribute_variable in attribute_variables %} {% if attribute_variable.is_component == false %} if (this->{{attribute_variable.attribute_flag_name}}) { - {% if (attribute_variable.attribute_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"]) %} + {% if (attribute_variable.ptotobuf_type or attribute_variable.attribute_type) in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"] %} proto_{{cpp_class_header}}.{{attribute_variable.mutable_proto_drilldown_calls}}set_allocated_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); {% else %} proto_{{cpp_class_header}}.{{attribute_variable.mutable_proto_drilldown_calls}}set_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); @@ -112,11 +112,11 @@ waypoint::{{cpp_class}} {{cpp_class}}::as_protobuf() const { void {{cpp_class}}::parse_protobuf(waypoint::{{cpp_class}} proto_{{cpp_class_header}}) { {% for attribute_variable in attribute_variables %} {% if attribute_variable.is_component == false %} - {% if (attribute_variable.attribute_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"]) %} + {% if (attribute_variable.ptotobuf_type or attribute_variable.attribute_type) in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"] %} if (proto_{{cpp_class_header}}{{attribute_variable.proto_drilldown_calls}}.has_{{attribute_variable.protobuf_field}}()) { - {% elif (attribute_variable.attribute_type == "String") %} + {% elif (attribute_variable.ptotobuf_type or attribute_variable.attribute_type) == "String" %} if (proto_{{cpp_class_header}}{{attribute_variable.proto_drilldown_calls}}.{{attribute_variable.protobuf_field}}() != "") { - {% elif (attribute_variable.attribute_type == "Enum") %} + {% elif (attribute_variable.ptotobuf_type or attribute_variable.attribute_type) == "Enum" %} if (proto_{{cpp_class_header}}{{attribute_variable.proto_drilldown_calls}}.{{attribute_variable.protobuf_field}}() != 0) { {% else %} if (proto_{{cpp_class_header}}{{attribute_variable.proto_drilldown_calls}}.{{attribute_variable.protobuf_field}}() != 0) { diff --git a/xml_converter/proto/waypoint.proto b/xml_converter/proto/waypoint.proto index ab239d57..bfc2f74f 100644 --- a/xml_converter/proto/waypoint.proto +++ b/xml_converter/proto/waypoint.proto @@ -19,7 +19,7 @@ message Category { message Icon { TexturePath texture_path = 2; - GUID guid = 3; + bytes guid = 3; int32 map_id = 4; float distance_fade_end = 5; float distance_fade_start = 6; @@ -57,7 +57,7 @@ message Icon { message Trail { TexturePath texture_path = 2; - GUID guid = 3; + bytes guid = 3; int32 map_id = 4; float distance_fade_end = 5; float distance_fade_start = 6; @@ -125,10 +125,6 @@ message Trigger { ResetBehavior reset_behavior = 15; } -message GUID { - bytes guid = 1; -} - enum CullChirality { none = 0; clockwise = 1; diff --git a/xml_converter/src/attribute/unique_id.cpp b/xml_converter/src/attribute/unique_id.cpp index 5de78428..abad77ec 100644 --- a/xml_converter/src/attribute/unique_id.cpp +++ b/xml_converter/src/attribute/unique_id.cpp @@ -25,17 +25,13 @@ string stringify_unique_id(UniqueId attribute_value) { return base64_encode(&attribute_value.guid[0], attribute_value.guid.size()); } -waypoint::GUID* to_proto_unique_id(UniqueId attribute_value) { - waypoint::GUID* guid = new waypoint::GUID(); - std::string s(attribute_value.guid.begin(), attribute_value.guid.end()); - guid->set_guid(s); - return guid; +string to_proto_unique_id(UniqueId attribute_value) { + return std::string(attribute_value.guid.begin(), attribute_value.guid.end()); } -UniqueId from_proto_unique_id(waypoint::GUID attribute_value) { +UniqueId from_proto_unique_id(string attribute_value) { UniqueId unique_id; - string s = attribute_value.guid(); - std::vector guid(s.begin(), s.end()); + std::vector guid(attribute_value.begin(), attribute_value.end()); unique_id.guid = guid; return unique_id; } diff --git a/xml_converter/src/attribute/unique_id.hpp b/xml_converter/src/attribute/unique_id.hpp index 44755836..59853469 100644 --- a/xml_converter/src/attribute/unique_id.hpp +++ b/xml_converter/src/attribute/unique_id.hpp @@ -20,6 +20,6 @@ UniqueId parse_unique_id(rapidxml::xml_attribute<>* input, std::vectorfestival_filter)); } if (this->guid_is_set) { - proto_icon.set_allocated_guid(to_proto_unique_id(this->guid)); + proto_icon.set_guid(to_proto_unique_id(this->guid)); } if (this->has_countdown_is_set) { proto_icon.mutable_trigger()->set_has_countdown(to_proto_bool(this->has_countdown)); @@ -689,7 +689,7 @@ void Icon::parse_protobuf(waypoint::Icon proto_icon) { this->festival_filter = from_proto_festival_filter(proto_icon.festival_filter()); this->festival_filter_is_set = true; } - if (proto_icon.has_guid()) { + if (proto_icon.guid() != "") { this->guid = from_proto_unique_id(proto_icon.guid()); this->guid_is_set = true; } diff --git a/xml_converter/src/trail_gen.cpp b/xml_converter/src/trail_gen.cpp index 2d6210e7..26881f17 100644 --- a/xml_converter/src/trail_gen.cpp +++ b/xml_converter/src/trail_gen.cpp @@ -319,7 +319,7 @@ waypoint::Trail Trail::as_protobuf() const { proto_trail.set_allocated_festival_filter(to_proto_festival_filter(this->festival_filter)); } if (this->guid_is_set) { - proto_trail.set_allocated_guid(to_proto_unique_id(this->guid)); + proto_trail.set_guid(to_proto_unique_id(this->guid)); } if (this->is_wall_is_set) { proto_trail.set_is_wall(to_proto_bool(this->is_wall)); @@ -413,7 +413,7 @@ void Trail::parse_protobuf(waypoint::Trail proto_trail) { this->festival_filter = from_proto_festival_filter(proto_trail.festival_filter()); this->festival_filter_is_set = true; } - if (proto_trail.has_guid()) { + if (proto_trail.guid() != "") { this->guid = from_proto_unique_id(proto_trail.guid()); this->guid_is_set = true; } From 5b72f6247cee6d637092d73824847a3dfc182a1b Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Mon, 9 Oct 2023 04:18:52 -0500 Subject: [PATCH 2/4] removing extra line warning from python linter --- xml_converter/generators/code_generator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xml_converter/generators/code_generator.py b/xml_converter/generators/code_generator.py index 1922da6f..6f60cf58 100644 --- a/xml_converter/generators/code_generator.py +++ b/xml_converter/generators/code_generator.py @@ -421,7 +421,6 @@ def generate_cpp_variable_data( if "ptotobuf_type" in fieldval: ptotobuf_type = fieldval["ptotobuf_type"] - attribute_variable = AttributeVariable( attribute_name=attribute_name, attribute_type=fieldval["type"], From 7e8cd83f7620910e684062ff016fa1b0494739bc Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Mon, 9 Oct 2023 04:42:29 -0500 Subject: [PATCH 3/4] simplifying genrator code with sane default value setting --- xml_converter/generators/code_generator.py | 8 ++++++-- xml_converter/generators/cpp_templates/class_template.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/xml_converter/generators/code_generator.py b/xml_converter/generators/code_generator.py index 6f60cf58..7d2235b3 100644 --- a/xml_converter/generators/code_generator.py +++ b/xml_converter/generators/code_generator.py @@ -169,7 +169,11 @@ class AttributeVariable: is_component: bool = False # A flag to override the type that should be used when writing or reading from a protobuf - ptotobuf_type: Optional[str] = None + ptotobuf_type: str = "" + + def __post_init__(self) -> None: + if self.ptotobuf_type == "": + self.ptotobuf_type = self.attribute_type XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS: Final[List[str]] = ["attribute", "errors"] @@ -417,7 +421,7 @@ def generate_cpp_variable_data( if fieldval['xml_bundled_components'] == []: write_to_xml = False - ptotobuf_type = None + ptotobuf_type = "" if "ptotobuf_type" in fieldval: ptotobuf_type = fieldval["ptotobuf_type"] diff --git a/xml_converter/generators/cpp_templates/class_template.cpp b/xml_converter/generators/cpp_templates/class_template.cpp index 8c98652c..3009e8ab 100644 --- a/xml_converter/generators/cpp_templates/class_template.cpp +++ b/xml_converter/generators/cpp_templates/class_template.cpp @@ -98,7 +98,7 @@ waypoint::{{cpp_class}} {{cpp_class}}::as_protobuf() const { {% for attribute_variable in attribute_variables %} {% if attribute_variable.is_component == false %} if (this->{{attribute_variable.attribute_flag_name}}) { - {% if (attribute_variable.ptotobuf_type or attribute_variable.attribute_type) in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"] %} + {% if attribute_variable.ptotobuf_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"] %} proto_{{cpp_class_header}}.{{attribute_variable.mutable_proto_drilldown_calls}}set_allocated_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); {% else %} proto_{{cpp_class_header}}.{{attribute_variable.mutable_proto_drilldown_calls}}set_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); @@ -112,11 +112,11 @@ waypoint::{{cpp_class}} {{cpp_class}}::as_protobuf() const { void {{cpp_class}}::parse_protobuf(waypoint::{{cpp_class}} proto_{{cpp_class_header}}) { {% for attribute_variable in attribute_variables %} {% if attribute_variable.is_component == false %} - {% if (attribute_variable.ptotobuf_type or attribute_variable.attribute_type) in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"] %} + {% if attribute_variable.ptotobuf_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"] %} if (proto_{{cpp_class_header}}{{attribute_variable.proto_drilldown_calls}}.has_{{attribute_variable.protobuf_field}}()) { - {% elif (attribute_variable.ptotobuf_type or attribute_variable.attribute_type) == "String" %} + {% elif attribute_variable.ptotobuf_type == "String" %} if (proto_{{cpp_class_header}}{{attribute_variable.proto_drilldown_calls}}.{{attribute_variable.protobuf_field}}() != "") { - {% elif (attribute_variable.ptotobuf_type or attribute_variable.attribute_type) == "Enum" %} + {% elif attribute_variable.ptotobuf_type == "Enum" %} if (proto_{{cpp_class_header}}{{attribute_variable.proto_drilldown_calls}}.{{attribute_variable.protobuf_field}}() != 0) { {% else %} if (proto_{{cpp_class_header}}{{attribute_variable.proto_drilldown_calls}}.{{attribute_variable.protobuf_field}}() != 0) { From 0ceba3d397e6aeb7a39011b27258dcaffcd1d7cb Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Mon, 9 Oct 2023 04:43:40 -0500 Subject: [PATCH 4/4] fixing a typo --- xml_converter/doc/trigger/guid.md | 2 +- xml_converter/generators/code_generator.py | 16 ++++++++-------- .../generators/cpp_templates/class_template.cpp | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/xml_converter/doc/trigger/guid.md b/xml_converter/doc/trigger/guid.md index 13f5e881..a25d39f7 100644 --- a/xml_converter/doc/trigger/guid.md +++ b/xml_converter/doc/trigger/guid.md @@ -5,7 +5,7 @@ class: UniqueId xml_fields: ["GUID"] applies_to: ["Icon", "Trail"] protobuf_field: guid -ptotobuf_type: "String" +protobuf_type: String --- A globally unique identifier value to make sure this maker's trigger reset data is always assocaited with this marker and never lost or confused with other markers. diff --git a/xml_converter/generators/code_generator.py b/xml_converter/generators/code_generator.py index 7d2235b3..1e3cc815 100644 --- a/xml_converter/generators/code_generator.py +++ b/xml_converter/generators/code_generator.py @@ -70,7 +70,7 @@ optional={ "side_effects": array_t(string_t()), "uses_file_path": boolean_t(), - "ptotobuf_type": enum_t(["Int32", "Fixed32", "Float32", "String"]), + "protobuf_type": enum_t(["Int32", "Fixed32", "Float32", "String"]), } ), }) @@ -169,11 +169,11 @@ class AttributeVariable: is_component: bool = False # A flag to override the type that should be used when writing or reading from a protobuf - ptotobuf_type: str = "" + protobuf_type: str = "" def __post_init__(self) -> None: - if self.ptotobuf_type == "": - self.ptotobuf_type = self.attribute_type + if self.protobuf_type == "": + self.protobuf_type = self.attribute_type XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS: Final[List[str]] = ["attribute", "errors"] @@ -421,9 +421,9 @@ def generate_cpp_variable_data( if fieldval['xml_bundled_components'] == []: write_to_xml = False - ptotobuf_type = "" - if "ptotobuf_type" in fieldval: - ptotobuf_type = fieldval["ptotobuf_type"] + protobuf_type = "" + if "protobuf_type" in fieldval: + protobuf_type = fieldval["protobuf_type"] attribute_variable = AttributeVariable( attribute_name=attribute_name, @@ -439,7 +439,7 @@ def generate_cpp_variable_data( write_to_xml=write_to_xml, attribute_flag_name=attribute_name + "_is_set", side_effects=side_effects, - ptotobuf_type=ptotobuf_type + protobuf_type=protobuf_type ) attribute_variables.append(attribute_variable) diff --git a/xml_converter/generators/cpp_templates/class_template.cpp b/xml_converter/generators/cpp_templates/class_template.cpp index 3009e8ab..c2081d8a 100644 --- a/xml_converter/generators/cpp_templates/class_template.cpp +++ b/xml_converter/generators/cpp_templates/class_template.cpp @@ -98,7 +98,7 @@ waypoint::{{cpp_class}} {{cpp_class}}::as_protobuf() const { {% for attribute_variable in attribute_variables %} {% if attribute_variable.is_component == false %} if (this->{{attribute_variable.attribute_flag_name}}) { - {% if attribute_variable.ptotobuf_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"] %} + {% if attribute_variable.protobuf_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"] %} proto_{{cpp_class_header}}.{{attribute_variable.mutable_proto_drilldown_calls}}set_allocated_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); {% else %} proto_{{cpp_class_header}}.{{attribute_variable.mutable_proto_drilldown_calls}}set_{{attribute_variable.protobuf_field}}(to_proto_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}})); @@ -112,11 +112,11 @@ waypoint::{{cpp_class}} {{cpp_class}}::as_protobuf() const { void {{cpp_class}}::parse_protobuf(waypoint::{{cpp_class}} proto_{{cpp_class_header}}) { {% for attribute_variable in attribute_variables %} {% if attribute_variable.is_component == false %} - {% if attribute_variable.ptotobuf_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"] %} + {% if attribute_variable.protobuf_type in ["MultiflagValue", "CompoundValue", "Custom", "CompoundCustomClass"] %} if (proto_{{cpp_class_header}}{{attribute_variable.proto_drilldown_calls}}.has_{{attribute_variable.protobuf_field}}()) { - {% elif attribute_variable.ptotobuf_type == "String" %} + {% elif attribute_variable.protobuf_type == "String" %} if (proto_{{cpp_class_header}}{{attribute_variable.proto_drilldown_calls}}.{{attribute_variable.protobuf_field}}() != "") { - {% elif attribute_variable.ptotobuf_type == "Enum" %} + {% elif attribute_variable.protobuf_type == "Enum" %} if (proto_{{cpp_class_header}}{{attribute_variable.proto_drilldown_calls}}.{{attribute_variable.protobuf_field}}() != 0) { {% else %} if (proto_{{cpp_class_header}}{{attribute_variable.proto_drilldown_calls}}.{{attribute_variable.protobuf_field}}() != 0) {