-
Notifications
You must be signed in to change notification settings - Fork 1
/
NodeQueue.cpp
121 lines (90 loc) · 3.25 KB
/
NodeQueue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* LevelAPI - Geometry Dash level cacher with search functionality and more.
Copyright (C) 2023 Sergei Baigerov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "lapi_database.h"
#include <vector>
#include "Tools.h"
using namespace LevelAPI::DatabaseController;
NodeQueue::NodeQueue(const NodeCommandQueue &q, bool executeQueue, int runtimeState) {
m_vCommandQueue.push_back(q);
m_bExecuteQueue = executeQueue;
m_nRuntimeState = runtimeState;
currentState = NC_IDLE;
setupJSON();
_jsonObject["commandQueue"].push_back(q);
_jsonObject["executeQueue"] = executeQueue;
_jsonObject["runtimeState"] = runtimeState;
}
NodeQueue::NodeQueue(const std::vector<NodeCommandQueue> &vec, bool executeQueue, int runtimeState) {
m_vCommandQueue = vec;
m_bExecuteQueue = executeQueue;
m_nRuntimeState = runtimeState;
currentState = NC_IDLE;
setupJSON();
_jsonObject["commandQueue"] = nlohmann::json::array();
for (const NodeCommandQueue &q : m_vCommandQueue) {
_jsonObject["commandQueue"].push_back(q);
}
_jsonObject["executeQueue"] = executeQueue;
_jsonObject["runtimeState"] = runtimeState;
}
NodeQueue::NodeQueue(bool executeQueue, int runtimeState) {
m_bExecuteQueue = executeQueue;
m_nRuntimeState = runtimeState;
currentState = NC_IDLE;
setupJSON();
save();
}
NodeQueue::NodeQueue() {
m_bExecuteQueue = false;
m_nRuntimeState = 0;
currentState = NC_IDLE;
setupJSON();
save();
// NodeQueue(false, 0);
}
void NodeQueue::save() {
_jsonObject["commandQueue"].clear();
_jsonObject["executeQueue"] = m_bExecuteQueue;
_jsonObject["runtimeState"] = m_nRuntimeState;
_jsonObject["resolverQueue"] = m_vResolverQueuedLevels;
// printf("rsize: %d %d\n", _jsonObject["resolverQueue"].size(), m_vResolverQueuedLevels.size());
int i = 0;
for (NodeCommandQueue &q : m_vCommandQueue) {
q.save();
_jsonObject["commandQueue"].push_back(q);
}
}
void NodeQueue::recover() {
GET_JSON_VALUE(_jsonObject, "executeQueue", m_bExecuteQueue, bool);
GET_JSON_VALUE(_jsonObject, "runtimeState", m_nRuntimeState, int);
int i = 0;
while(i < _jsonObject["commandQueue"].size()) {
NodeCommandQueue cmd;
cmd._jsonObject = _jsonObject["commandQueue"].at(i);
cmd.recover();
m_vCommandQueue.push_back(cmd);
i++;
}
i = 0;
while(i < _jsonObject["resolverQueue"].size()) {
m_vResolverQueuedLevels.push_back(_jsonObject["resolverQueue"].at(i).get<int>());
i++;
}
}
void NodeQueue::setupJSON() {
_jsonObject = nlohmann::json();
}
NodeQueue::~NodeQueue() {
}