Skip to content

Commit

Permalink
Merge pull request #140 from klingbolt/color_work_3
Browse files Browse the repository at this point in the history
Color Rework Rebased
  • Loading branch information
AsherGlick authored Jul 8, 2023
2 parents 4d460a2 + b7b0b6a commit ad3bffe
Show file tree
Hide file tree
Showing 14 changed files with 445 additions and 271 deletions.
41 changes: 19 additions & 22 deletions xml_converter/doc/position/position.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,26 @@ applies_to: ["Icon"]
xml_fields: ["Position"]
compatability: [TacO, Burrito, BlishHUD]
protobuf_field: position
xml_bundled_components: []
xml_separate_components: ["X Position", "Y Position", "Z Position"]
components:

- name: X Position
type: Float32
xml_fields: [XPos, PositionX]
protobuf_field: "x"
compatability: [TacO, Burrito, BlishHUD]


- name: Y Position
type: Float32
xml_fields: [YPos, PositionY]
protobuf_field: "y"
compatability: [TacO, Burrito, BlishHUD]


- name: Z Position
type: Float32
xml_fields: [ZPos, PositionZ]
protobuf_field: "z"
compatability: [TacO, Burrito, BlishHUD]

xml_export: "Children"
- name: X Position
type: Float32
xml_fields: [XPos, PositionX]
protobuf_field: "x"
compatability: [TacO, Burrito, BlishHUD]

- name: Y Position
type: Float32
xml_fields: [YPos, PositionY]
protobuf_field: "y"
compatability: [TacO, Burrito, BlishHUD]

- name: Z Position
type: Float32
xml_fields: [ZPos, PositionZ]
protobuf_field: "z"
compatability: [TacO, Burrito, BlishHUD]
---
An XYZ location of a point in the game world.

Expand Down
7 changes: 3 additions & 4 deletions xml_converter/doc/rotation/euler_rotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,27 @@ applies_to: ["Icon"]
xml_fields: ["Rotate"]
compatability: [TacO, Burrito, BlishHUD]
protobuf_field: euler_rotation
xml_bundled_components: ['X Rotation', 'Y Rotation', 'Z Rotation']
xml_separate_components: []
components:
- name: X Rotation
type: Float32
xml_fields: [RotateX]
protobuf_field: "x"
compatability: [TacO, Burrito, BlishHUD]


- name: Y Rotation
type: Float32
xml_fields: [RotateY]
protobuf_field: "y"
compatability: [TacO, Burrito, BlishHUD]


- name: Z Rotation
type: Float32
xml_fields: [RotateZ]
protobuf_field: "z"
compatability: [TacO, Burrito, BlishHUD]

xml_export: "Parent"

---
Euler X Y Z rotation.

Expand Down
30 changes: 29 additions & 1 deletion xml_converter/doc/texture/color.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
---
name: Color
type: Custom
type: CompoundCustomClass
class: Color
applies_to: [Icon, Trail]
xml_fields: [Color, BHColor]
protobuf_field: rgba_color
compatability: [TacO, BlishHUD, Burrito]
xml_bundled_components: ['Red', 'Green', 'Blue']
xml_separate_components: ['Alpha']
components:
- name: Red
type: Float32
xml_fields: [Red]
protobuf_field: rgba_color
compatability: [TacO, Burrito, BlishHUD]

- name: Green
type: Float32
xml_fields: [Green]
protobuf_field: rgba_color
compatability: [TacO, Burrito, BlishHUD]

- name: Blue
type: Float32
xml_fields: [Blue]
protobuf_field: rgba_color
compatability: [TacO, Burrito, BlishHUD]

- name: Alpha
type: Float32
xml_fields: [Alpha]
protobuf_field: rgba_color
compatability: [TacO, Burrito, BlishHUD]


---
A multiplier color to tint the raw albedo texture of a marker of trail texture. (Unclear) Solid white will result in no change, solid black will result in a black texture.

Expand Down
154 changes: 106 additions & 48 deletions xml_converter/generators/code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
properties:
type:
type: string
enum: [Int32, Fixed32, Float32, String, Boolean, MultiflagValue, Enum, CompoundValue, Custom]
enum: [Int32, Fixed32, Float32, String, Boolean, MultiflagValue, Enum, CompoundValue, Custom, CompoundCustomClass]
allOf:
#############################
# Int32 Type
Expand Down Expand Up @@ -131,15 +131,64 @@
const: CompoundValue
then:
additionalProperties: false
required: [{shared_fields}, xml_export, components]
required: [{shared_fields}, xml_bundled_components, xml_separate_components, components]
properties:
{shared_field_properties}
xml_export:
xml_bundled_components:
type: array
items:
type: string
xml_separate_components:
type: array
items:
type: string
components:
type: array
items:
type: object
additionalProperties: false
required: [name, type, xml_fields, protobuf_field, compatability]
properties:
name:
type: string
type:
type: string
enum: [Int32, Fixed32, Float32]
xml_fields:
type: array
items:
type: string
pattern: "^[A-Za-z]+$"
protobuf_field:
type: string
pattern: "^[a-z_.]+$"
compatability:
type: array
items:
type: string
enum: [BlishHUD, Burrito, TacO]
#############################
# CompoundCustomClass Type
#############################
- if:
properties:
type:
const: CompoundCustomClass
then:
additionalProperties: false
required: [{shared_fields}, xml_bundled_components, xml_separate_components, class]
properties:
{shared_field_properties}
class:
type: string
enum:
- Parent
- Parent and Children
- Children
xml_bundled_components:
type: array
items:
type: string
xml_separate_components:
type: array
items:
type: string
components:
type: array
items:
Expand All @@ -166,7 +215,6 @@
type: string
enum: [BlishHUD, Burrito, TacO]
#############################
# Custom Type
#############################
Expand Down Expand Up @@ -289,12 +337,14 @@ class AttributeVariable:
xml_fields: List[str]
protobuf_field: str
args: List[str] = field(default_factory=list)
default_xml_fields: List[str] = field(default_factory=list)
xml_export: str = ""
default_xml_field: str = ""
side_effects: List[str] = field(default_factory=list)
compound_name: Optional[str] = None
xml_bundled_components: List[str] = field(default_factory=list)
attribute_flag_name: Optional[str] = ""
write_to_xml: bool = True
is_trigger: bool = False
uses_file_path: bool = False
is_component: bool = False


XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS: Final[List[str]] = ["attribute", "errors"]
Expand Down Expand Up @@ -433,16 +483,9 @@ def generate_cpp_variable_data(
doc_type: str,
) -> Tuple[List[AttributeVariable], CPPInclude]:

cpp_includes: CPPInclude = CPPInclude()
attribute_name: str = ""
# Type defining the outputs
attribute_variables: List[AttributeVariable] = []
xml_fields: List[str] = []
default_xml_fields: List[str] = []
side_effects: List[str] = []
xml_export: str = ""
args: List[str] = []
protobuf_field: str = ""
is_trigger: bool = False
cpp_includes: CPPInclude = CPPInclude()

cpp_includes.hpp_absolute_includes.add("string")
cpp_includes.hpp_absolute_includes.add("vector")
Expand All @@ -467,21 +510,24 @@ def generate_cpp_variable_data(

for filepath, document in sorted(self.data.items()):
fieldval = document.metadata
attribute_name = attribute_name_from_markdown_data(fieldval['name'])
attribute_name: str = attribute_name_from_markdown_data(fieldval['name'])

if doc_type in fieldval['applies_to']:
xml_fields = []
default_xml_fields = []
side_effects = []
xml_export = ""
args = XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS.copy()
xml_fields: List[str] = []
side_effects: List[str] = []
write_to_xml: bool = True
protobuf_field: str = ""
is_trigger: bool = False
default_xml_field: str = ""

args: List[str] = XML_ATTRIBUTE_PARSER_DEFAULT_ARGUMENTS.copy()

if fieldval['type'] in documentation_type_data:
cpp_type = documentation_type_data[fieldval['type']]["cpp_type"]
class_name = documentation_type_data[fieldval['type']]["class_name"]
cpp_includes.cpp_relative_includes.add("attribute/{}.hpp".format(class_name))

elif fieldval['type'] == "Custom":
elif fieldval['type'] in ["Custom", "CompoundCustomClass"]:
cpp_type = fieldval['class']
class_name = insert_delimiter(fieldval['class'], delimiter="_")
cpp_includes.hpp_relative_includes.add("attribute/{}.hpp".format(class_name))
Expand All @@ -500,7 +546,7 @@ def generate_cpp_variable_data(

for x in fieldval['xml_fields']:
xml_fields.append(lowercase(x, delimiter=""))
default_xml_fields.append(fieldval['xml_fields'][0])
default_xml_field = fieldval['xml_fields'][0]

if fieldval["protobuf_field"].startswith("trigger"):
is_trigger = True
Expand All @@ -517,42 +563,50 @@ def generate_cpp_variable_data(
side_effects.append(attribute_name_from_markdown_data(side_effect))

# Compound Values are unique in that the components have xml fields in addition to the compound variable
if fieldval['type'] == "CompoundValue":
xml_export = fieldval['xml_export']
if fieldval['type'] in ["CompoundValue", "CompoundCustomClass"]:
for component in fieldval['components']:
component_xml_fields = []
component_default_xml_fields = []
for item in component['xml_fields']:
if xml_export == "Children":
component_default_xml_fields.append(item)
if xml_export == "Parent":
component_default_xml_fields.append(fieldval["xml_fields"][0])
component_xml_fields.append(lowercase(item, delimiter=""))
component_xml_fields: List[str] = []
component_name: str = attribute_name_from_markdown_data(component['name'])
component_default_xml_field: str = ""
for x in component['xml_fields']:
component_xml_fields.append(lowercase(x, delimiter=""))
component_class_name = documentation_type_data[component['type']]["class_name"]
if component['name'] in fieldval['xml_separate_components']:
component_default_xml_field = component['xml_fields'][0]
write_to_xml = True
if component['name'] in fieldval['xml_bundled_components']:
component_default_xml_field = fieldval['xml_fields'][0]
write_to_xml = False
component_attribute_variable = AttributeVariable(
attribute_name=lowercase(component['name'], delimiter="_"),
attribute_name=attribute_name + "." + component_name,
attribute_type="CompoundValue",
cpp_type=doc_type_to_cpp_type[component['type']],
class_name=class_name,
class_name=component_class_name,
xml_fields=component_xml_fields,
default_xml_fields=component_default_xml_fields,
xml_export=xml_export,
default_xml_field=component_default_xml_field,
protobuf_field=component["protobuf_field"],
compound_name=lowercase(fieldval['name'], delimiter="_"),
attribute_flag_name=attribute_name + "_is_set",
write_to_xml=write_to_xml,
is_component=True,
args=args,
)
attribute_variables.append(component_attribute_variable)
# If there aren't any components to bundle, we don't want to render the attribute
if fieldval['xml_bundled_components'] == []:
write_to_xml = False

attribute_variable = AttributeVariable(
attribute_name=attribute_name,
attribute_type=fieldval["type"],
cpp_type=cpp_type,
class_name=class_name,
xml_fields=xml_fields,
default_xml_fields=default_xml_fields,
xml_export=xml_export,
default_xml_field=default_xml_field,
protobuf_field=protobuf_field,
is_trigger=is_trigger,
args=args,
write_to_xml=write_to_xml,
attribute_flag_name=attribute_name + "_is_set",
side_effects=side_effects,
)
attribute_variables.append(attribute_variable)
Expand Down Expand Up @@ -594,8 +648,9 @@ def write_attribute(self, output_directory: str) -> None:

for filepath in attribute_names:
attribute_variables = []
attribute_name = attribute_names[filepath]
xml_bundled_components: List[str] = []
metadata[filepath] = self.data[filepath].metadata
attribute_name = attribute_name_from_markdown_data(metadata[filepath]['name'])

if metadata[filepath]["protobuf_field"].startswith("trigger"):
is_trigger = True
Expand Down Expand Up @@ -628,15 +683,17 @@ def write_attribute(self, output_directory: str) -> None:
raise ValueError("Unexpected type for component. Look at markdown file {attribute_name}".format(
attribute_name=attribute_name
))
component_attribute_name: str = attribute_name_from_markdown_data(component['name'])
for item in component['xml_fields']:
xml_fields.append(normalize(item))
if component['name'] in metadata[filepath]['xml_bundled_components']:
xml_bundled_components.append(component_attribute_name)
attribute_variable = AttributeVariable(
attribute_name=lowercase(component['name'], delimiter="_"),
attribute_name=component_attribute_name,
attribute_type=metadata[filepath]['type'],
cpp_type=doc_type_to_cpp_type[component['type']],
class_name=attribute_name,
xml_fields=xml_fields,
xml_export=metadata[filepath]["xml_export"],
protobuf_field=component["protobuf_field"],
is_trigger=is_trigger,
)
Expand Down Expand Up @@ -675,6 +732,7 @@ def write_attribute(self, output_directory: str) -> None:
attribute_variables=attribute_variables,
class_name=capitalize(attribute_name, delimiter=""),
enumerate=enumerate,
xml_bundled_components=xml_bundled_components
))

############################################################################
Expand Down
Loading

0 comments on commit ad3bffe

Please sign in to comment.