diff options
Diffstat (limited to 'game_data.cpp')
-rw-r--r-- | game_data.cpp | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/game_data.cpp b/game_data.cpp index f377e0b..54a01ed 100644 --- a/game_data.cpp +++ b/game_data.cpp | |||
@@ -34,7 +34,7 @@ GameData::GameData() { | |||
34 | YAML::Node lingo_config = YAML::LoadFile("assets/LL1.yaml"); | 34 | YAML::Node lingo_config = YAML::LoadFile("assets/LL1.yaml"); |
35 | YAML::Node areas_config = YAML::LoadFile("assets/areas.yaml"); | 35 | YAML::Node areas_config = YAML::LoadFile("assets/areas.yaml"); |
36 | 36 | ||
37 | rooms_.reserve(lingo_config.size() + 1); // The +1 is for Menu | 37 | rooms_.reserve(lingo_config.size() * 2); |
38 | 38 | ||
39 | for (const auto &room_it : lingo_config) { | 39 | for (const auto &room_it : lingo_config) { |
40 | int room_id = AddOrGetRoom(room_it.first.as<std::string>()); | 40 | int room_id = AddOrGetRoom(room_it.first.as<std::string>()); |
@@ -183,6 +183,10 @@ GameData::GameData() { | |||
183 | door_obj.skip_location = door_it.second["skip_location"].as<bool>(); | 183 | door_obj.skip_location = door_it.second["skip_location"].as<bool>(); |
184 | } | 184 | } |
185 | 185 | ||
186 | if (door_it.second["event"]) { | ||
187 | door_obj.skip_location = door_it.second["event"].as<bool>(); | ||
188 | } | ||
189 | |||
186 | if (door_it.second["item_name"]) { | 190 | if (door_it.second["item_name"]) { |
187 | door_obj.item_name = door_it.second["item_name"].as<std::string>(); | 191 | door_obj.item_name = door_it.second["item_name"].as<std::string>(); |
188 | } else if (!door_it.second["skip_item"] && !door_it.second["event"]) { | 192 | } else if (!door_it.second["skip_item"] && !door_it.second["event"]) { |
@@ -232,6 +236,52 @@ GameData::GameData() { | |||
232 | AddOrGetArea(area_it.second["fold_into"].as<std::string>()); | 236 | AddOrGetArea(area_it.second["fold_into"].as<std::string>()); |
233 | } | 237 | } |
234 | } | 238 | } |
239 | |||
240 | for (const Panel &panel : panels_) { | ||
241 | if (panel.check) { | ||
242 | int room_id = panel.room; | ||
243 | std::string room_name = rooms_[room_id].name; | ||
244 | |||
245 | std::string area_name = room_name; | ||
246 | if (fold_areas.count(room_name)) { | ||
247 | int fold_area_id = fold_areas[room_name]; | ||
248 | area_name = map_areas_[fold_area_id].name; | ||
249 | } | ||
250 | |||
251 | int area_id = AddOrGetArea(area_name); | ||
252 | MapArea &map_area = map_areas_[area_id]; | ||
253 | // room field should be the original room ID | ||
254 | map_area.locations.push_back( | ||
255 | {.name = panel.name, .room = panel.room, .panels = {panel.id}}); | ||
256 | } | ||
257 | } | ||
258 | |||
259 | for (const Door &door : doors_) { | ||
260 | if (!door.skip_location) { | ||
261 | int room_id = door.room; | ||
262 | std::string area_name = rooms_[room_id].name; | ||
263 | std::string section_name; | ||
264 | |||
265 | size_t divider_pos = door.location_name.find(" - "); | ||
266 | if (divider_pos == std::string::npos) { | ||
267 | section_name = door.location_name; | ||
268 | } else { | ||
269 | area_name = door.location_name.substr(0, divider_pos); | ||
270 | section_name = door.location_name.substr(divider_pos + 3); | ||
271 | } | ||
272 | |||
273 | if (fold_areas.count(area_name)) { | ||
274 | int fold_area_id = fold_areas[area_name]; | ||
275 | area_name = map_areas_[fold_area_id].name; | ||
276 | } | ||
277 | |||
278 | int area_id = AddOrGetArea(area_name); | ||
279 | MapArea &map_area = map_areas_[area_id]; | ||
280 | // room field should be the original room ID | ||
281 | map_area.locations.push_back( | ||
282 | {.name = section_name, .room = door.room, .panels = door.panels}); | ||
283 | } | ||
284 | } | ||
235 | } | 285 | } |
236 | 286 | ||
237 | int GameData::AddOrGetRoom(std::string room) { | 287 | int GameData::AddOrGetRoom(std::string room) { |
@@ -258,8 +308,10 @@ int GameData::AddOrGetPanel(std::string room, std::string panel) { | |||
258 | std::string full_name = room + " - " + panel; | 308 | std::string full_name = room + " - " + panel; |
259 | 309 | ||
260 | if (!panel_by_id_.count(full_name)) { | 310 | if (!panel_by_id_.count(full_name)) { |
261 | panel_by_id_[full_name] = panels_.size(); | 311 | int panel_id = panels_.size(); |
262 | panels_.push_back({.name = panel, .room = AddOrGetRoom(room)}); | 312 | panel_by_id_[full_name] = panel_id; |
313 | panels_.push_back( | ||
314 | {.id = panel_id, .name = panel, .room = AddOrGetRoom(room)}); | ||
263 | } | 315 | } |
264 | 316 | ||
265 | return panel_by_id_[full_name]; | 317 | return panel_by_id_[full_name]; |
@@ -267,9 +319,9 @@ int GameData::AddOrGetPanel(std::string room, std::string panel) { | |||
267 | 319 | ||
268 | int GameData::AddOrGetArea(std::string area) { | 320 | int GameData::AddOrGetArea(std::string area) { |
269 | if (!area_by_id_.count(area)) { | 321 | if (!area_by_id_.count(area)) { |
270 | area_by_id_[area] = map_areas_.size(); | 322 | int area_id = map_areas_.size(); |
271 | map_areas_.push_back( | 323 | area_by_id_[area] = area_id; |
272 | {.id = static_cast<int>(map_areas_.size()), .name = area}); | 324 | map_areas_.push_back({.id = area_id, .name = area}); |
273 | } | 325 | } |
274 | 326 | ||
275 | return area_by_id_[area]; | 327 | return area_by_id_[area]; |