diff options
Diffstat (limited to 'src/ipc_state.cpp')
-rw-r--r-- | src/ipc_state.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/ipc_state.cpp b/src/ipc_state.cpp index 18f318f..c0bdc9b 100644 --- a/src/ipc_state.cpp +++ b/src/ipc_state.cpp | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <mutex> | 9 | #include <mutex> |
10 | #include <nlohmann/json.hpp> | 10 | #include <nlohmann/json.hpp> |
11 | #include <optional> | 11 | #include <optional> |
12 | #include <set> | ||
12 | #include <string> | 13 | #include <string> |
13 | #include <thread> | 14 | #include <thread> |
14 | #include <tuple> | 15 | #include <tuple> |
@@ -35,6 +36,7 @@ struct IPCState { | |||
35 | std::string game_ap_user; | 36 | std::string game_ap_user; |
36 | 37 | ||
37 | std::optional<std::tuple<int, int>> player_position; | 38 | std::optional<std::tuple<int, int>> player_position; |
39 | std::set<std::string> solved_panels; | ||
38 | 40 | ||
39 | int backoff_amount = 0; | 41 | int backoff_amount = 0; |
40 | 42 | ||
@@ -77,6 +79,12 @@ struct IPCState { | |||
77 | return player_position; | 79 | return player_position; |
78 | } | 80 | } |
79 | 81 | ||
82 | const std::set<std::string>& GetSolvedPanels() { | ||
83 | std::lock_guard state_guard(state_mutex); | ||
84 | |||
85 | return solved_panels; | ||
86 | } | ||
87 | |||
80 | private: | 88 | private: |
81 | void Thread() { | 89 | void Thread() { |
82 | for (;;) { | 90 | for (;;) { |
@@ -137,7 +145,17 @@ struct IPCState { | |||
137 | } | 145 | } |
138 | } | 146 | } |
139 | 147 | ||
140 | void OnConnect() { connected = true; } | 148 | void OnConnect() { |
149 | connected = true; | ||
150 | |||
151 | { | ||
152 | std::lock_guard state_guard(state_mutex); | ||
153 | |||
154 | slot_matches = false; | ||
155 | player_position = std::nullopt; | ||
156 | solved_panels.clear(); | ||
157 | } | ||
158 | } | ||
141 | 159 | ||
142 | void OnClose() { | 160 | void OnClose() { |
143 | connected = false; | 161 | connected = false; |
@@ -168,6 +186,14 @@ struct IPCState { | |||
168 | std::make_tuple<int, int>(msg["position"]["x"], msg["position"]["z"]); | 186 | std::make_tuple<int, int>(msg["position"]["x"], msg["position"]["z"]); |
169 | 187 | ||
170 | tracker_frame->RedrawPosition(); | 188 | tracker_frame->RedrawPosition(); |
189 | } else if (msg["cmd"] == "SolvePanels") { | ||
190 | std::lock_guard state_guard(state_mutex); | ||
191 | |||
192 | for (std::string panel : msg["panels"]) { | ||
193 | solved_panels.insert(std::move(panel)); | ||
194 | } | ||
195 | |||
196 | tracker_frame->UpdateIndicators(kUPDATE_ONLY_PANELS); | ||
171 | } | 197 | } |
172 | } | 198 | } |
173 | 199 | ||
@@ -229,3 +255,7 @@ bool IPC_IsConnected() { return GetState().IsConnected(); } | |||
229 | std::optional<std::tuple<int, int>> IPC_GetPlayerPosition() { | 255 | std::optional<std::tuple<int, int>> IPC_GetPlayerPosition() { |
230 | return GetState().GetPlayerPosition(); | 256 | return GetState().GetPlayerPosition(); |
231 | } | 257 | } |
258 | |||
259 | const std::set<std::string>& IPC_GetSolvedPanels() { | ||
260 | return GetState().GetSolvedPanels(); | ||
261 | } | ||