Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting GUID to be a scalar string value in protobuf #179

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions xml_converter/doc/trigger/guid.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class: UniqueId
xml_fields: ["GUID"]
applies_to: ["Icon", "Trail"]
protobuf_field: guid
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.

Expand Down
13 changes: 13 additions & 0 deletions xml_converter/generators/code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
optional={
"side_effects": array_t(string_t()),
"uses_file_path": boolean_t(),
"protobuf_type": enum_t(["Int32", "Fixed32", "Float32", "String"]),
}
),
})
Expand Down Expand Up @@ -167,6 +168,13 @@ 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
protobuf_type: str = ""

def __post_init__(self) -> None:
if self.protobuf_type == "":
self.protobuf_type = self.attribute_type


XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS: Final[List[str]] = ["attribute", "errors"]

Expand Down Expand Up @@ -413,6 +421,10 @@ def generate_cpp_variable_data(
if fieldval['xml_bundled_components'] == []:
write_to_xml = False

protobuf_type = ""
if "protobuf_type" in fieldval:
protobuf_type = fieldval["protobuf_type"]

attribute_variable = AttributeVariable(
attribute_name=attribute_name,
attribute_type=fieldval["type"],
Expand All @@ -427,6 +439,7 @@ def generate_cpp_variable_data(
write_to_xml=write_to_xml,
attribute_flag_name=attribute_name + "_is_set",
side_effects=side_effects,
protobuf_type=protobuf_type
)
attribute_variables.append(attribute_variable)

Expand Down
8 changes: 4 additions & 4 deletions xml_converter/generators/cpp_templates/class_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.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}}));
Expand All @@ -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.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.attribute_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.attribute_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) {
Expand Down
8 changes: 2 additions & 6 deletions xml_converter/proto/waypoint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -125,10 +125,6 @@ message Trigger {
ResetBehavior reset_behavior = 15;
}

message GUID {
bytes guid = 1;
}

enum CullChirality {
none = 0;
clockwise = 1;
Expand Down
12 changes: 4 additions & 8 deletions xml_converter/src/attribute/unique_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> guid(s.begin(), s.end());
std::vector<uint8_t> guid(attribute_value.begin(), attribute_value.end());
unique_id.guid = guid;
return unique_id;
}
4 changes: 2 additions & 2 deletions xml_converter/src/attribute/unique_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ UniqueId parse_unique_id(rapidxml::xml_attribute<>* input, std::vector<XMLError*

std::string stringify_unique_id(UniqueId attribute_value);

waypoint::GUID* to_proto_unique_id(UniqueId attribute_value);
std::string to_proto_unique_id(UniqueId attribute_value);

UniqueId from_proto_unique_id(waypoint::GUID attribute_value);
UniqueId from_proto_unique_id(std::string attribute_value);
4 changes: 2 additions & 2 deletions xml_converter/src/icon_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ waypoint::Icon Icon::as_protobuf() const {
proto_icon.set_allocated_festival_filter(to_proto_festival_filter(this->festival_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));
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions xml_converter/src/trail_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down