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

Simplifying rgbcolor to a single fixed32 field #312

Merged
merged 1 commit into from
May 27, 2024
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
8 changes: 4 additions & 4 deletions xml_converter/doc/texture/color.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ components:
- name: Red
type: Float32
xml_fields: [Red]
protobuf_field: rgba_color
protobuf_field: null
examples: ["0", "0.25", "0.5", "0.75", "1.0"]

- name: Green
type: Float32
xml_fields: [Green]
protobuf_field: rgba_color
protobuf_field: null
examples: ["0", "0.25", "0.5", "0.75", "1.0"]

- name: Blue
type: Float32
xml_fields: [Blue]
protobuf_field: rgba_color
protobuf_field: null
examples: ["0", "0.25", "0.5", "0.75", "1.0"]

- name: Alpha
type: Float32
xml_fields: [Alpha]
protobuf_field: rgba_color
protobuf_field: null
examples: ["0", "0.25", "0.5", "0.75", "1.0"]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ void proto_to_{{attribute_name}}(
bool* is_set) {
{{class_name}} {{attribute_name}};
{% for attribute_component in attribute_components %}
{{attribute_name}}.{{attribute_component.attribute_name}} = input.{{attribute_component.protobuf_field}}();
{% if attribute_component.protobuf_field != None %}
{{attribute_name}}.{{attribute_component.attribute_name}} = input.{{attribute_component.protobuf_field}}();
{% endif %}
{% endfor %}
*value = {{attribute_name}};
*is_set = true;
Expand All @@ -71,7 +73,9 @@ void {{attribute_name}}_to_proto(
std::function<void({{proto_field_cpp_type}}*)> setter) {
{{proto_field_cpp_type}}* proto_{{attribute_name}} = new {{proto_field_cpp_type}}();
{% for attribute_component in attribute_components %}
proto_{{attribute_name}}->set_{{attribute_component.protobuf_field}}(value.{{attribute_component.attribute_name}});
{% if attribute_component.protobuf_field != None %}
proto_{{attribute_name}}->set_{{attribute_component.protobuf_field}}(value.{{attribute_component.attribute_name}});
{% endif %}
{% endfor %}
setter(proto_{{attribute_name}});
}
14 changes: 10 additions & 4 deletions xml_converter/generators/generate_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class AttributeVariable:
class AttributeComponent:
attribute_name: str
cpp_type: str
protobuf_field: str
protobuf_field: Optional[str]
xml_fields: List[str]


Expand Down Expand Up @@ -337,13 +337,13 @@ def generate_cpp_variable_data(

proto_info=AttributeVariableProtoInfo(
protobuf_field=component.protobuf_field,
protobuf_cpp_type=get_proto_field_cpp_type(doc_type, fieldval.protobuf_field + "." + component.protobuf_field),
is_proto_field_scalar=is_proto_field_scalar(doc_type, fieldval.protobuf_field + "." + component.protobuf_field),
protobuf_cpp_type=get_proto_field_cpp_type(doc_type, combine_fields(fieldval.protobuf_field, component.protobuf_field)),
is_proto_field_scalar=is_proto_field_scalar(doc_type, combine_fields(fieldval.protobuf_field, component.protobuf_field)),
serialize_proto_function="to_proto_" + component_class_name,
serialize_proto_side_effects=[],
deserialize_proto_function="from_proto_" + component_class_name,
deserialize_proto_side_effects=[],
) if fieldval.protobuf_field is not None else None,
) if fieldval.protobuf_field is not None and component.protobuf_field is not None else None,

xml_info=AttributeVariableXMLInfo(
xml_fields=component_xml_fields,
Expand Down Expand Up @@ -591,6 +591,12 @@ def write_attribute(output_directory: str, data: Dict[str, Document]) -> List[st
return files_written


def combine_fields(base_field: str, sub_field: Optional[str]) -> str:
if sub_field is None:
return base_field
return base_field + "." + sub_field


################################################################################
# write_if_different
#
Expand Down
4 changes: 3 additions & 1 deletion xml_converter/generators/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ def generate_auto_docs(self, metadata: Dict[str, MetadataType], content: Dict[st
if fieldval.variable_type == "CompoundValue" or fieldval.variable_type == "CompoundCustomClass":
for component_field in fieldval.components:

if fieldval.protobuf_field is not None:
if fieldval.protobuf_field is not None and component_field.protobuf_field is not None:
binary_field_name = fieldval.protobuf_field + "." + component_field.protobuf_field
elif fieldval.protobuf_field is not None:
binary_field_name = fieldval.protobuf_field
else:
binary_field_name = ""

Expand Down
2 changes: 1 addition & 1 deletion xml_converter/generators/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class CompoundSubComponent:
name: str
subcomponent_type: SubcomponentType = field(metadata={"json": "type"})
xml_fields: List[str]
protobuf_field: str
protobuf_field: Optional[str]
examples: List[str] = field(default_factory=list)


Expand Down
2 changes: 1 addition & 1 deletion xml_converter/generators/protobuf_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def get_proto_field_type(message: str, field: str) -> str:
"uint64": "unsigned long",
"sint32": "int",
"sint64": "long",
"fixed32": "int",
"fixed32": "uint32_t",
"fixed64": "long",
"sfixed32": "int",
"sfixed64": "long",
Expand Down
9 changes: 2 additions & 7 deletions xml_converter/proto/waypoint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ message Icon {
bool scale_on_map_with_zoom = 23;
string tip_description = 24;
string tip_name = 25;
RGBAColor rgba_color = 26;
fixed32 rgba_color = 26;
FestivalFilter festival_filter = 27;
MapTypeFilter map_type_filter = 28;
MountFilter mount_filter = 29;
Expand Down Expand Up @@ -75,11 +75,10 @@ message Trail {

int32 achievement_id = 16;
int32 achievement_bit_index = 17;

bool disable_player_cutout = 19;
bool is_wall = 20;
float scale = 21;
RGBAColor rgba_color = 22;
fixed32 rgba_color = 22;
FestivalFilter festival_filter = 23;
MapTypeFilter map_type_filter = 24;
MountFilter mount_filter = 25;
Expand All @@ -96,10 +95,6 @@ message Trail {
float bhdraft__schedule_duration = 2053;
}

message RGBAColor {
int32 rgba_color = 1;
}

message Position {
float x = 1;
float y = 2;
Expand Down
17 changes: 7 additions & 10 deletions xml_converter/src/attribute/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,17 @@ string color_to_xml_attribute(
// Parses a Color from a proto field.
////////////////////////////////////////////////////////////////////////////////
void proto_to_color(
waypoint::RGBAColor input,
uint32_t input,
ProtoReaderState*,
Color* value,
bool* is_set) {
Color color;
std::stringstream stream;
uint32_t rgba = input.rgba_color();

color.red = convert_color_channel_int_to_float((rgba >> 24) & 0xff);
color.green = convert_color_channel_int_to_float((rgba >> 16) & 0xff);
color.blue = convert_color_channel_int_to_float((rgba >> 8) & 0xff);
color.alpha = convert_color_channel_int_to_float(rgba & 0xff);
color.red = convert_color_channel_int_to_float((input >> 24) & 0xff);
color.green = convert_color_channel_int_to_float((input >> 16) & 0xff);
color.blue = convert_color_channel_int_to_float((input >> 8) & 0xff);
color.alpha = convert_color_channel_int_to_float(input & 0xff);

*value = color;
*is_set = true;
Expand All @@ -148,8 +147,7 @@ void proto_to_color(
void color_to_proto(
Color value,
ProtoWriterState*,
std::function<void(waypoint::RGBAColor*)> setter) {
waypoint::RGBAColor* color = new waypoint::RGBAColor();
std::function<void(uint32_t)> setter) {
// The default RGB in burrito will be 000000 (i.e. black)
// Default value of alpha in Burrito is 1.0 (i.e. 255)
int int_alpha = 255;
Expand All @@ -164,6 +162,5 @@ void color_to_proto(
uint32_t a = (int_alpha & 0xff);
uint32_t rgba = r | g | b | a;

color->set_rgba_color(rgba);
setter(color);
setter(rgba);
}
4 changes: 2 additions & 2 deletions xml_converter/src/attribute/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ std::string color_to_xml_attribute(
const Color* value);

void proto_to_color(
waypoint::RGBAColor input,
uint32_t input,
ProtoReaderState* state,
Color* value,
bool* is_set);

void color_to_proto(
Color value,
ProtoWriterState* state,
std::function<void(waypoint::RGBAColor*)> setter);
std::function<void(uint32_t)> setter);
4 changes: 2 additions & 2 deletions xml_converter/src/icon_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ waypoint::Icon Icon::as_protobuf(ProtoWriterState* state) const {
float_to_proto(this->bounce_height, state, setter);
}
if (this->color_is_set) {
std::function<void(waypoint::RGBAColor*)> setter = [&proto_icon](waypoint::RGBAColor* val) { proto_icon.set_allocated_rgba_color(val); };
std::function<void(uint32_t)> setter = [&proto_icon](uint32_t val) { proto_icon.set_rgba_color(val); };
color_to_proto(this->color, state, setter);
}
if (this->copy_clipboard_is_set) {
Expand Down Expand Up @@ -617,7 +617,7 @@ void Icon::parse_protobuf(waypoint::Icon proto_icon, ProtoReaderState* state) {
if (proto_icon.trigger().bounce_height() != 0) {
proto_to_float(proto_icon.trigger().bounce_height(), state, &(this->bounce_height), &(this->bounce_height_is_set));
}
if (proto_icon.has_rgba_color()) {
if (proto_icon.rgba_color() != 0) {
proto_to_color(proto_icon.rgba_color(), state, &(this->color), &(this->color_is_set));
}
if (proto_icon.trigger().action_copy_clipboard() != "") {
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 @@ -262,7 +262,7 @@ waypoint::Trail Trail::as_protobuf(ProtoWriterState* state) const {
float_to_proto(this->animation_speed, state, setter);
}
if (this->color_is_set) {
std::function<void(waypoint::RGBAColor*)> setter = [&proto_trail](waypoint::RGBAColor* val) { proto_trail.set_allocated_rgba_color(val); };
std::function<void(uint32_t)> setter = [&proto_trail](uint32_t val) { proto_trail.set_rgba_color(val); };
color_to_proto(this->color, state, setter);
}
if (this->cull_chirality_is_set) {
Expand Down Expand Up @@ -366,7 +366,7 @@ void Trail::parse_protobuf(waypoint::Trail proto_trail, ProtoReaderState* state)
if (proto_trail.animation_speed() != 0) {
proto_to_float(proto_trail.animation_speed(), state, &(this->animation_speed), &(this->animation_speed_is_set));
}
if (proto_trail.has_rgba_color()) {
if (proto_trail.rgba_color() != 0) {
proto_to_color(proto_trail.rgba_color(), state, &(this->color), &(this->color_is_set));
}
if (proto_trail.cull_chirality() != 0) {
Expand Down
Loading