diff options
Diffstat (limited to 'tools/util')
| -rw-r--r-- | tools/util/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | tools/util/godot_scene.cpp | 6 | ||||
| -rw-r--r-- | tools/util/ids_yaml_format.cpp | 203 | ||||
| -rw-r--r-- | tools/util/ids_yaml_format.h | 16 |
4 files changed, 224 insertions, 5 deletions
| diff --git a/tools/util/CMakeLists.txt b/tools/util/CMakeLists.txt index 4d19c3b..0859a58 100644 --- a/tools/util/CMakeLists.txt +++ b/tools/util/CMakeLists.txt | |||
| @@ -1,11 +1,13 @@ | |||
| 1 | find_package(Protobuf REQUIRED) | 1 | find_package(Protobuf REQUIRED) |
| 2 | find_package(yaml-cpp REQUIRED) | ||
| 2 | 3 | ||
| 3 | add_library(util | 4 | add_library(util |
| 4 | godot_scene.cpp | 5 | godot_scene.cpp |
| 5 | identifiers.cpp | 6 | identifiers.cpp |
| 7 | ids_yaml_format.cpp | ||
| 6 | naming.cpp | 8 | naming.cpp |
| 7 | ) | 9 | ) |
| 8 | set_property(TARGET util PROPERTY CXX_STANDARD 20) | 10 | set_property(TARGET util PROPERTY CXX_STANDARD 20) |
| 9 | set_property(TARGET util PROPERTY CXX_STANDARD_REQUIRED ON) | 11 | set_property(TARGET util PROPERTY CXX_STANDARD_REQUIRED ON) |
| 10 | target_include_directories(util PUBLIC ${CMAKE_BINARY_DIR}) | 12 | target_include_directories(util PUBLIC ${CMAKE_BINARY_DIR}) |
| 11 | target_link_libraries(util PUBLIC protos protobuf::libprotobuf) | 13 | target_link_libraries(util PUBLIC protos protobuf::libprotobuf yaml-cpp::yaml-cpp) |
| diff --git a/tools/util/godot_scene.cpp b/tools/util/godot_scene.cpp index 1e77c9e..f788d21 100644 --- a/tools/util/godot_scene.cpp +++ b/tools/util/godot_scene.cpp | |||
| @@ -1,10 +1,8 @@ | |||
| 1 | #include "godot_scene.h" | 1 | #include "godot_scene.h" |
| 2 | 2 | ||
| 3 | #include <absl/strings/str_split.h> | ||
| 4 | #include <absl/strings/string_view.h> | ||
| 5 | |||
| 6 | #include <fstream> | 3 | #include <fstream> |
| 7 | #include <sstream> | 4 | #include <sstream> |
| 5 | #include <string_view> | ||
| 8 | #include <variant> | 6 | #include <variant> |
| 9 | 7 | ||
| 10 | namespace com::fourisland::lingo2_archipelago { | 8 | namespace com::fourisland::lingo2_archipelago { |
| @@ -23,7 +21,7 @@ struct Heading { | |||
| 23 | GodotInstanceType instance_type; | 21 | GodotInstanceType instance_type; |
| 24 | }; | 22 | }; |
| 25 | 23 | ||
| 26 | Heading ParseTscnHeading(absl::string_view line) { | 24 | Heading ParseTscnHeading(std::string_view line) { |
| 27 | std::string original_line(line); | 25 | std::string original_line(line); |
| 28 | Heading heading; | 26 | Heading heading; |
| 29 | 27 | ||
| diff --git a/tools/util/ids_yaml_format.cpp b/tools/util/ids_yaml_format.cpp new file mode 100644 index 0000000..5b9113b --- /dev/null +++ b/tools/util/ids_yaml_format.cpp | |||
| @@ -0,0 +1,203 @@ | |||
| 1 | #include "ids_yaml_format.h" | ||
| 2 | |||
| 3 | #include <yaml-cpp/yaml.h> | ||
| 4 | |||
| 5 | #include <fstream> | ||
| 6 | #include <functional> | ||
| 7 | |||
| 8 | namespace com::fourisland::lingo2_archipelago { | ||
| 9 | namespace { | ||
| 10 | |||
| 11 | template <typename T> | ||
| 12 | void OperateOnSortedMap( | ||
| 13 | const T& map, std::function<void(const std::string& name, | ||
| 14 | const typename T::mapped_type& value)> | ||
| 15 | callback) { | ||
| 16 | std::vector<std::string> names; | ||
| 17 | for (const auto& it : map) { | ||
| 18 | names.push_back(it.first); | ||
| 19 | } | ||
| 20 | |||
| 21 | std::sort(names.begin(), names.end()); | ||
| 22 | |||
| 23 | for (const std::string& name : names) { | ||
| 24 | callback(name, map.at(name)); | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | } // namespace | ||
| 29 | |||
| 30 | IdMappings ReadIdsFromYaml(const std::string& filename) { | ||
| 31 | IdMappings result; | ||
| 32 | |||
| 33 | YAML::Node document = YAML::LoadFile(filename); | ||
| 34 | |||
| 35 | if (document["maps"]) { | ||
| 36 | for (const auto& map_it : document["maps"]) { | ||
| 37 | IdMappings::MapIds& map_ids = | ||
| 38 | (*result.mutable_maps())[map_it.first.as<std::string>()]; | ||
| 39 | |||
| 40 | if (map_it.second["rooms"]) { | ||
| 41 | for (const auto& room_it : map_it.second["rooms"]) { | ||
| 42 | IdMappings::RoomIds& room_ids = | ||
| 43 | (*map_ids.mutable_rooms())[room_it.first.as<std::string>()]; | ||
| 44 | |||
| 45 | if (room_it.second["panels"]) { | ||
| 46 | for (const auto& panel_it : room_it.second["panels"]) { | ||
| 47 | (*room_ids.mutable_panels())[panel_it.first.as<std::string>()] = | ||
| 48 | panel_it.second.as<uint64_t>(); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | if (room_it.second["masteries"]) { | ||
| 53 | for (const auto& mastery_it : room_it.second["masteries"]) { | ||
| 54 | (*room_ids | ||
| 55 | .mutable_masteries())[mastery_it.first.as<std::string>()] = | ||
| 56 | mastery_it.second.as<uint64_t>(); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | if (room_it.second["keyholders"]) { | ||
| 61 | for (const auto& keyholder_it : room_it.second["keyholders"]) { | ||
| 62 | (*room_ids.mutable_keyholders())[keyholder_it.first | ||
| 63 | .as<std::string>()] = | ||
| 64 | keyholder_it.second.as<uint64_t>(); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | if (room_it.second["ports"]) { | ||
| 69 | for (const auto& port_it : room_it.second["ports"]) { | ||
| 70 | (*room_ids.mutable_ports())[port_it.first.as<std::string>()] = | ||
| 71 | port_it.second.as<uint64_t>(); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | if (map_it.second["doors"]) { | ||
| 78 | for (const auto& door_it : map_it.second["doors"]) { | ||
| 79 | (*map_ids.mutable_doors())[door_it.first.as<std::string>()] = | ||
| 80 | door_it.second.as<uint64_t>(); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | if (document["letters"]) { | ||
| 87 | for (const auto& letter_it : document["letters"]) { | ||
| 88 | (*result.mutable_letters())[letter_it.first.as<std::string>()] = | ||
| 89 | letter_it.second.as<uint64_t>(); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | if (document["endings"]) { | ||
| 94 | for (const auto& ending_it : document["endings"]) { | ||
| 95 | (*result.mutable_endings())[ending_it.first.as<std::string>()] = | ||
| 96 | ending_it.second.as<uint64_t>(); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | if (document["special"]) { | ||
| 101 | for (const auto& special_it : document["special"]) { | ||
| 102 | (*result.mutable_special())[special_it.first.as<std::string>()] = | ||
| 103 | special_it.second.as<uint64_t>(); | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | if (document["progressives"]) { | ||
| 108 | for (const auto& prog_it : document["progressives"]) { | ||
| 109 | (*result.mutable_progressives())[prog_it.first.as<std::string>()] = | ||
| 110 | prog_it.second.as<uint64_t>(); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | if (document["door_groups"]) { | ||
| 115 | for (const auto& group_it : document["door_groups"]) { | ||
| 116 | (*result.mutable_door_groups())[group_it.first.as<std::string>()] = | ||
| 117 | group_it.second.as<uint64_t>(); | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | return result; | ||
| 122 | } | ||
| 123 | |||
| 124 | void WriteIdsAsYaml(const IdMappings& ids, const std::string& filename) { | ||
| 125 | YAML::Node result; | ||
| 126 | |||
| 127 | OperateOnSortedMap(ids.maps(), [&result](const std::string& map_name, | ||
| 128 | const IdMappings::MapIds& map_ids) { | ||
| 129 | YAML::Node map_node; | ||
| 130 | |||
| 131 | OperateOnSortedMap( | ||
| 132 | map_ids.rooms(), [&map_node](const std::string& room_name, | ||
| 133 | const IdMappings::RoomIds& room_ids) { | ||
| 134 | YAML::Node room_node; | ||
| 135 | |||
| 136 | OperateOnSortedMap( | ||
| 137 | room_ids.panels(), | ||
| 138 | [&room_node](const std::string& panel_name, uint64_t panel_id) { | ||
| 139 | room_node["panels"][panel_name] = panel_id; | ||
| 140 | }); | ||
| 141 | |||
| 142 | OperateOnSortedMap(room_ids.masteries(), | ||
| 143 | [&room_node](const std::string& mastery_name, | ||
| 144 | uint64_t mastery_id) { | ||
| 145 | room_node["masteries"][mastery_name] = | ||
| 146 | mastery_id; | ||
| 147 | }); | ||
| 148 | |||
| 149 | OperateOnSortedMap(room_ids.keyholders(), | ||
| 150 | [&room_node](const std::string& keyholder_name, | ||
| 151 | uint64_t keyholder_id) { | ||
| 152 | room_node["keyholders"][keyholder_name] = | ||
| 153 | keyholder_id; | ||
| 154 | }); | ||
| 155 | |||
| 156 | OperateOnSortedMap( | ||
| 157 | room_ids.ports(), | ||
| 158 | [&room_node](const std::string& port_name, uint64_t port_id) { | ||
| 159 | room_node["ports"][port_name] = port_id; | ||
| 160 | }); | ||
| 161 | |||
| 162 | map_node["rooms"][room_name] = std::move(room_node); | ||
| 163 | }); | ||
| 164 | |||
| 165 | OperateOnSortedMap( | ||
| 166 | map_ids.doors(), | ||
| 167 | [&map_node](const std::string& door_name, uint64_t door_id) { | ||
| 168 | map_node["doors"][door_name] = door_id; | ||
| 169 | }); | ||
| 170 | |||
| 171 | result["maps"][map_name] = std::move(map_node); | ||
| 172 | }); | ||
| 173 | |||
| 174 | OperateOnSortedMap(ids.letters(), [&result](const std::string& letter_name, | ||
| 175 | uint64_t letter_id) { | ||
| 176 | result["letters"][letter_name] = letter_id; | ||
| 177 | }); | ||
| 178 | |||
| 179 | OperateOnSortedMap(ids.endings(), [&result](const std::string& ending_name, | ||
| 180 | uint64_t ending_id) { | ||
| 181 | result["endings"][ending_name] = ending_id; | ||
| 182 | }); | ||
| 183 | |||
| 184 | OperateOnSortedMap(ids.special(), [&result](const std::string& special_name, | ||
| 185 | uint64_t special_id) { | ||
| 186 | result["special"][special_name] = special_id; | ||
| 187 | }); | ||
| 188 | |||
| 189 | OperateOnSortedMap(ids.progressives(), | ||
| 190 | [&result](const std::string& prog_name, uint64_t prog_id) { | ||
| 191 | result["progressives"][prog_name] = prog_id; | ||
| 192 | }); | ||
| 193 | |||
| 194 | OperateOnSortedMap(ids.door_groups(), [&result](const std::string& group_name, | ||
| 195 | uint64_t group_id) { | ||
| 196 | result["door_groups"][group_name] = group_id; | ||
| 197 | }); | ||
| 198 | |||
| 199 | std::ofstream output_stream(filename); | ||
| 200 | output_stream << result << std::endl; | ||
| 201 | } | ||
| 202 | |||
| 203 | } // namespace com::fourisland::lingo2_archipelago | ||
| diff --git a/tools/util/ids_yaml_format.h b/tools/util/ids_yaml_format.h new file mode 100644 index 0000000..d926369 --- /dev/null +++ b/tools/util/ids_yaml_format.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #ifndef TOOLS_UTIL_IDS_YAML_FORMAT_H_ | ||
| 2 | #define TOOLS_UTIL_IDS_YAML_FORMAT_H_ | ||
| 3 | |||
| 4 | #include <string> | ||
| 5 | |||
| 6 | #include "proto/human.pb.h" | ||
| 7 | |||
| 8 | namespace com::fourisland::lingo2_archipelago { | ||
| 9 | |||
| 10 | IdMappings ReadIdsFromYaml(const std::string& filename); | ||
| 11 | |||
| 12 | void WriteIdsAsYaml(const IdMappings& ids, const std::string& filename); | ||
| 13 | |||
| 14 | } // namespace com::fourisland::lingo2_archipelago | ||
| 15 | |||
| 16 | #endif /* TOOLS_UTIL_IDS_YAML_FORMAT_H_ */ | ||
