diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2025-08-07 13:34:42 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2025-08-07 13:34:42 -0400 |
commit | e9d9da34e86a1e5f0de155bf9086d3e5ff6b2da0 (patch) | |
tree | 432e1177f11e7e2b5e0d6400fad977def7d31129 | |
parent | 1eacf01378d4dff3aed73fffcc42e0352b93835e (diff) | |
download | lingo2-archipelago-e9d9da34e86a1e5f0de155bf9086d3e5ff6b2da0.tar.gz lingo2-archipelago-e9d9da34e86a1e5f0de155bf9086d3e5ff6b2da0.tar.bz2 lingo2-archipelago-e9d9da34e86a1e5f0de155bf9086d3e5ff6b2da0.zip |
Protobuf works! Parsing connections
-rw-r--r-- | .clang-format | 1 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | .gitmodules | 0 | ||||
-rw-r--r-- | CMakeLists.txt | 12 | ||||
-rw-r--r-- | data/connections.txtpb | 2 | ||||
-rw-r--r-- | proto/CMakeLists.txt | 11 | ||||
-rw-r--r-- | proto/common.proto | 13 | ||||
-rw-r--r-- | proto/data.proto | 13 | ||||
-rw-r--r-- | proto/human.proto | 12 | ||||
-rw-r--r-- | tools/datapacker/CMakeLists.txt | 10 | ||||
-rw-r--r-- | tools/datapacker/container.cpp | 205 | ||||
-rw-r--r-- | tools/datapacker/container.h | 65 | ||||
-rw-r--r-- | tools/datapacker/main.cpp | 196 | ||||
-rw-r--r-- | vcpkg-configuration.json | 14 | ||||
-rw-r--r-- | vcpkg.json | 5 |
15 files changed, 536 insertions, 24 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..f6cb8ad --- /dev/null +++ b/.clang-format | |||
@@ -0,0 +1 @@ | |||
BasedOnStyle: Google | |||
diff --git a/.gitignore b/.gitignore index 84ef6b2..bf52fcf 100644 --- a/.gitignore +++ b/.gitignore | |||
@@ -1,2 +1,3 @@ | |||
1 | build/ | 1 | build/ |
2 | generated/ | 2 | generated/ |
3 | .vscode/ | ||
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/.gitmodules | |||
diff --git a/CMakeLists.txt b/CMakeLists.txt index f23152d..10025ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -1,8 +1,6 @@ | |||
1 | find_package(Protobuf) | 1 | cmake_minimum_required(VERSION 3.28) |
2 | 2 | ||
3 | protobuf_generate( | 3 | project(lingo2_archipelago) |
4 | LANGUAGE cpp | 4 | |
5 | OUT_VAR CPP_PROTO_SRCS | 5 | add_subdirectory(proto) |
6 | PROTOC_OUT_DIR generated/cpp/proto | 6 | add_subdirectory(tools/datapacker) |
7 | PROTOS proto/human.proto proto/data.proto | ||
8 | ) | ||
diff --git a/data/connections.txtpb b/data/connections.txtpb index a4f166f..5f2af9b 100644 --- a/data/connections.txtpb +++ b/data/connections.txtpb | |||
@@ -9,7 +9,7 @@ connections { | |||
9 | } | 9 | } |
10 | to { | 10 | to { |
11 | room { | 11 | room { |
12 | map: "the_entry" | 12 | map: "the_words" |
13 | name: "Entrance" | 13 | name: "Entrance" |
14 | } | 14 | } |
15 | } | 15 | } |
diff --git a/proto/CMakeLists.txt b/proto/CMakeLists.txt new file mode 100644 index 0000000..c5abd46 --- /dev/null +++ b/proto/CMakeLists.txt | |||
@@ -0,0 +1,11 @@ | |||
1 | find_package(Protobuf REQUIRED) | ||
2 | |||
3 | add_library(protos) | ||
4 | |||
5 | protobuf_generate( | ||
6 | LANGUAGE cpp | ||
7 | TARGET protos | ||
8 | PROTOS human.proto data.proto common.proto | ||
9 | ) | ||
10 | |||
11 | target_link_libraries(protos PUBLIC protobuf::libprotobuf) | ||
diff --git a/proto/common.proto b/proto/common.proto new file mode 100644 index 0000000..eb1d6b5 --- /dev/null +++ b/proto/common.proto | |||
@@ -0,0 +1,13 @@ | |||
1 | edition = "2023"; | ||
2 | |||
3 | package com.fourisland.lingo2_archipelago; | ||
4 | |||
5 | message Proxy { | ||
6 | string answer = 1; | ||
7 | string path = 2; | ||
8 | } | ||
9 | |||
10 | message Letter { | ||
11 | string letter = 1; | ||
12 | bool double = 2; | ||
13 | } | ||
diff --git a/proto/data.proto b/proto/data.proto index 71c3aeb..b3b6e6b 100644 --- a/proto/data.proto +++ b/proto/data.proto | |||
@@ -1,5 +1,7 @@ | |||
1 | edition = "2023"; | 1 | edition = "2023"; |
2 | 2 | ||
3 | import "common.proto"; | ||
4 | |||
3 | package com.fourisland.lingo2_archipelago; | 5 | package com.fourisland.lingo2_archipelago; |
4 | 6 | ||
5 | message ProxyIdentifier { | 7 | message ProxyIdentifier { |
@@ -8,11 +10,9 @@ message ProxyIdentifier { | |||
8 | } | 10 | } |
9 | 11 | ||
10 | message Connection { | 12 | message Connection { |
11 | uint64 id = 7; | ||
12 | |||
13 | uint64 from_room = 1; | 13 | uint64 from_room = 1; |
14 | uint64 to_room = 2; | 14 | uint64 to_room = 2; |
15 | repeated uint64 required_door = 3; | 15 | uint64 required_door = 3; |
16 | 16 | ||
17 | oneof trigger { | 17 | oneof trigger { |
18 | uint64 port = 4; | 18 | uint64 port = 4; |
@@ -82,6 +82,7 @@ message Port { | |||
82 | 82 | ||
83 | message Room { | 83 | message Room { |
84 | uint64 id = 1; | 84 | uint64 id = 1; |
85 | uint64 map_id = 8; | ||
85 | string name = 2; | 86 | string name = 2; |
86 | string display_name = 3; | 87 | string display_name = 3; |
87 | 88 | ||
@@ -91,7 +92,13 @@ message Room { | |||
91 | repeated uint64 ports = 7; | 92 | repeated uint64 ports = 7; |
92 | } | 93 | } |
93 | 94 | ||
95 | message Map { | ||
96 | uint64 id = 1; | ||
97 | string name = 2; | ||
98 | } | ||
99 | |||
94 | message AllObjects { | 100 | message AllObjects { |
101 | repeated Map maps = 7; | ||
95 | repeated Room rooms = 1; | 102 | repeated Room rooms = 1; |
96 | repeated Door doors = 2; | 103 | repeated Door doors = 2; |
97 | repeated Panel panels = 3; | 104 | repeated Panel panels = 3; |
diff --git a/proto/human.proto b/proto/human.proto index 06c89cd..cdbb8b9 100644 --- a/proto/human.proto +++ b/proto/human.proto | |||
@@ -1,5 +1,7 @@ | |||
1 | edition = "2023"; | 1 | edition = "2023"; |
2 | 2 | ||
3 | import "common.proto"; | ||
4 | |||
3 | package com.fourisland.lingo2_archipelago; | 5 | package com.fourisland.lingo2_archipelago; |
4 | 6 | ||
5 | message RoomIdentifier { | 7 | message RoomIdentifier { |
@@ -93,11 +95,6 @@ message HumanDoors { | |||
93 | repeated HumanDoor doors = 1; | 95 | repeated HumanDoor doors = 1; |
94 | } | 96 | } |
95 | 97 | ||
96 | message Proxy { | ||
97 | string answer = 1; | ||
98 | string path = 2; | ||
99 | } | ||
100 | |||
101 | message HumanPanel { | 98 | message HumanPanel { |
102 | string name = 1; | 99 | string name = 1; |
103 | string path = 5; | 100 | string path = 5; |
@@ -125,11 +122,6 @@ message HumanPainting { | |||
125 | DoorIdentifier required_door = 5; | 122 | DoorIdentifier required_door = 5; |
126 | } | 123 | } |
127 | 124 | ||
128 | message Letter { | ||
129 | string letter = 1; | ||
130 | bool double = 2; | ||
131 | } | ||
132 | |||
133 | message HumanPort { | 125 | message HumanPort { |
134 | string name = 1; | 126 | string name = 1; |
135 | string path = 2; | 127 | string path = 2; |
diff --git a/tools/datapacker/CMakeLists.txt b/tools/datapacker/CMakeLists.txt new file mode 100644 index 0000000..0274043 --- /dev/null +++ b/tools/datapacker/CMakeLists.txt | |||
@@ -0,0 +1,10 @@ | |||
1 | find_package(Protobuf REQUIRED) | ||
2 | |||
3 | add_executable(datapacker | ||
4 | main.cpp | ||
5 | container.cpp | ||
6 | ) | ||
7 | set_property(TARGET datapacker PROPERTY CXX_STANDARD 20) | ||
8 | set_property(TARGET datapacker PROPERTY CXX_STANDARD_REQUIRED ON) | ||
9 | target_include_directories(datapacker PUBLIC ${CMAKE_BINARY_DIR}) | ||
10 | target_link_libraries(datapacker PUBLIC protos protobuf::libprotobuf) | ||
diff --git a/tools/datapacker/container.cpp b/tools/datapacker/container.cpp new file mode 100644 index 0000000..ead3818 --- /dev/null +++ b/tools/datapacker/container.cpp | |||
@@ -0,0 +1,205 @@ | |||
1 | #include "container.h" | ||
2 | |||
3 | namespace com::fourisland::lingo2_archipelago { | ||
4 | |||
5 | uint64_t Container::FindOrAddMap(std::string map_name) { | ||
6 | auto it = map_id_by_name_.find(map_name); | ||
7 | |||
8 | if (it == map_id_by_name_.end()) { | ||
9 | uint64_t new_id = all_objects_.maps_size(); | ||
10 | Map* map = all_objects_.add_maps(); | ||
11 | map->set_id(new_id); | ||
12 | map->set_name(map_name); | ||
13 | |||
14 | map_id_by_name_[map_name] = new_id; | ||
15 | |||
16 | return new_id; | ||
17 | } else { | ||
18 | return it->second; | ||
19 | } | ||
20 | } | ||
21 | |||
22 | uint64_t Container::FindOrAddRoom(std::optional<std::string> map_name, | ||
23 | std::string room_name, | ||
24 | std::optional<std::string> map_fallback) { | ||
25 | if (!map_name) { | ||
26 | if (!map_fallback) { | ||
27 | std::cout << "No map name provided for " << room_name << std::endl; | ||
28 | map_name = "global"; | ||
29 | } else { | ||
30 | map_name = map_fallback; | ||
31 | } | ||
32 | } | ||
33 | |||
34 | auto& map_container = room_id_by_map_room_names_[*map_name]; | ||
35 | auto it = map_container.find(room_name); | ||
36 | if (it == map_container.end()) { | ||
37 | uint64_t new_id = all_objects_.rooms_size(); | ||
38 | Room* room = all_objects_.add_rooms(); | ||
39 | room->set_id(new_id); | ||
40 | room->set_map_id(FindOrAddMap(*map_name)); | ||
41 | room->set_name(room_name); | ||
42 | |||
43 | map_container[room_name] = new_id; | ||
44 | |||
45 | return new_id; | ||
46 | } else { | ||
47 | return it->second; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | uint64_t Container::FindOrAddPainting( | ||
52 | std::optional<std::string> map_name, std::optional<std::string> room_name, | ||
53 | std::string painting_name, std::optional<std::string> map_fallback, | ||
54 | std::optional<std::string> room_fallback) { | ||
55 | if (!map_name) { | ||
56 | if (!map_fallback) { | ||
57 | std::cout << "No map name provided for " << painting_name << std::endl; | ||
58 | map_name = "global"; | ||
59 | } else { | ||
60 | map_name = map_fallback; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | if (!room_name) { | ||
65 | if (!room_fallback) { | ||
66 | std::cout << "No room name provided for " << painting_name << std::endl; | ||
67 | room_name = "global"; | ||
68 | } else { | ||
69 | room_name = room_fallback; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | auto& room_container = | ||
74 | painting_id_by_map_room_painting_names_[*map_name][*room_name]; | ||
75 | auto it = room_container.find(painting_name); | ||
76 | if (it == room_container.end()) { | ||
77 | uint64_t new_id = all_objects_.paintings_size(); | ||
78 | Painting* painting = all_objects_.add_paintings(); | ||
79 | painting->set_id(new_id); | ||
80 | painting->set_room_id(FindOrAddRoom(map_name, *room_name, std::nullopt)); | ||
81 | painting->set_name(painting_name); | ||
82 | |||
83 | room_container[painting_name] = new_id; | ||
84 | |||
85 | return new_id; | ||
86 | } else { | ||
87 | return it->second; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | uint64_t Container::FindOrAddPort(std::optional<std::string> map_name, | ||
92 | std::optional<std::string> room_name, | ||
93 | std::string port_name, | ||
94 | std::optional<std::string> map_fallback, | ||
95 | std::optional<std::string> room_fallback) { | ||
96 | if (!map_name) { | ||
97 | if (!map_fallback) { | ||
98 | std::cout << "No map name provided for " << port_name << std::endl; | ||
99 | map_name = "global"; | ||
100 | } else { | ||
101 | map_name = map_fallback; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | if (!room_name) { | ||
106 | if (!room_fallback) { | ||
107 | std::cout << "No room name provided for " << port_name << std::endl; | ||
108 | room_name = "global"; | ||
109 | } else { | ||
110 | room_name = room_fallback; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | auto& room_container = port_id_by_map_room_port_names_[*map_name][*room_name]; | ||
115 | auto it = room_container.find(port_name); | ||
116 | if (it == room_container.end()) { | ||
117 | uint64_t new_id = all_objects_.ports_size(); | ||
118 | Port* port = all_objects_.add_ports(); | ||
119 | port->set_id(new_id); | ||
120 | port->set_room_id(FindOrAddRoom(map_name, *room_name, std::nullopt)); | ||
121 | port->set_name(port_name); | ||
122 | |||
123 | room_container[port_name] = new_id; | ||
124 | |||
125 | return new_id; | ||
126 | } else { | ||
127 | return it->second; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | uint64_t Container::FindOrAddPanel(std::optional<std::string> map_name, | ||
132 | std::optional<std::string> room_name, | ||
133 | std::string panel_name, | ||
134 | std::optional<std::string> map_fallback, | ||
135 | std::optional<std::string> room_fallback) { | ||
136 | if (!map_name) { | ||
137 | if (!map_fallback) { | ||
138 | std::cout << "No map name provided for " << panel_name << std::endl; | ||
139 | map_name = "global"; | ||
140 | } else { | ||
141 | map_name = map_fallback; | ||
142 | } | ||
143 | } | ||
144 | |||
145 | if (!room_name) { | ||
146 | if (!room_fallback) { | ||
147 | std::cout << "No room name provided for " << panel_name << std::endl; | ||
148 | room_name = "global"; | ||
149 | } else { | ||
150 | room_name = room_fallback; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | auto& room_container = | ||
155 | panel_id_by_map_room_panel_names_[*map_name][*room_name]; | ||
156 | auto it = room_container.find(panel_name); | ||
157 | if (it == room_container.end()) { | ||
158 | uint64_t new_id = all_objects_.panels_size(); | ||
159 | Panel* panel = all_objects_.add_panels(); | ||
160 | panel->set_id(new_id); | ||
161 | panel->set_room_id(FindOrAddRoom(map_name, *room_name, std::nullopt)); | ||
162 | panel->set_name(panel_name); | ||
163 | |||
164 | room_container[panel_name] = new_id; | ||
165 | |||
166 | return new_id; | ||
167 | } else { | ||
168 | return it->second; | ||
169 | } | ||
170 | } | ||
171 | |||
172 | uint64_t Container::FindOrAddDoor(std::optional<std::string> map_name, | ||
173 | std::string door_name, | ||
174 | std::optional<std::string> map_fallback) { | ||
175 | if (!map_name) { | ||
176 | if (!map_fallback) { | ||
177 | std::cout << "No map name provided for " << door_name << std::endl; | ||
178 | map_name = "global"; | ||
179 | } else { | ||
180 | map_name = map_fallback; | ||
181 | } | ||
182 | } | ||
183 | |||
184 | auto& map_container = door_id_by_map_door_names_[*map_name]; | ||
185 | auto it = map_container.find(door_name); | ||
186 | if (it == map_container.end()) { | ||
187 | uint64_t new_id = all_objects_.doors_size(); | ||
188 | Door* door = all_objects_.add_doors(); | ||
189 | door->set_id(new_id); | ||
190 | door->set_map_id(FindOrAddMap(*map_name)); | ||
191 | door->set_name(door_name); | ||
192 | |||
193 | map_container[door_name] = new_id; | ||
194 | |||
195 | return new_id; | ||
196 | } else { | ||
197 | return it->second; | ||
198 | } | ||
199 | } | ||
200 | |||
201 | void Container::AddConnection(const Connection& connection) { | ||
202 | *all_objects_.add_connections() = connection; | ||
203 | } | ||
204 | |||
205 | } // namespace com::fourisland::lingo2_archipelago | ||
diff --git a/tools/datapacker/container.h b/tools/datapacker/container.h new file mode 100644 index 0000000..96e5a50 --- /dev/null +++ b/tools/datapacker/container.h | |||
@@ -0,0 +1,65 @@ | |||
1 | #ifndef TOOLS_DATAPACKER_CONTAINER_H_ | ||
2 | #define TOOLS_DATAPACKER_CONTAINER_H_ | ||
3 | |||
4 | #include <cstdint> | ||
5 | #include <map> | ||
6 | #include <optional> | ||
7 | #include <string> | ||
8 | |||
9 | #include "proto/data.pb.h" | ||
10 | |||
11 | namespace com::fourisland::lingo2_archipelago { | ||
12 | |||
13 | class Container { | ||
14 | public: | ||
15 | uint64_t FindOrAddMap(std::string map_name); | ||
16 | |||
17 | uint64_t FindOrAddRoom(std::optional<std::string> map_name, | ||
18 | std::string room_name, | ||
19 | std::optional<std::string> map_fallback); | ||
20 | |||
21 | uint64_t FindOrAddPainting(std::optional<std::string> map_name, | ||
22 | std::optional<std::string> room_name, | ||
23 | std::string painting_name, | ||
24 | std::optional<std::string> map_fallback, | ||
25 | std::optional<std::string> room_fallback); | ||
26 | |||
27 | uint64_t FindOrAddPort(std::optional<std::string> map_name, | ||
28 | std::optional<std::string> room_name, | ||
29 | std::string port_name, | ||
30 | std::optional<std::string> map_fallback, | ||
31 | std::optional<std::string> room_fallback); | ||
32 | |||
33 | uint64_t FindOrAddPanel(std::optional<std::string> map_name, | ||
34 | std::optional<std::string> room_name, | ||
35 | std::string panel_name, | ||
36 | std::optional<std::string> map_fallback, | ||
37 | std::optional<std::string> room_fallback); | ||
38 | |||
39 | uint64_t FindOrAddDoor(std::optional<std::string> map_name, | ||
40 | std::string door_name, | ||
41 | std::optional<std::string> map_fallback); | ||
42 | |||
43 | void AddConnection(const Connection& connection); | ||
44 | |||
45 | const AllObjects& all_objects() const { return all_objects_; } | ||
46 | |||
47 | private: | ||
48 | AllObjects all_objects_; | ||
49 | |||
50 | std::map<std::string, uint64_t> map_id_by_name_; | ||
51 | std::map<std::string, std::map<std::string, uint64_t>> | ||
52 | room_id_by_map_room_names_; | ||
53 | std::map<std::string, std::map<std::string, std::map<std::string, uint64_t>>> | ||
54 | painting_id_by_map_room_painting_names_; | ||
55 | std::map<std::string, std::map<std::string, std::map<std::string, uint64_t>>> | ||
56 | port_id_by_map_room_port_names_; | ||
57 | std::map<std::string, std::map<std::string, std::map<std::string, uint64_t>>> | ||
58 | panel_id_by_map_room_panel_names_; | ||
59 | std::map<std::string, std::map<std::string, uint64_t>> | ||
60 | door_id_by_map_door_names_; | ||
61 | }; | ||
62 | |||
63 | } // namespace com::fourisland::lingo2_archipelago | ||
64 | |||
65 | #endif /* TOOLS_DATAPACKER_CONTAINER_H_ */ | ||
diff --git a/tools/datapacker/main.cpp b/tools/datapacker/main.cpp index fd0ace6..b2ec068 100644 --- a/tools/datapacker/main.cpp +++ b/tools/datapacker/main.cpp | |||
@@ -1,21 +1,211 @@ | |||
1 | #include <google/protobuf/message.h> | ||
2 | #include <google/protobuf/text_format.h> | ||
3 | |||
4 | #include <cstdint> | ||
5 | #include <filesystem> | ||
6 | #include <fstream> | ||
1 | #include <iostream> | 7 | #include <iostream> |
8 | #include <map> | ||
9 | #include <optional> | ||
10 | #include <sstream> | ||
2 | #include <string> | 11 | #include <string> |
3 | 12 | ||
4 | void Run(const std::string& mapdir, const std::string& outputpath) { | 13 | #include "container.h" |
14 | #include "proto/data.pb.h" | ||
15 | #include "proto/human.pb.h" | ||
16 | |||
17 | namespace com::fourisland::lingo2_archipelago { | ||
18 | namespace { | ||
19 | |||
20 | template <typename T> | ||
21 | T ReadMessageFromFile(const std::string& path) { | ||
22 | std::ifstream file(path); | ||
23 | std::stringstream buffer; | ||
24 | buffer << file.rdbuf(); | ||
5 | 25 | ||
26 | T message; | ||
27 | google::protobuf::TextFormat::ParseFromString(buffer.str(), &message); | ||
28 | |||
29 | return message; | ||
6 | } | 30 | } |
7 | 31 | ||
32 | class DataPacker { | ||
33 | public: | ||
34 | DataPacker(const std::string& mapdir, const std::string& outputpath) | ||
35 | : mapdir_(mapdir), outputpath_(outputpath) {} | ||
36 | |||
37 | void Run() { | ||
38 | std::filesystem::path datadir_path = mapdir_; | ||
39 | |||
40 | ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); | ||
41 | |||
42 | { | ||
43 | std::ofstream outputfile(outputpath_); | ||
44 | container_.all_objects().SerializeToOstream(&outputfile); | ||
45 | } | ||
46 | |||
47 | std::string output; | ||
48 | google::protobuf::TextFormat::PrintToString(container_.all_objects(), | ||
49 | &output); | ||
50 | std::cout << output << std::endl; | ||
51 | } | ||
52 | |||
53 | private: | ||
54 | void ProcessConnectionsFile(std::filesystem::path path, | ||
55 | std::optional<std::string> current_map_name) { | ||
56 | if (!std::filesystem::exists(path)) { | ||
57 | return; | ||
58 | } | ||
59 | |||
60 | auto connections = ReadMessageFromFile<HumanConnections>(path.string()); | ||
61 | |||
62 | for (const HumanConnection& connection : connections.connections()) { | ||
63 | ProcessConnection(connection, current_map_name); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | void ProcessConnection(const HumanConnection& human_connection, | ||
68 | const std::optional<std::string>& current_map_name) { | ||
69 | Connection f_connection; | ||
70 | |||
71 | if (human_connection.has_from_room()) { | ||
72 | f_connection.set_from_room(container_.FindOrAddRoom( | ||
73 | std::nullopt, human_connection.from_room(), current_map_name)); | ||
74 | } else if (human_connection.has_from()) { | ||
75 | ProcessSingleConnection(human_connection.from(), current_map_name, | ||
76 | f_connection); | ||
77 | } | ||
78 | |||
79 | Connection r_connection; | ||
80 | r_connection.set_to_room(f_connection.from_room()); | ||
81 | |||
82 | if (human_connection.has_to_room()) { | ||
83 | r_connection.set_to_room(container_.FindOrAddRoom( | ||
84 | std::nullopt, human_connection.to_room(), current_map_name)); | ||
85 | } else if (human_connection.has_to()) { | ||
86 | ProcessSingleConnection(human_connection.to(), current_map_name, | ||
87 | r_connection); | ||
88 | } | ||
89 | |||
90 | f_connection.set_to_room(r_connection.from_room()); | ||
91 | |||
92 | if (human_connection.has_door()) { | ||
93 | std::optional<std::string> map_name = | ||
94 | human_connection.door().has_map() | ||
95 | ? std::optional<std::string>(human_connection.door().map()) | ||
96 | : std::nullopt; | ||
97 | uint64_t door_id = container_.FindOrAddDoor( | ||
98 | map_name, human_connection.door().name(), current_map_name); | ||
99 | f_connection.set_required_door(door_id); | ||
100 | r_connection.set_required_door(door_id); | ||
101 | } | ||
102 | |||
103 | container_.AddConnection(f_connection); | ||
104 | if (!human_connection.oneway()) { | ||
105 | container_.AddConnection(r_connection); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | void ProcessSingleConnection( | ||
110 | const HumanConnection::Endpoint& endpoint, | ||
111 | const std::optional<std::string>& current_map_name, | ||
112 | Connection& connection) { | ||
113 | if (endpoint.has_room()) { | ||
114 | std::optional<std::string> map_name = | ||
115 | endpoint.room().has_map() | ||
116 | ? std::optional<std::string>(endpoint.room().map()) | ||
117 | : std::nullopt; | ||
118 | connection.set_from_room(container_.FindOrAddRoom( | ||
119 | map_name, endpoint.room().name(), current_map_name)); | ||
120 | } else if (endpoint.has_painting()) { | ||
121 | std::optional<std::string> map_name = | ||
122 | endpoint.painting().has_map() | ||
123 | ? std::optional<std::string>(endpoint.painting().map()) | ||
124 | : std::nullopt; | ||
125 | |||
126 | std::string room_name; | ||
127 | if (!endpoint.painting().has_room()) { | ||
128 | std::cout << "Missing room name for painting " | ||
129 | << endpoint.painting().name() << std::endl; | ||
130 | room_name = "default"; | ||
131 | } else { | ||
132 | room_name = endpoint.painting().room(); | ||
133 | } | ||
134 | |||
135 | connection.set_from_room( | ||
136 | container_.FindOrAddRoom(map_name, room_name, current_map_name)); | ||
137 | connection.set_painting(container_.FindOrAddPainting( | ||
138 | map_name, room_name, endpoint.painting().name(), current_map_name, | ||
139 | std::nullopt)); | ||
140 | } else if (endpoint.has_port()) { | ||
141 | std::optional<std::string> map_name = | ||
142 | endpoint.port().has_map() | ||
143 | ? std::optional<std::string>(endpoint.port().map()) | ||
144 | : std::nullopt; | ||
145 | |||
146 | std::string room_name; | ||
147 | if (!endpoint.port().has_room()) { | ||
148 | std::cout << "Missing room name for port " << endpoint.port().name() | ||
149 | << std::endl; | ||
150 | room_name = "default"; | ||
151 | } else { | ||
152 | room_name = endpoint.port().room(); | ||
153 | } | ||
154 | |||
155 | connection.set_from_room( | ||
156 | container_.FindOrAddRoom(map_name, room_name, current_map_name)); | ||
157 | connection.set_port( | ||
158 | container_.FindOrAddPort(map_name, room_name, endpoint.port().name(), | ||
159 | current_map_name, std::nullopt)); | ||
160 | } else if (endpoint.has_panel()) { | ||
161 | std::optional<std::string> map_name = | ||
162 | endpoint.panel().has_map() | ||
163 | ? std::optional<std::string>(endpoint.panel().map()) | ||
164 | : std::nullopt; | ||
165 | |||
166 | std::string room_name; | ||
167 | if (!endpoint.panel().has_room()) { | ||
168 | std::cout << "Missing room name for panel " << endpoint.panel().name() | ||
169 | << std::endl; | ||
170 | room_name = "default"; | ||
171 | } else { | ||
172 | room_name = endpoint.panel().room(); | ||
173 | } | ||
174 | |||
175 | connection.set_from_room( | ||
176 | container_.FindOrAddRoom(map_name, room_name, current_map_name)); | ||
177 | connection.mutable_panel()->set_panel(container_.FindOrAddPanel( | ||
178 | map_name, room_name, endpoint.panel().name(), current_map_name, | ||
179 | std::nullopt)); | ||
180 | if (endpoint.panel().has_answer()) { | ||
181 | connection.mutable_panel()->set_answer(endpoint.panel().answer()); | ||
182 | } | ||
183 | } | ||
184 | } | ||
185 | |||
186 | std::string mapdir_; | ||
187 | std::string outputpath_; | ||
188 | |||
189 | Container container_; | ||
190 | }; | ||
191 | |||
192 | } // namespace | ||
193 | } // namespace com::fourisland::lingo2_archipelago | ||
194 | |||
8 | int main(int argc, char** argv) { | 195 | int main(int argc, char** argv) { |
9 | if (argc != 3) { | 196 | if (argc != 3) { |
10 | std::cout << "Incorrect argument count." << std::endl; | 197 | std::cout << "Incorrect argument count." << std::endl; |
11 | std::cout << "Usage: datapacker [path to map directory] [output file]" << std::endl; | 198 | std::cout << "Usage: datapacker [path to map directory] [output file]" |
199 | << std::endl; | ||
12 | return 1; | 200 | return 1; |
13 | } | 201 | } |
14 | 202 | ||
15 | std::string mapdir = argv[1]; | 203 | std::string mapdir = argv[1]; |
16 | std::string outputpath = argv[2]; | 204 | std::string outputpath = argv[2]; |
17 | 205 | ||
18 | Run(mapdir, outputpath); | 206 | com::fourisland::lingo2_archipelago::DataPacker data_packer(mapdir, |
207 | outputpath); | ||
208 | data_packer.Run(); | ||
19 | 209 | ||
20 | return 0; | 210 | return 0; |
21 | } | 211 | } |
diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json new file mode 100644 index 0000000..2edc580 --- /dev/null +++ b/vcpkg-configuration.json | |||
@@ -0,0 +1,14 @@ | |||
1 | { | ||
2 | "default-registry": { | ||
3 | "kind": "git", | ||
4 | "baseline": "70a7abe262134f51393f02966e80789a2305ce6f", | ||
5 | "repository": "https://github.com/microsoft/vcpkg" | ||
6 | }, | ||
7 | "registries": [ | ||
8 | { | ||
9 | "kind": "artifact", | ||
10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", | ||
11 | "name": "microsoft" | ||
12 | } | ||
13 | ] | ||
14 | } | ||
diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..4b3fb5d --- /dev/null +++ b/vcpkg.json | |||
@@ -0,0 +1,5 @@ | |||
1 | { | ||
2 | "dependencies": [ | ||
3 | "protobuf" | ||
4 | ] | ||
5 | } | ||