diff options
Diffstat (limited to 'src/game_data.cpp')
-rw-r--r-- | src/game_data.cpp | 89 |
1 files changed, 56 insertions, 33 deletions
diff --git a/src/game_data.cpp b/src/game_data.cpp index a4a441d..a5af66b 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp | |||
@@ -12,32 +12,6 @@ | |||
12 | 12 | ||
13 | namespace { | 13 | namespace { |
14 | 14 | ||
15 | LingoColor GetColorForString(const std::string &str) { | ||
16 | if (str == "black") { | ||
17 | return LingoColor::kBlack; | ||
18 | } else if (str == "red") { | ||
19 | return LingoColor::kRed; | ||
20 | } else if (str == "blue") { | ||
21 | return LingoColor::kBlue; | ||
22 | } else if (str == "yellow") { | ||
23 | return LingoColor::kYellow; | ||
24 | } else if (str == "orange") { | ||
25 | return LingoColor::kOrange; | ||
26 | } else if (str == "green") { | ||
27 | return LingoColor::kGreen; | ||
28 | } else if (str == "gray") { | ||
29 | return LingoColor::kGray; | ||
30 | } else if (str == "brown") { | ||
31 | return LingoColor::kBrown; | ||
32 | } else if (str == "purple") { | ||
33 | return LingoColor::kPurple; | ||
34 | } else { | ||
35 | TrackerLog(fmt::format("Invalid color: {}", str)); | ||
36 | |||
37 | return LingoColor::kNone; | ||
38 | } | ||
39 | } | ||
40 | |||
41 | struct GameData { | 15 | struct GameData { |
42 | std::vector<Room> rooms_; | 16 | std::vector<Room> rooms_; |
43 | std::vector<Door> doors_; | 17 | std::vector<Door> doors_; |
@@ -59,6 +33,7 @@ struct GameData { | |||
59 | 33 | ||
60 | std::map<std::string, int> room_by_painting_; | 34 | std::map<std::string, int> room_by_painting_; |
61 | std::map<int, int> room_by_sunwarp_; | 35 | std::map<int, int> room_by_sunwarp_; |
36 | std::map<int, int> panel_by_solve_index_; | ||
62 | 37 | ||
63 | std::vector<int> achievement_panels_; | 38 | std::vector<int> achievement_panels_; |
64 | 39 | ||
@@ -84,7 +59,7 @@ struct GameData { | |||
84 | ids_config["special_items"][color_name]) { | 59 | ids_config["special_items"][color_name]) { |
85 | std::string input_name = color_name; | 60 | std::string input_name = color_name; |
86 | input_name[0] = std::tolower(input_name[0]); | 61 | input_name[0] = std::tolower(input_name[0]); |
87 | ap_id_by_color_[GetColorForString(input_name)] = | 62 | ap_id_by_color_[GetLingoColorForString(input_name)] = |
88 | ids_config["special_items"][color_name].as<int>(); | 63 | ids_config["special_items"][color_name].as<int>(); |
89 | } else { | 64 | } else { |
90 | TrackerLog(fmt::format("Missing AP item ID for color {}", color_name)); | 65 | TrackerLog(fmt::format("Missing AP item ID for color {}", color_name)); |
@@ -103,6 +78,8 @@ struct GameData { | |||
103 | 78 | ||
104 | rooms_.reserve(lingo_config.size() * 2); | 79 | rooms_.reserve(lingo_config.size() * 2); |
105 | 80 | ||
81 | std::vector<int> panel_location_ids; | ||
82 | |||
106 | for (const auto &room_it : lingo_config) { | 83 | for (const auto &room_it : lingo_config) { |
107 | int room_id = AddOrGetRoom(room_it.first.as<std::string>()); | 84 | int room_id = AddOrGetRoom(room_it.first.as<std::string>()); |
108 | room_definition_order_.push_back(room_id); | 85 | room_definition_order_.push_back(room_id); |
@@ -181,12 +158,12 @@ struct GameData { | |||
181 | 158 | ||
182 | if (panel_it.second["colors"]) { | 159 | if (panel_it.second["colors"]) { |
183 | if (panel_it.second["colors"].IsScalar()) { | 160 | if (panel_it.second["colors"].IsScalar()) { |
184 | panels_[panel_id].colors.push_back(GetColorForString( | 161 | panels_[panel_id].colors.push_back(GetLingoColorForString( |
185 | panel_it.second["colors"].as<std::string>())); | 162 | panel_it.second["colors"].as<std::string>())); |
186 | } else { | 163 | } else { |
187 | for (const auto &color_node : panel_it.second["colors"]) { | 164 | for (const auto &color_node : panel_it.second["colors"]) { |
188 | panels_[panel_id].colors.push_back( | 165 | panels_[panel_id].colors.push_back( |
189 | GetColorForString(color_node.as<std::string>())); | 166 | GetLingoColorForString(color_node.as<std::string>())); |
190 | } | 167 | } |
191 | } | 168 | } |
192 | } | 169 | } |
@@ -292,10 +269,11 @@ struct GameData { | |||
292 | ids_config["panels"][rooms_[room_id].name] && | 269 | ids_config["panels"][rooms_[room_id].name] && |
293 | ids_config["panels"][rooms_[room_id].name] | 270 | ids_config["panels"][rooms_[room_id].name] |
294 | [panels_[panel_id].name]) { | 271 | [panels_[panel_id].name]) { |
295 | panels_[panel_id].ap_location_id = | 272 | int location_id = ids_config["panels"][rooms_[room_id].name] |
296 | ids_config["panels"][rooms_[room_id].name] | 273 | [panels_[panel_id].name] |
297 | [panels_[panel_id].name] | 274 | .as<int>(); |
298 | .as<int>(); | 275 | panels_[panel_id].ap_location_id = location_id; |
276 | panel_location_ids.push_back(location_id); | ||
299 | } else { | 277 | } else { |
300 | TrackerLog(fmt::format("Missing AP location ID for panel {} - {}", | 278 | TrackerLog(fmt::format("Missing AP location ID for panel {} - {}", |
301 | rooms_[room_id].name, | 279 | rooms_[room_id].name, |
@@ -589,6 +567,21 @@ struct GameData { | |||
589 | } | 567 | } |
590 | } | 568 | } |
591 | 569 | ||
570 | // Determine the panel solve indices from the sorted location IDs. | ||
571 | std::sort(panel_location_ids.begin(), panel_location_ids.end()); | ||
572 | |||
573 | std::map<int, int> solve_index_by_location_id; | ||
574 | for (int i = 0; i < panel_location_ids.size(); i++) { | ||
575 | solve_index_by_location_id[panel_location_ids[i]] = i; | ||
576 | } | ||
577 | |||
578 | for (Panel &panel : panels_) { | ||
579 | if (panel.ap_location_id != -1) { | ||
580 | panel.solve_index = solve_index_by_location_id[panel.ap_location_id]; | ||
581 | panel_by_solve_index_[panel.solve_index] = panel.id; | ||
582 | } | ||
583 | } | ||
584 | |||
592 | map_areas_.reserve(areas_config.size()); | 585 | map_areas_.reserve(areas_config.size()); |
593 | 586 | ||
594 | std::map<std::string, int> fold_areas; | 587 | std::map<std::string, int> fold_areas; |
@@ -964,6 +957,10 @@ const Panel &GD_GetPanel(int panel_id) { | |||
964 | return GetState().panels_.at(panel_id); | 957 | return GetState().panels_.at(panel_id); |
965 | } | 958 | } |
966 | 959 | ||
960 | int GD_GetPanelBySolveIndex(int solve_index) { | ||
961 | return GetState().panel_by_solve_index_.at(solve_index); | ||
962 | } | ||
963 | |||
967 | const std::vector<PaintingExit> &GD_GetPaintings() { | 964 | const std::vector<PaintingExit> &GD_GetPaintings() { |
968 | return GetState().paintings_; | 965 | return GetState().paintings_; |
969 | } | 966 | } |
@@ -1010,3 +1007,29 @@ std::optional<int> GD_GetSubwayItemForPainting(const std::string &painting_id) { | |||
1010 | int GD_GetSubwayItemForSunwarp(const SubwaySunwarp &sunwarp) { | 1007 | int GD_GetSubwayItemForSunwarp(const SubwaySunwarp &sunwarp) { |
1011 | return GetState().subway_item_by_sunwarp_.at(sunwarp); | 1008 | return GetState().subway_item_by_sunwarp_.at(sunwarp); |
1012 | } | 1009 | } |
1010 | |||
1011 | LingoColor GetLingoColorForString(const std::string &str) { | ||
1012 | if (str == "black") { | ||
1013 | return LingoColor::kBlack; | ||
1014 | } else if (str == "red") { | ||
1015 | return LingoColor::kRed; | ||
1016 | } else if (str == "blue") { | ||
1017 | return LingoColor::kBlue; | ||
1018 | } else if (str == "yellow") { | ||
1019 | return LingoColor::kYellow; | ||
1020 | } else if (str == "orange") { | ||
1021 | return LingoColor::kOrange; | ||
1022 | } else if (str == "green") { | ||
1023 | return LingoColor::kGreen; | ||
1024 | } else if (str == "gray") { | ||
1025 | return LingoColor::kGray; | ||
1026 | } else if (str == "brown") { | ||
1027 | return LingoColor::kBrown; | ||
1028 | } else if (str == "purple") { | ||
1029 | return LingoColor::kPurple; | ||
1030 | } else { | ||
1031 | TrackerLog(fmt::format("Invalid color: {}", str)); | ||
1032 | |||
1033 | return LingoColor::kNone; | ||
1034 | } | ||
1035 | } | ||