-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggleStacker.cpp
More file actions
291 lines (259 loc) · 8.41 KB
/
ToggleStacker.cpp
File metadata and controls
291 lines (259 loc) · 8.41 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#include "stdafx.h"
#include "ToggleStacker.h"
#include <Spore/App/cPropManager.h>
#include <Spore\Properties.h>
#include <unordered_map>
using namespace UTFWin;
enum class Mode {
DEFAULT,
STACK_ALL,
STACK_NONE,
STACK_NO_BASE,
};
Mode currentMode = Mode::DEFAULT;
struct CustomModeEntry {
EditorRigblockPtr part;
Mode mode;
};
vector<ToggleStacker::CustomModeEntry> customModeParts;
ToggleStacker::ToggleStacker()
{
App::AddUpdateFunction(this);
}
ToggleStacker::~ToggleStacker()
{
}
void ToggleStacker::Update()
{
static const vector<ResourceKey> notInteractKeys = {
// Creature parts
{id("nose"), 0x0, id("creature")},
{id("eye"), 0x0, id("creature")},
{id("antenna"), 0x0, id("creature")},
{id("ear"), 0x0, id("creature")},
{id("detail"), 0x0, id("creature")},
{id("fin"), 0x0, id("creature")},
{id("wing"), 0x0, id("creature")},
{id("weapon"), 0x0, id("creature")},
{id("foot"), 0x0, id("creature")},
{id("grasper"), 0x0, id("creature")},
{id("mouth"), 0x0, id("creature")},
// Flora parts
{id("cap"), 0x0, id("plant")},
{id("fruit"), 0x0, id("plant")},
{id("leaf"), 0x0, id("plant")},
// Outfitter parts
{id("shoulderpad"), 0x0, id("tribal")},
{id("hat"), 0x0, id("tribal")},
{id("mask"), 0x0, id("tribal")},
{id("collar"), 0x0, id("tribal")},
{id("feather"), 0x0, id("tribal")},
{id("horn"), 0x0, id("tribal")},
{id("symbol"), 0x0, id("tribal")},
// Vehicle parts
{id("wing"), 0x0, id("vehicle")},
{id("window"), 0x0, id("vehicle")},
{id("wheel"), 0x0, id("vehicle")},
{id("weapon"), 0x0, id("vehicle")},
{id("ski"), 0x0, id("vehicle")},
{id("sail"), 0x0, id("vehicle")},
{id("ringpop"), 0x0, id("vehicle")},
{id("propeller"), 0x0, id("vehicle")},
{id("paddle"), 0x0, id("vehicle")},
{id("medallion"), 0x0, id("vehicle")},
{id("light"), 0x0, id("vehicle")},
{id("jetengine"), 0x0, id("vehicle")},
{id("flag"), 0x0, id("vehicle")},
{id("detail"), 0x0, id("vehicle")},
{id("Cultural"), 0x0, id("vehicle")},
{id("balloon"), 0x0, id("vehicle")},
// Building parts
{id("window"), 0x0, id("building")},
{id("detail"), 0x0, id("building")},
{id("stair"), 0x0, id("building")},
{id("floor"), 0x0, id("building")},
{id("door"), 0x0, id("building")},
{id("chimney"), 0x0, id("building")},
{id("balcony"), 0x0, id("building")}
};
if (!Editor.IsMode(Editors::Mode::BuildMode) || Editor.GetEditorModel() == nullptr) {
customModeParts.clear();
return;
}
for each (EditorRigblockPtr part in Editor.GetEditorModel()->mRigblocks)
{
part->mModelTypesNotToInteractWith.clear();
part->mModelTypesToInteractWith.clear();
switch (currentMode)
{
case Mode::DEFAULT:
{
PropertyListPtr propList = part->mpPropList;
vector<ResourceKey> notInteractNames;
App::Property::GetArrayKey(propList.get(), 0x044DCD0A, notInteractNames);
for each (ResourceKey name in notInteractNames) {
part->mModelTypesNotToInteractWith.push_back(name);
}
vector<ResourceKey> interactNames;
App::Property::GetArrayKey(propList.get(), 0x6FFDED92, interactNames);
for each (ResourceKey name in interactNames) {
part->mModelTypesToInteractWith.push_back(name);
}
break;
}
case Mode::STACK_ALL:
break;
case Mode::STACK_NONE:
{
for (const ResourceKey& key : notInteractKeys)
{
part->mModelTypesNotToInteractWith.push_back(key);
}
break;
}
case Mode::CUSTOM:
break;
default:
break;
}
}
for each (ToggleStacker::CustomModeEntry entry in customModeParts)
{
EditorRigblockPtr part = entry.part;
Mode mode = entry.mode;
part->mModelTypesNotToInteractWith.clear();
part->mModelTypesToInteractWith.clear();
switch (entry.mode) {
case Mode::DEFAULT:
{
PropertyListPtr propList = part->mpPropList;
vector<ResourceKey> notInteractNames;
App::Property::GetArrayKey(propList.get(), 0x044DCD0A, notInteractNames);
for each (ResourceKey name in notInteractNames) {
part->mModelTypesNotToInteractWith.push_back(name);
}
vector<ResourceKey> interactNames;
App::Property::GetArrayKey(propList.get(), 0x6FFDED92, interactNames);
for each (ResourceKey name in interactNames) {
part->mModelTypesToInteractWith.push_back(name);
}
break;
}
case Mode::STACK_ALL:
break;
case Mode::STACK_NONE:
{
for (const ResourceKey& key : notInteractKeys)
{
part->mModelTypesNotToInteractWith.push_back(key);
}
break;
}
case Mode::CUSTOM:
break;
default:
break;
}
}
}
void ToggleStacker::ParseLine(const ArgScript::Line& line)
{
auto mode = line.GetOption("mode", 1);
auto custom = line.GetOption("custom", 1);
if (mode != nullptr) {
std::string m = mode[0];
if (m == "all" || m == "stack" || m == "yes") {
currentMode = Mode::STACK_ALL;
App::ConsolePrintF("ToggleStacker activated (STACK_ALL), all parts will now stack.");
}
else if (m == "none" || m == "unstack" || m == "no") {
currentMode = Mode::STACK_NONE;
App::ConsolePrintF("ToggleStacker activated (STACK_NONE), no parts will stack.");
}
else if (m == "default" || m == "deactivate" || m == "off" || m == "false") {
currentMode = Mode::DEFAULT;
App::ConsolePrintF("ToggleStacker deactivated (DEFAULT), default behavior restored.");
}
else {
App::ConsolePrintF("Unknown Togglestacker mode. Avaliable modes: 'all / stack / yes', 'none / unstack / no', 'default / deactivate / off / false'.");
}
}
if (custom != nullptr) {
if (!Editor.IsMode(Editors::Mode::BuildMode) || Editor.GetEditorModel() == nullptr) {
App::ConsolePrintF("Use this option in the editor while hovering or selecting a part!");
return;
}
std::string c = custom[0];
if (c == "add" || c == "include") {
EditorRigblockPtr targetPart = Editor.mpSelectedPart ? Editor.mpSelectedPart : Editor.mpActivePart;
if (!targetPart) {
App::ConsolePrintF("No selected or hovered part found! Select or hover over a part and run this command again!");
return;
}
customModeParts.erase(
std::remove_if(customModeParts.begin(), customModeParts.end(),
[targetPart](const CustomModeEntry& entry) {
return entry.part == targetPart;
}),
customModeParts.end()
);
customModeParts.emplace_back(CustomModeEntry{ targetPart, currentMode });
App::ConsolePrintF("Added selected/hovered part to custom stacking behavior.\nPart will now retain this stacking mode even when changing modes.");
}
else if (c == "remove" || c == "delete" || c == "erase") {
EditorRigblockPtr targetPart = Editor.mpSelectedPart ? Editor.mpSelectedPart : Editor.mpActivePart;
if (!targetPart) {
App::ConsolePrintF("No selected or hovered part found! Select or hover over a part and run this command again!");
return;
}
auto it = std::remove_if(customModeParts.begin(), customModeParts.end(),
[targetPart](const ToggleStacker::CustomModeEntry& entry) {
return entry.part == targetPart;
});
if (it != customModeParts.end()) {
customModeParts.erase(it, customModeParts.end());
App::ConsolePrintF("Removed selected/hovered part from custom stacking behavior.\nPart will no longer follow its own stacking mode.");
}
else {
App::ConsolePrintF("Part does not have any custom stacking mode. Nothing changed.");
}
}
else if (c == "reset" || c == "clear") {
customModeParts.clear();
App::ConsolePrintF("Restored all custom part stacking behaviors to default.\nAll parts will now follow the current stacking mode.");
}
else {
App::ConsolePrintF("Unknown Togglestacker custom argument. Avaliable custom arguments: 'add / include', 'remove / delete / erase', 'reset / clear'.");
}
}
if (mode == nullptr && custom == nullptr) {
if (currentMode != Mode::DEFAULT)
{
currentMode = Mode::DEFAULT;
App::ConsolePrintF("ToggleStacker deactivated, default behavior restored for all* parts.");
}
else
{
currentMode = Mode::STACK_ALL;
App::ConsolePrintF("ToggleStacker activated, all* parts will now stack.");
}
}
}
const char* ToggleStacker::GetDescription(ArgScript::DescriptionMode mode) const
{
if (mode == ArgScript::DescriptionMode::Basic) {
return "Toggles the ability to stack any part on each other.";
}
else
{
return "ToggleStacker: Toggles the ability to stack any part on each other, or disable stacking alltogether, on specific parts or all of them.";
}
}
int ToggleStacker::AddRef()
{
return DefaultRefCounted::AddRef();
}
int ToggleStacker::Release()
{
return DefaultRefCounted::Release();
}