about summary refs log tree commit diff stats
path: root/src/ap_state.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-04-03 14:33:30 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2024-04-03 14:33:30 -0400
commit3037b9305b10b58e01055c21bbce223d7b2c673f (patch)
treeebe7d5c88906c45b0b494955aef21e0a7756fa49 /src/ap_state.cpp
parente57195bfd9d84a571e8fa11998af5065848b4360 (diff)
downloadlingo-ap-tracker-3037b9305b10b58e01055c21bbce223d7b2c673f.tar.gz
lingo-ap-tracker-3037b9305b10b58e01055c21bbce223d7b2c673f.tar.bz2
lingo-ap-tracker-3037b9305b10b58e01055c21bbce223d7b2c673f.zip
Added player position tracking
Diffstat (limited to 'src/ap_state.cpp')
-rw-r--r--src/ap_state.cpp58
1 files changed, 39 insertions, 19 deletions
diff --git a/src/ap_state.cpp b/src/ap_state.cpp index 8134cdb..58670e6 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp
@@ -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;
@@ -95,6 +96,8 @@ struct APState {
95 } 96 }
96 } 97 }
97 98
99 tracked_data_storage_keys.push_back("PlayerPos");
100
98 initialized = true; 101 initialized = true;
99 } 102 }
100 103
@@ -122,6 +125,7 @@ struct APState {
122 inventory.clear(); 125 inventory.clear();
123 checked_locations.clear(); 126 checked_locations.clear();
124 data_storage.clear(); 127 data_storage.clear();
128 player_pos = std::nullopt;
125 victory_data_storage_key.clear(); 129 victory_data_storage_key.clear();
126 door_shuffle_mode = kNO_DOORS; 130 door_shuffle_mode = kNO_DOORS;
127 color_shuffle = false; 131 color_shuffle = false;
@@ -187,15 +191,7 @@ struct APState {
187 apclient->set_retrieved_handler( 191 apclient->set_retrieved_handler(
188 [this](const std::map<std::string, nlohmann::json>& data) { 192 [this](const std::map<std::string, nlohmann::json>& data) {
189 for (const auto& [key, value] : data) { 193 for (const auto& [key, value] : data) {
190 if (value.is_boolean()) { 194 HandleDataStorage(key, value);
191 data_storage[key] = value.get<bool>();
192 TrackerLog("Data storage " + key + " retrieved as " +
193 (value.get<bool>() ? "true" : "false"));
194 } else if (value.is_number()) {
195 data_storage[key] = value.get<int>();
196 TrackerLog("Data storage " + key + " retrieved as " +
197 std::to_string(value.get<int>()));
198 }
199 } 195 }
200 196
201 RefreshTracker(); 197 RefreshTracker();
@@ -204,16 +200,7 @@ struct APState {
204 apclient->set_set_reply_handler([this](const std::string& key, 200 apclient->set_set_reply_handler([this](const std::string& key,
205 const nlohmann::json& value, 201 const nlohmann::json& value,
206 const nlohmann::json&) { 202 const nlohmann::json&) {
207 if (value.is_boolean()) { 203 HandleDataStorage(key, value);
208 data_storage[key] = value.get<bool>();
209 TrackerLog("Data storage " + key + " retrieved as " +
210 (value.get<bool>() ? "true" : "false"));
211 } else if (value.is_number()) {
212 data_storage[key] = value.get<int>();
213 TrackerLog("Data storage " + key + " retrieved as " +
214 std::to_string(value.get<int>()));
215 }
216
217 RefreshTracker(); 204 RefreshTracker();
218 }); 205 });
219 206
@@ -335,6 +322,35 @@ struct APState {
335 } 322 }
336 } 323 }
337 324
325 void HandleDataStorage(const std::string& key, const nlohmann::json& value) {
326 if (value.is_boolean()) {
327 data_storage[key] = value.get<bool>();
328 TrackerLog("Data storage " + key + " retrieved as " +
329 (value.get<bool>() ? "true" : "false"));
330 } else if (value.is_number()) {
331 data_storage[key] = value.get<int>();
332 TrackerLog("Data storage " + key + " retrieved as " +
333 std::to_string(value.get<int>()));
334 } else if (value.is_object()) {
335 if (key.ends_with("PlayerPos")) {
336 auto map_value = value.get<std::map<std::string, int>>();
337 player_pos = std::tuple<int, int>(map_value["x"], map_value["z"]);
338 } else {
339 data_storage[key] = value.get<std::map<std::string, int>>();
340 }
341
342 TrackerLog("Data storage " + key + " retrieved as dictionary");
343 } else if (value.is_null()) {
344 if (key.ends_with("PlayerPos")) {
345 player_pos = std::nullopt;
346 } else {
347 data_storage.erase(key);
348 }
349
350 TrackerLog("Data storage " + key + " retrieved as null");
351 }
352 }
353
338 bool HasCheckedGameLocation(int location_id) { 354 bool HasCheckedGameLocation(int location_id) {
339 return checked_locations.count(location_id); 355 return checked_locations.count(location_id);
340 } 356 }
@@ -446,3 +462,7 @@ bool AP_HasAchievement(const std::string& achievement_name) {
446bool AP_HasEarlyColorHallways() { return GetState().early_color_hallways; } 462bool AP_HasEarlyColorHallways() { return GetState().early_color_hallways; }
447 463
448bool AP_HasReachedGoal() { return GetState().HasReachedGoal(); } 464bool AP_HasReachedGoal() { return GetState().HasReachedGoal(); }
465
466std::optional<std::tuple<int, int>> AP_GetPlayerPosition() {
467 return GetState().player_pos;
468}