From 9f25878acfe1c7281a96f83742349516510c5b6d Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 2 May 2023 10:07:25 -0400 Subject: Added areas to map --- game_data.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'game_data.cpp') diff --git a/game_data.cpp b/game_data.cpp index 0ae5468..f377e0b 100644 --- a/game_data.cpp +++ b/game_data.cpp @@ -217,6 +217,21 @@ GameData::GameData() { } } } + + map_areas_.reserve(areas_config.size()); + + std::map fold_areas; + for (const auto &area_it : areas_config) { + if (area_it.second["map"]) { + int area_id = AddOrGetArea(area_it.first.as()); + MapArea &area_obj = map_areas_[area_id]; + area_obj.map_x = area_it.second["map"][0].as(); + area_obj.map_y = area_it.second["map"][1].as(); + } else if (area_it.second["fold_into"]) { + fold_areas[area_it.first.as()] = + AddOrGetArea(area_it.second["fold_into"].as()); + } + } } int GameData::AddOrGetRoom(std::string room) { @@ -250,6 +265,16 @@ int GameData::AddOrGetPanel(std::string room, std::string panel) { return panel_by_id_[full_name]; } +int GameData::AddOrGetArea(std::string area) { + if (!area_by_id_.count(area)) { + area_by_id_[area] = map_areas_.size(); + map_areas_.push_back( + {.id = static_cast(map_areas_.size()), .name = area}); + } + + return area_by_id_[area]; +} + const GameData &GetGameData() { static GameData *instance = new GameData(); return *instance; -- cgit 1.4.1