about summary refs log tree commit diff stats
path: root/ap_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ap_state.cpp')
-rw-r--r--ap_state.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/ap_state.cpp b/ap_state.cpp index 4d7ddb7..9df487f 100644 --- a/ap_state.cpp +++ b/ap_state.cpp
@@ -9,6 +9,7 @@
9#include <thread> 9#include <thread>
10 10
11#include "game_data.h" 11#include "game_data.h"
12#include "tracker_state.h"
12 13
13constexpr int AP_MAJOR = 0; 14constexpr int AP_MAJOR = 0;
14constexpr int AP_MINOR = 4; 15constexpr int AP_MINOR = 4;
@@ -16,6 +17,11 @@ constexpr int AP_REVISION = 0;
16 17
17constexpr int ITEM_HANDLING = 7; // <- all 18constexpr int ITEM_HANDLING = 7; // <- all
18 19
20NLOHMANN_JSON_SERIALIZE_ENUM(DoorShuffleMode,
21 {{DoorShuffleMode::kNone, "none"},
22 {DoorShuffleMode::kSimple, "simple"},
23 {DoorShuffleMode::kComplex, "complex"}});
24
19APState::APState() { 25APState::APState() {
20 std::thread([this]() { 26 std::thread([this]() {
21 for (;;) { 27 for (;;) {
@@ -92,6 +98,9 @@ void APState::Connect(std::string server, std::string player,
92 apclient_->set_slot_connected_handler([&](const nlohmann::json& slot_data) { 98 apclient_->set_slot_connected_handler([&](const nlohmann::json& slot_data) {
93 tracker_frame_->SetStatusMessage("Connected to Archipelago!"); 99 tracker_frame_->SetStatusMessage("Connected to Archipelago!");
94 100
101 door_shuffle_mode_ = slot_data["shuffle_doors"].get<DoorShuffleMode>();
102 color_shuffle_ = slot_data["shuffle_colors"].get<bool>();
103
95 connected = true; 104 connected = true;
96 has_connection_result = true; 105 has_connection_result = true;
97 }); 106 });
@@ -169,6 +178,16 @@ void APState::Connect(std::string server, std::string player,
169 } 178 }
170 } 179 }
171 180
181 ap_id_by_color_[LingoColor::kBlack] = GetItemId("Black");
182 ap_id_by_color_[LingoColor::kRed] = GetItemId("Red");
183 ap_id_by_color_[LingoColor::kBlue] = GetItemId("Blue");
184 ap_id_by_color_[LingoColor::kYellow] = GetItemId("Yellow");
185 ap_id_by_color_[LingoColor::kPurple] = GetItemId("Purple");
186 ap_id_by_color_[LingoColor::kOrange] = GetItemId("Orange");
187 ap_id_by_color_[LingoColor::kGreen] = GetItemId("Green");
188 ap_id_by_color_[LingoColor::kBrown] = GetItemId("Brown");
189 ap_id_by_color_[LingoColor::kGray] = GetItemId("Gray");
190
172 RefreshTracker(); 191 RefreshTracker();
173 } else { 192 } else {
174 client_active_ = false; 193 client_active_ = false;
@@ -185,7 +204,27 @@ bool APState::HasCheckedGameLocation(int area_id, int section_id) const {
185 } 204 }
186} 205}
187 206
188void APState::RefreshTracker() { tracker_frame_->UpdateIndicators(); } 207bool APState::HasColorItem(LingoColor color) const {
208 if (ap_id_by_color_.count(color)) {
209 return inventory_.count(ap_id_by_color_.at(color));
210 } else {
211 return false;
212 }
213}
214
215void APState::RefreshTracker() {
216 GetTrackerState().CalculateState();
217 tracker_frame_->UpdateIndicators();
218}
219
220int64_t APState::GetItemId(const std::string& item_name) {
221 int64_t ap_id = apclient_->get_item_id(item_name);
222 if (ap_id == APClient::INVALID_NAME_ID) {
223 std::cout << "Could not find AP item ID for " << item_name << std::endl;
224 }
225
226 return ap_id;
227}
189 228
190APState& GetAPState() { 229APState& GetAPState() {
191 static APState* instance = new APState(); 230 static APState* instance = new APState();