diff options
| author | Star Rauchenberger <fefferburbia@gmail.com> | 2025-08-07 14:28:56 -0400 |
|---|---|---|
| committer | Star Rauchenberger <fefferburbia@gmail.com> | 2025-08-07 14:28:56 -0400 |
| commit | 3c26cedd030c464e3b8a5576a98c19eb45134658 (patch) | |
| tree | b2a9dcda18dfd39c43e85723d073bf56aaf1c3ed /tools/datapacker/main.cpp | |
| parent | e9d9da34e86a1e5f0de155bf9086d3e5ff6b2da0 (diff) | |
| download | lingo2-archipelago-3c26cedd030c464e3b8a5576a98c19eb45134658.tar.gz lingo2-archipelago-3c26cedd030c464e3b8a5576a98c19eb45134658.tar.bz2 lingo2-archipelago-3c26cedd030c464e3b8a5576a98c19eb45134658.zip | |
Process the rest of the defined protos
Diffstat (limited to 'tools/datapacker/main.cpp')
| -rw-r--r-- | tools/datapacker/main.cpp | 200 |
1 files changed, 199 insertions, 1 deletions
| diff --git a/tools/datapacker/main.cpp b/tools/datapacker/main.cpp index b2ec068..e63f940 100644 --- a/tools/datapacker/main.cpp +++ b/tools/datapacker/main.cpp | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #include <google/protobuf/message.h> | 1 | #include <google/protobuf/message.h> |
| 2 | #include <google/protobuf/text_format.h> | 2 | #include <google/protobuf/text_format.h> |
| 3 | 3 | ||
| 4 | #include <algorithm> | ||
| 4 | #include <cstdint> | 5 | #include <cstdint> |
| 5 | #include <filesystem> | 6 | #include <filesystem> |
| 6 | #include <fstream> | 7 | #include <fstream> |
| @@ -19,6 +20,8 @@ namespace { | |||
| 19 | 20 | ||
| 20 | template <typename T> | 21 | template <typename T> |
| 21 | T ReadMessageFromFile(const std::string& path) { | 22 | T ReadMessageFromFile(const std::string& path) { |
| 23 | std::cout << "Processing " << path << std::endl; | ||
| 24 | |||
| 22 | std::ifstream file(path); | 25 | std::ifstream file(path); |
| 23 | std::stringstream buffer; | 26 | std::stringstream buffer; |
| 24 | buffer << file.rdbuf(); | 27 | buffer << file.rdbuf(); |
| @@ -38,6 +41,7 @@ class DataPacker { | |||
| 38 | std::filesystem::path datadir_path = mapdir_; | 41 | std::filesystem::path datadir_path = mapdir_; |
| 39 | 42 | ||
| 40 | ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); | 43 | ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); |
| 44 | ProcessMaps(datadir_path); | ||
| 41 | 45 | ||
| 42 | { | 46 | { |
| 43 | std::ofstream outputfile(outputpath_); | 47 | std::ofstream outputfile(outputpath_); |
| @@ -51,6 +55,200 @@ class DataPacker { | |||
| 51 | } | 55 | } |
| 52 | 56 | ||
| 53 | private: | 57 | private: |
| 58 | void ProcessMaps(std::filesystem::path path) { | ||
| 59 | std::filesystem::path maps_dir = path / "maps"; | ||
| 60 | for (auto const& dir_entry : | ||
| 61 | std::filesystem::directory_iterator(maps_dir)) { | ||
| 62 | ProcessMap(dir_entry.path()); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | void ProcessMap(std::filesystem::path path) { | ||
| 67 | std::string map_name = path.filename(); | ||
| 68 | |||
| 69 | ProcessConnectionsFile(path / "connections.txtpb", map_name); | ||
| 70 | ProcessDoorsFile(path / "doors.txtpb", map_name); | ||
| 71 | ProcessRooms(path / "rooms", map_name); | ||
| 72 | } | ||
| 73 | |||
| 74 | void ProcessRooms(std::filesystem::path path, | ||
| 75 | const std::string& current_map_name) { | ||
| 76 | for (auto const& dir_entry : std::filesystem::directory_iterator(path)) { | ||
| 77 | auto room = ReadMessageFromFile<HumanRoom>(dir_entry.path().string()); | ||
| 78 | ProcessRoom(room, current_map_name); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | void ProcessRoom(const HumanRoom& h_room, | ||
| 83 | const std::string& current_map_name) { | ||
| 84 | uint64_t room_id = | ||
| 85 | container_.FindOrAddRoom(current_map_name, h_room.name(), std::nullopt); | ||
| 86 | Room& room = *container_.all_objects().mutable_rooms(room_id); | ||
| 87 | |||
| 88 | room.set_display_name(h_room.display_name()); | ||
| 89 | |||
| 90 | for (const HumanPanel& h_panel : h_room.panels()) { | ||
| 91 | room.add_panels(ProcessPanel(h_panel, current_map_name, room.name())); | ||
| 92 | } | ||
| 93 | |||
| 94 | for (const HumanPainting& h_painting : h_room.paintings()) { | ||
| 95 | room.add_paintings( | ||
| 96 | ProcessPainting(h_painting, current_map_name, room.name())); | ||
| 97 | } | ||
| 98 | |||
| 99 | for (const HumanPort& h_port : h_room.ports()) { | ||
| 100 | room.add_ports(ProcessPort(h_port, current_map_name, room.name())); | ||
| 101 | } | ||
| 102 | |||
| 103 | std::copy( | ||
| 104 | h_room.letters().begin(), h_room.letters().end(), | ||
| 105 | google::protobuf::RepeatedFieldBackInserter(room.mutable_letters())); | ||
| 106 | } | ||
| 107 | |||
| 108 | uint64_t ProcessPanel(const HumanPanel& h_panel, | ||
| 109 | const std::string& current_map_name, | ||
| 110 | const std::string& current_room_name) { | ||
| 111 | uint64_t panel_id = | ||
| 112 | container_.FindOrAddPanel(current_map_name, current_room_name, | ||
| 113 | h_panel.name(), std::nullopt, std::nullopt); | ||
| 114 | Panel& panel = *container_.all_objects().mutable_panels(panel_id); | ||
| 115 | |||
| 116 | panel.set_path(h_panel.path()); | ||
| 117 | panel.set_clue(h_panel.clue()); | ||
| 118 | panel.set_answer(h_panel.answer()); | ||
| 119 | |||
| 120 | std::copy( | ||
| 121 | h_panel.symbols().begin(), h_panel.symbols().end(), | ||
| 122 | google::protobuf::RepeatedFieldBackInserter(panel.mutable_symbols())); | ||
| 123 | std::copy( | ||
| 124 | h_panel.proxies().begin(), h_panel.proxies().end(), | ||
| 125 | google::protobuf::RepeatedFieldBackInserter(panel.mutable_proxies())); | ||
| 126 | |||
| 127 | if (h_panel.has_required_door()) { | ||
| 128 | std::optional<std::string> map_name = | ||
| 129 | h_panel.required_door().has_map() | ||
| 130 | ? std::optional<std::string>(h_panel.required_door().map()) | ||
| 131 | : std::nullopt; | ||
| 132 | panel.set_required_door(container_.FindOrAddDoor( | ||
| 133 | map_name, h_panel.required_door().name(), current_map_name)); | ||
| 134 | } | ||
| 135 | |||
| 136 | return panel_id; | ||
| 137 | } | ||
| 138 | |||
| 139 | uint64_t ProcessPainting(const HumanPainting& h_painting, | ||
| 140 | const std::string& current_map_name, | ||
| 141 | const std::string& current_room_name) { | ||
| 142 | uint64_t painting_id = container_.FindOrAddPainting( | ||
| 143 | current_map_name, current_room_name, h_painting.name(), std::nullopt, | ||
| 144 | std::nullopt); | ||
| 145 | Painting& painting = | ||
| 146 | *container_.all_objects().mutable_paintings(painting_id); | ||
| 147 | |||
| 148 | painting.set_path(h_painting.path()); | ||
| 149 | painting.set_display_name(h_painting.display_name()); | ||
| 150 | painting.set_orientation(h_painting.orientation()); | ||
| 151 | |||
| 152 | if (h_painting.has_flipped()) { | ||
| 153 | painting.set_flipped(h_painting.flipped()); | ||
| 154 | } | ||
| 155 | |||
| 156 | if (h_painting.has_move()) { | ||
| 157 | painting.set_move(h_painting.move()); | ||
| 158 | } | ||
| 159 | |||
| 160 | if (h_painting.has_enter_only()) { | ||
| 161 | painting.set_enter_only(h_painting.enter_only()); | ||
| 162 | } | ||
| 163 | |||
| 164 | if (h_painting.has_required_door()) { | ||
| 165 | std::optional<std::string> map_name = | ||
| 166 | h_painting.required_door().has_map() | ||
| 167 | ? std::optional<std::string>(h_painting.required_door().map()) | ||
| 168 | : std::nullopt; | ||
| 169 | painting.set_required_door(container_.FindOrAddDoor( | ||
| 170 | map_name, h_painting.required_door().name(), current_map_name)); | ||
| 171 | } | ||
| 172 | |||
| 173 | return painting_id; | ||
| 174 | } | ||
| 175 | |||
| 176 | uint64_t ProcessPort(const HumanPort& h_port, | ||
| 177 | const std::string& current_map_name, | ||
| 178 | const std::string& current_room_name) { | ||
| 179 | uint64_t port_id = | ||
| 180 | container_.FindOrAddPort(current_map_name, current_room_name, | ||
| 181 | h_port.name(), std::nullopt, std::nullopt); | ||
| 182 | Port& port = *container_.all_objects().mutable_ports(port_id); | ||
| 183 | |||
| 184 | port.set_path(h_port.path()); | ||
| 185 | port.set_orientation(h_port.orientation()); | ||
| 186 | |||
| 187 | if (h_port.has_required_door()) { | ||
| 188 | std::optional<std::string> map_name = | ||
| 189 | h_port.required_door().has_map() | ||
| 190 | ? std::optional<std::string>(h_port.required_door().map()) | ||
| 191 | : std::nullopt; | ||
| 192 | port.set_required_door(container_.FindOrAddDoor( | ||
| 193 | map_name, h_port.required_door().name(), current_map_name)); | ||
| 194 | } | ||
| 195 | |||
| 196 | return port_id; | ||
| 197 | } | ||
| 198 | |||
| 199 | void ProcessDoorsFile(std::filesystem::path path, | ||
| 200 | const std::string& current_map_name) { | ||
| 201 | if (!std::filesystem::exists(path)) { | ||
| 202 | return; | ||
| 203 | } | ||
| 204 | |||
| 205 | auto doors = ReadMessageFromFile<HumanDoors>(path.string()); | ||
| 206 | |||
| 207 | for (const HumanDoor& door : doors.doors()) { | ||
| 208 | ProcessDoor(door, current_map_name); | ||
| 209 | } | ||
| 210 | } | ||
| 211 | |||
| 212 | void ProcessDoor(const HumanDoor& h_door, | ||
| 213 | const std::string& current_map_name) { | ||
| 214 | uint64_t door_id = | ||
| 215 | container_.FindOrAddDoor(current_map_name, h_door.name(), std::nullopt); | ||
| 216 | Door& door = *container_.all_objects().mutable_doors(door_id); | ||
| 217 | |||
| 218 | std::copy( | ||
| 219 | h_door.receivers().begin(), h_door.receivers().end(), | ||
| 220 | google::protobuf::RepeatedFieldBackInserter(door.mutable_receivers())); | ||
| 221 | std::copy( | ||
| 222 | h_door.switches().begin(), h_door.switches().end(), | ||
| 223 | google::protobuf::RepeatedFieldBackInserter(door.mutable_switches())); | ||
| 224 | |||
| 225 | for (const PaintingIdentifier& pi : h_door.move_paintings()) { | ||
| 226 | std::optional<std::string> map_name = | ||
| 227 | pi.has_map() ? std::optional<std::string>(pi.map()) : std::nullopt; | ||
| 228 | door.add_move_paintings(container_.FindOrAddPainting( | ||
| 229 | map_name, pi.room(), pi.name(), current_map_name, std::nullopt)); | ||
| 230 | } | ||
| 231 | |||
| 232 | for (const PanelIdentifier& pi : h_door.panels()) { | ||
| 233 | ProxyIdentifier* proxy = door.add_panels(); | ||
| 234 | |||
| 235 | std::optional<std::string> map_name = | ||
| 236 | pi.has_map() ? std::optional<std::string>(pi.map()) : std::nullopt; | ||
| 237 | proxy->set_panel(container_.FindOrAddPanel( | ||
| 238 | map_name, pi.room(), pi.name(), current_map_name, std::nullopt)); | ||
| 239 | |||
| 240 | if (pi.has_answer()) { | ||
| 241 | proxy->set_answer(pi.answer()); | ||
| 242 | } | ||
| 243 | } | ||
| 244 | |||
| 245 | if (h_door.has_control_center_color()) { | ||
| 246 | door.set_control_center_color(h_door.control_center_color()); | ||
| 247 | } | ||
| 248 | |||
| 249 | door.set_type(h_door.type()); | ||
| 250 | } | ||
| 251 | |||
| 54 | void ProcessConnectionsFile(std::filesystem::path path, | 252 | void ProcessConnectionsFile(std::filesystem::path path, |
| 55 | std::optional<std::string> current_map_name) { | 253 | std::optional<std::string> current_map_name) { |
| 56 | if (!std::filesystem::exists(path)) { | 254 | if (!std::filesystem::exists(path)) { |
| @@ -80,7 +278,7 @@ class DataPacker { | |||
| 80 | r_connection.set_to_room(f_connection.from_room()); | 278 | r_connection.set_to_room(f_connection.from_room()); |
| 81 | 279 | ||
| 82 | if (human_connection.has_to_room()) { | 280 | if (human_connection.has_to_room()) { |
| 83 | r_connection.set_to_room(container_.FindOrAddRoom( | 281 | r_connection.set_from_room(container_.FindOrAddRoom( |
| 84 | std::nullopt, human_connection.to_room(), current_map_name)); | 282 | std::nullopt, human_connection.to_room(), current_map_name)); |
| 85 | } else if (human_connection.has_to()) { | 283 | } else if (human_connection.has_to()) { |
| 86 | ProcessSingleConnection(human_connection.to(), current_map_name, | 284 | ProcessSingleConnection(human_connection.to(), current_map_name, |
