diff options
Diffstat (limited to 'src/ap_state.cpp')
| -rw-r--r-- | src/ap_state.cpp | 60 |
1 files changed, 40 insertions, 20 deletions
| diff --git a/src/ap_state.cpp b/src/ap_state.cpp index 1ac6575..aeed914 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp | |||
| @@ -27,7 +27,7 @@ | |||
| 27 | 27 | ||
| 28 | constexpr int AP_MAJOR = 0; | 28 | constexpr int AP_MAJOR = 0; |
| 29 | constexpr int AP_MINOR = 4; | 29 | constexpr int AP_MINOR = 4; |
| 30 | constexpr int AP_REVISION = 0; | 30 | constexpr int AP_REVISION = 5; |
| 31 | 31 | ||
| 32 | constexpr const char* CERT_STORE_PATH = "cacert.pem"; | 32 | constexpr const char* CERT_STORE_PATH = "cacert.pem"; |
| 33 | constexpr int ITEM_HANDLING = 7; // <- all | 33 | constexpr int ITEM_HANDLING = 7; // <- all |
| @@ -54,6 +54,7 @@ struct APState { | |||
| 54 | std::map<int64_t, int> inventory; | 54 | std::map<int64_t, int> inventory; |
| 55 | std::set<int64_t> checked_locations; | 55 | std::set<int64_t> checked_locations; |
| 56 | std::map<std::string, std::any> data_storage; | 56 | std::map<std::string, std::any> data_storage; |
| 57 | std::optional<std::tuple<int, int>> player_pos; | ||
| 57 | 58 | ||
| 58 | DoorShuffleMode door_shuffle_mode = kNO_DOORS; | 59 | DoorShuffleMode door_shuffle_mode = kNO_DOORS; |
| 59 | bool color_shuffle = false; | 60 | bool color_shuffle = false; |
| @@ -101,6 +102,8 @@ struct APState { | |||
| 101 | } | 102 | } |
| 102 | } | 103 | } |
| 103 | 104 | ||
| 105 | tracked_data_storage_keys.push_back("PlayerPos"); | ||
| 106 | |||
| 104 | initialized = true; | 107 | initialized = true; |
| 105 | } | 108 | } |
| 106 | 109 | ||
| @@ -128,6 +131,7 @@ struct APState { | |||
| 128 | inventory.clear(); | 131 | inventory.clear(); |
| 129 | checked_locations.clear(); | 132 | checked_locations.clear(); |
| 130 | data_storage.clear(); | 133 | data_storage.clear(); |
| 134 | player_pos = std::nullopt; | ||
| 131 | victory_data_storage_key.clear(); | 135 | victory_data_storage_key.clear(); |
| 132 | door_shuffle_mode = kNO_DOORS; | 136 | door_shuffle_mode = kNO_DOORS; |
| 133 | color_shuffle = false; | 137 | color_shuffle = false; |
| @@ -199,15 +203,7 @@ struct APState { | |||
| 199 | apclient->set_retrieved_handler( | 203 | apclient->set_retrieved_handler( |
| 200 | [this](const std::map<std::string, nlohmann::json>& data) { | 204 | [this](const std::map<std::string, nlohmann::json>& data) { |
| 201 | for (const auto& [key, value] : data) { | 205 | for (const auto& [key, value] : data) { |
| 202 | if (value.is_boolean()) { | 206 | HandleDataStorage(key, value); |
| 203 | data_storage[key] = value.get<bool>(); | ||
| 204 | TrackerLog("Data storage " + key + " retrieved as " + | ||
| 205 | (value.get<bool>() ? "true" : "false")); | ||
| 206 | } else if (value.is_number()) { | ||
| 207 | data_storage[key] = value.get<int>(); | ||
| 208 | TrackerLog("Data storage " + key + " retrieved as " + | ||
| 209 | std::to_string(value.get<int>())); | ||
| 210 | } | ||
| 211 | } | 207 | } |
| 212 | 208 | ||
| 213 | RefreshTracker(); | 209 | RefreshTracker(); |
| @@ -216,16 +212,7 @@ struct APState { | |||
| 216 | apclient->set_set_reply_handler([this](const std::string& key, | 212 | apclient->set_set_reply_handler([this](const std::string& key, |
| 217 | const nlohmann::json& value, | 213 | const nlohmann::json& value, |
| 218 | const nlohmann::json&) { | 214 | const nlohmann::json&) { |
| 219 | if (value.is_boolean()) { | 215 | HandleDataStorage(key, value); |
| 220 | data_storage[key] = value.get<bool>(); | ||
| 221 | TrackerLog("Data storage " + key + " retrieved as " + | ||
| 222 | (value.get<bool>() ? "true" : "false")); | ||
| 223 | } else if (value.is_number()) { | ||
| 224 | data_storage[key] = value.get<int>(); | ||
| 225 | TrackerLog("Data storage " + key + " retrieved as " + | ||
| 226 | std::to_string(value.get<int>())); | ||
| 227 | } | ||
| 228 | |||
| 229 | RefreshTracker(); | 216 | RefreshTracker(); |
| 230 | }); | 217 | }); |
| 231 | 218 | ||
| @@ -369,6 +356,35 @@ struct APState { | |||
| 369 | } | 356 | } |
| 370 | } | 357 | } |
| 371 | 358 | ||
| 359 | void HandleDataStorage(const std::string& key, const nlohmann::json& value) { | ||
| 360 | if (value.is_boolean()) { | ||
| 361 | data_storage[key] = value.get<bool>(); | ||
| 362 | TrackerLog("Data storage " + key + " retrieved as " + | ||
| 363 | (value.get<bool>() ? "true" : "false")); | ||
| 364 | } else if (value.is_number()) { | ||
| 365 | data_storage[key] = value.get<int>(); | ||
| 366 | TrackerLog("Data storage " + key + " retrieved as " + | ||
| 367 | std::to_string(value.get<int>())); | ||
| 368 | } else if (value.is_object()) { | ||
| 369 | if (key.ends_with("PlayerPos")) { | ||
| 370 | auto map_value = value.get<std::map<std::string, int>>(); | ||
| 371 | player_pos = std::tuple<int, int>(map_value["x"], map_value["z"]); | ||
| 372 | } else { | ||
| 373 | data_storage[key] = value.get<std::map<std::string, int>>(); | ||
| 374 | } | ||
| 375 | |||
| 376 | TrackerLog("Data storage " + key + " retrieved as dictionary"); | ||
| 377 | } else if (value.is_null()) { | ||
| 378 | if (key.ends_with("PlayerPos")) { | ||
| 379 | player_pos = std::nullopt; | ||
| 380 | } else { | ||
| 381 | data_storage.erase(key); | ||
| 382 | } | ||
| 383 | |||
| 384 | TrackerLog("Data storage " + key + " retrieved as null"); | ||
| 385 | } | ||
| 386 | } | ||
| 387 | |||
| 372 | bool HasCheckedGameLocation(int location_id) { | 388 | bool HasCheckedGameLocation(int location_id) { |
| 373 | return checked_locations.count(location_id); | 389 | return checked_locations.count(location_id); |
| 374 | } | 390 | } |
| @@ -498,3 +514,7 @@ const std::map<int, SunwarpMapping>& AP_GetSunwarpMapping() { | |||
| 498 | } | 514 | } |
| 499 | 515 | ||
| 500 | bool AP_HasReachedGoal() { return GetState().HasReachedGoal(); } | 516 | bool AP_HasReachedGoal() { return GetState().HasReachedGoal(); } |
| 517 | |||
| 518 | std::optional<std::tuple<int, int>> AP_GetPlayerPosition() { | ||
| 519 | return GetState().player_pos; | ||
| 520 | } | ||
