-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefab.h
More file actions
357 lines (345 loc) · 8.54 KB
/
prefab.h
File metadata and controls
357 lines (345 loc) · 8.54 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
// Set prefab's properties, generate objects and give them events. Once done call prefab::generate()
#include<string>
#include<vector>
#include<fstream>
using namespace std;
struct Object;
namespace prefab {
string name;
int type = 0;
float offset = 0.;
vector<Object*> objects;
ofstream file;
void indent(int n) {
for (int i = 0; i < n; i++)
file << " ";
}
template <typename T>
void indent(int n, string s, T param) {
for (int i = 0; i < n; i++)
file << " ";
file << "\"" + s + "\" : \"" << param << "\", \n";
}
void generate();
}
namespace prefabTypes {
enum {
Bomb = 0,
Bullet = 1,
Beam = 2,
Spinner = 3,
Pulse = 4,
Character = 5,
Misc1 = 6,
Misc2 = 7,
Misc3 = 8,
Misc4 = 9
};
}
namespace eventTypes {
const string pos = "pos";
const string sca = "sca";
const string rot = "rot";
const string col = "col";
}
namespace easeTypes {
const string line = "Linear";
const string inst = "Instant";
const string iSine = "InSine";
const string oSine = "OutSine";
const string ioSine = "InOutSine";
const string iElas = "InElastic";
const string oElas = "OutElastic";
const string ioElas = "InOutElastic";
const string iBack = "InBack";
const string oBack = "OutBack";
const string ioBack = "InOutBack";
const string iBoun = "InBounce";
const string oBoun = "OutBounce";
const string ioBoun = "InOutBounce";
}
namespace et = easeTypes;
namespace shapes {
struct Shape {
int shape, so;
string text;
Shape(int shape, int so = 0, string text = "") {
this->shape = shape;
this->so = so;
this->text = text;
}
};
const Shape* const sq = new Shape(0); //Square
const Shape* const sq2 = new Shape(0, 1); //Hollow Square
const Shape* const sq3 = new Shape(0, 2); //Hollow Square
const Shape* const cr = new Shape(1);//Circle
const Shape* const cr2 = new Shape(1, 1);
const Shape* const cr3 = new Shape(1, 4);
const Shape* const sCr = new Shape(1, 2);//Semicircle
const Shape* const sCr2 = new Shape(1, 3);
const Shape* const qCr = new Shape(1, 5);//Quad Circle
const Shape* const qCr2 = new Shape(1, 6);
const Shape* const oCr = new Shape(1, 7);//Oct Circle
const Shape* const oCr2 = new Shape(1, 8);
const Shape* const tr = new Shape(2);
const Shape* const tr2 = new Shape(2, 1);
const Shape* const rTr = new Shape(2, 2);//Right Triangle
const Shape* const rTr2 = new Shape(2, 3);
const Shape* const circ = new Shape(1);
const Shape* const ar = new Shape(3);//Arrow
const Shape* const ar2 = new Shape(3, 1);
const Shape* const hx = new Shape(5);
const Shape* const hx2 = new Shape(5, 1);
const Shape* const hx3 = new Shape(5, 2);
const Shape* const sHx = new Shape(5, 3);//Semi Hexagon
const Shape* const sHx2 = new Shape(5, 4);
Shape* txt(string s) {
return new Shape(4, 0, s);
}
}
struct Event {
string eventType;
float t, x, y;
int r;
float rx, ry, rz;
string easeType;
Event(string type, float t, float x, float y, int r, float rx, float ry, float rz, string easeType) {
eventType = type;
this->t = t;
this->x = x;
this->y = y;
this->r = r;
this->rx = rx;
this->ry = ry;
this->rz = rz;
this->easeType = easeType;
}
void print() {
using namespace prefab;
indent(5);
file << "{ \n";
indent(6, "t", t);
indent(6, "x", x);
if (eventType == eventTypes::pos || eventType == eventTypes::sca)
indent(6, "y", y);
if (r) {
indent(6, "r", r);
indent(6, "rx", rx);
if (eventType == eventTypes::pos || eventType == eventTypes::sca)
indent(6, "ry", ry);
if (r != 2)
indent(6, "rz", rz);
}
if (easeType != "" && easeType != easeTypes::line)
indent(6, "ct", easeType);
file.seekp(-3, file.cur);
file << " \n";
indent(5);
file << "}";
}
};
struct Object {
string id, name, pt;
Object* parent = NULL;
int depth = 15;
shapes::Shape* shape = NULL;
bool helper = false;
bool autoKill = false;
bool empty = false;
float st = 0.;
float ox = 0.;
float oy = 0.;
int bin = 0;
int layer = 1;
float posOffset = 0.;
float scaOffset = 0.;
float rotOffset = 0.;
vector<Event> pos;
vector<Event> sca;
vector<Event> rot;
vector<Event> col;
Object(float st, int depth, const shapes::Shape* shape, int bin = 0, bool helper = false, bool autoKill = true, bool empty = false) {
this->st = st;
this->depth = depth;
this->shape = (shapes::Shape*) shape;
this->bin = bin;
this->helper = helper;
this->autoKill = autoKill;
this->empty = empty;
this->pt = "101";
id = std::to_string(prefab::objects.size());
prefab::objects.push_back(this);
}
void setCenter(float ox, float oy) {
this->ox = ox;
this->oy = oy;
}
void parentOffset(bool posBool, bool scaBool, bool rotBool, float posOffset = 0., float scaOffset = 0., float rotOffset = 0.) {
pt = posBool ? "1" : "0";
pt += scaBool ? "1" : "0";
pt += rotBool ? "1" : "0";
this->posOffset = posOffset;
this->scaOffset = scaOffset;
this->rotOffset = rotOffset;
}
void posEvent(float t, float x, float y, string easeType = easeTypes::line, int r = 0, float rx = 0., float ry = 0., float rz = 0.) {
pos.push_back(Event(eventTypes::pos, t, x, y, r, rx, ry, rz, easeType));
}
void scaEvent(float t, float x, float y, string easeType = easeTypes::line, int r = 0, float rx = 0., float ry = 0., float rz = 0.) {
sca.push_back(Event(eventTypes::sca, t, x, y, r, rx, ry, rz, easeType));
}
void rotEvent(float t, float x, string easeType = easeTypes::line, int r = 0, float rx = 0., float rz = 0.) {
rot.push_back(Event(eventTypes::rot, t, x, 0., r, rx, 0., rz, easeType));
}
void colEvent(float t, int x, string easeType = easeTypes::line, int r = 0, float rx = 0., float rz = 0.) {
col.push_back(Event(eventTypes::col, t, x, 0., r, rx, 0., rz, easeType));
}
void defaultStart() {//for empty objects
posEvent(0., 0., 0.);
scaEvent(0., 1., 1.);
rotEvent(0., 0.);
colEvent(0., 0);
}
void addEvent(Event event) {
if (event.eventType == eventTypes::pos)
pos.push_back(event);
else if (event.eventType == eventTypes::sca)
sca.push_back(event);
else if (event.eventType == eventTypes::rot)
rot.push_back(event);
else if (event.eventType == eventTypes::col)
col.push_back(event);
}
void print() {
using namespace prefab;
indent(2);
file << "{ \n";
indent(3, "id", id);
if (pt != "101")
indent(3, "pt", pt);
if (posOffset || scaOffset || rotOffset) {
indent(3);
file << "\"po\" : [\n";
indent(4);
file << '\"' << posOffset << "\",\n";
indent(4);
file << '\"' << scaOffset << "\",\n";
indent(4);
file << '\"' << rotOffset << "\"\n";
indent(4);
file << "],\n";
}
indent(3, "p", parent ? parent->id : "");
indent(3, "d", depth);
indent(3, "h", helper ? "True" : "False");
indent(3, "st", st);
indent(3, "name", name);
if (shape && (shape->shape || shape->so)) {
indent(3, "shape", shape->shape);
indent(3, "so", shape->so);
}
if (autoKill)
indent(3, "ak", "True");
if (empty)
indent(3, "empty", "True");
indent(3);
file << "\"o\" : { \n";
indent(4, "x", ox);
indent(4, "y", oy);
file.seekp(-3, file.cur);
file << " \n";
indent(3);
file << "}, \n";
indent(3);
file << "\"ed\" : { \n";
indent(4, "bin", bin);
indent(4, "layer", layer);
file.seekp(-3, file.cur);
file << " \n";
indent(3);
file << "}, \n";
indent(3);
file << "\"events\" : {\n";
indent(4);
file << "\"pos\" : [\n";
bool first = true;
for (Event& event : pos) {
if (first)
first = false;
else
file << ",\n";
event.print();
}
file << endl;
indent(4);
file << "], \n";
indent(4);
file << "\"sca\" : [\n";
first = true;
for (Event& event : sca) {
if (first)
first = false;
else
file << ",\n";
event.print();
}
file << endl;
indent(4);
file << "], \n";
indent(4);
file << "\"rot\" : [\n";
first = true;
for (Event& event : rot) {
if (first)
first = false;
else
file << ",\n";
event.print();
}
file << endl;
indent(4);
file << "], \n";
indent(4);
file << "\"col\" : [\n";
first = true;
for (Event& event : col) {
if (first)
first = false;
else
file << ",\n";
event.print();
}
file << endl;
indent(4);
file << "] \n";
indent(3);
file << "} \n";
indent(2);
file << "}";
}
};
void prefab::generate() {
string fileName = "";
for (char c : name)
fileName += tolower(c);
fileName += ".lsp";
file.open(fileName);
file << "{\n";
indent(1, "name", name);
indent(1, "type", type);
indent(1, "offset", offset);
indent(1);
file << "\"objects\" : [ \n";
bool first = true;
for (Object* object : objects) {
if (first)
first = false;
else
file << ",\n";
object->print();
}
file << endl;
indent(1);
file << "] \n}";
file.close();
}