Skip to content

Commit

Permalink
Merge branch 'xml_converter' into copying_files
Browse files Browse the repository at this point in the history
  • Loading branch information
klingbolt authored Mar 18, 2024
2 parents 2f68f5c + 6d720e2 commit fbce0f4
Show file tree
Hide file tree
Showing 94 changed files with 1,504 additions and 214 deletions.
33 changes: 29 additions & 4 deletions xml_converter/doc/map_id/map_id.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions xml_converter/doc/menu/menu_id.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ using namespace std;

void xml_attribute_to_{{attribute_name}}(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLReaderState* state,
std::vector<XMLError*>*,
XMLReaderState*,
{{class_name}}* value,
bool* is_set) {
{{class_name}} {{attribute_name}};
Expand All @@ -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) %}
Expand All @@ -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}};
Expand All @@ -67,7 +67,7 @@ void proto_to_{{attribute_name}}(

void {{attribute_name}}_to_proto(
{{class_name}} value,
ProtoWriterState* state,
ProtoWriterState*,
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 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace std;
void xml_attribute_to_{{attribute_name}}(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLReaderState* state,
XMLReaderState*,
{{class_name}}* value,
bool* is_set) {
{{class_name}} {{attribute_name}};
Expand Down Expand Up @@ -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) %}
Expand All @@ -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) {
Expand All @@ -82,7 +82,7 @@ void proto_to_{{attribute_name}}(

void {{attribute_name}}_to_proto(
{{class_name}} value,
ProtoWriterState* state,
ProtoWriterState*,
std::function<void({{proto_field_cpp_type}})> setter) {
switch (value) {
{% for attribute_component in attribute_components %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace std;
void xml_attribute_to_{{attribute_name}}(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLReaderState* state,
XMLReaderState*,
{{class_name}}* value,
bool* is_set) {
{{class_name}} {{attribute_name}};
Expand Down Expand Up @@ -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<string> flag_values;
{% for n, attribute_component in enumerate(attribute_components) %}
Expand All @@ -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}};
Expand All @@ -78,7 +78,7 @@ void proto_to_{{attribute_name}}(

void {{attribute_name}}_to_proto(
{{class_name}} value,
ProtoWriterState* state,
ProtoWriterState*,
std::function<void({{proto_field_cpp_type}}*)> setter) {
{{proto_field_cpp_type}}* proto_{{attribute_name}} = new {{proto_field_cpp_type}}();
bool should_write = false;
Expand Down
48 changes: 46 additions & 2 deletions xml_converter/generators/cpp_templates/class_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<XMLError*>* 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);
Expand Down Expand Up @@ -69,7 +69,7 @@ vector<string> {{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) {
Expand Down Expand Up @@ -120,3 +120,47 @@ 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 %}
}
3 changes: 3 additions & 0 deletions xml_converter/generators/cpp_templates/class_template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class {{cpp_class}} : public Parseable {
std::map<std::string, Category> children;
Icon default_icon;
Trail default_trail;
Category* parent;

void init_from_xml(rapidxml::xml_node<>* node, std::vector<XMLError*>* errors, XMLReaderState* state);
{% endif %}
Expand All @@ -39,4 +40,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);
};
27 changes: 20 additions & 7 deletions xml_converter/generators/generate_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -175,25 +178,35 @@ 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),
xml_class_name=cpp_classes[cpp_class],
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]]:
Expand Down
29 changes: 23 additions & 6 deletions xml_converter/generators/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


XML_ATTRIBUTE_REGEX: Final[str] = "^[A-Za-z]+$"
PROTO_FIELD_REGEX: Final[str] = "^[a-z_.]+$"
Expand Down Expand Up @@ -123,6 +125,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)
Expand Down Expand Up @@ -364,6 +369,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"

Expand All @@ -372,13 +385,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.delete_generated_docs("../src/")
generator.write_webdocs("../web_docs/")
write_cpp_classes("../src/", generator.data)
if generate_all or args.documentation:
generator.delete_generated_docs("../web_docs")
generator.write_webdocs("../web_docs/")

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()
17 changes: 17 additions & 0 deletions xml_converter/generators/web_templates/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,7 +99,12 @@
text-align: center;
margin: 10px;
}

.field_wrapper h1 {
border-bottom: 1px solid #777;
}
</style>
<link rel="stylesheet" type="text/css" href="./styles.css">
</head>
<body>
<div class="header">Hello world</div>
Expand Down
2 changes: 1 addition & 1 deletion xml_converter/generators/web_templates/infotable.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h3>Examples</h3>{{field_row.example}}<br>
<!-- </div><div class="halfbox"> -->
<h3>Valid XML Values</h3>{{field_row.valid_values_html}}<br>
<!-- </div><div style="clear: both"></div> -->
<h3>Description</h3>{{field_row.description}}<br>
<h1>Description</h1>{{field_row.description}}<br>
<!-- <div style="clear: both"></div><div class="halfbox"> -->
</div>
{% endfor %}
Expand Down
Loading

0 comments on commit fbce0f4

Please sign in to comment.