-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
ShapeVector_ScriptBinding.h
executable file
·453 lines (373 loc) · 14.1 KB
/
ShapeVector_ScriptBinding.h
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
//-----------------------------------------------------------------------------
// Copyright (c) 2013 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
ConsoleMethodGroupBeginWithDocs(ShapeVector, SceneObject)
/*! Sets a regular polygon primitive.
@return No return value.
*/
ConsoleMethodWithDocs(ShapeVector, setPolyPrimitive, ConsoleVoid, 3, 3, (vertexCount))
{
// Set Polygon Primitive.
object->setPolyPrimitive( dAtoi(argv[2]) );
}
//----------------------------------------------------------------------------
/*! Sets Custom Polygon.
@return No return value.
*/
ConsoleMethodWithDocs(ShapeVector, setPolyCustom, ConsoleVoid, 4, 4, (poly-count, poly-Definition$))
{
// Set Collision Poly Custom.
object->setPolyCustom( dAtoi(argv[2]), argv[3] );
}
//----------------------------------------------------------------------------
/*! Gets Polygon.
@return (poly-Definition) The vertices of the polygon in object space.
*/
ConsoleMethodWithDocs(ShapeVector, getPoly, ConsoleString, 2, 2, ())
{
// Get Collision Poly Count.
return object->getPoly();
}
//----------------------------------------------------------------------------
/*! Gets Polygon points in world space.
@return (poly-Definition) The vertices of the polygon in world space.
*/
ConsoleMethodWithDocs(ShapeVector, getWorldPoly, ConsoleString, 2, 2, ())
{
// Get Collision Poly Count.
return object->getWorldPoly();
}
//----------------------------------------------------------------------------
/*! RGBA value or ( stockColorName ) - Sets the line color.
@param red The red value.
@param green The green value.
@param blue The blue value.
@param alpha The alpha value.
@return No return Value.
*/
ConsoleMethodWithDocs(ShapeVector, setLineColor, ConsoleVoid, 3, 6, (float red, float green, float blue, [float alpha = 1.0]))
{
// The colors.
F32 red;
F32 green;
F32 blue;
F32 alpha = 1.0f;
// Space separated.
if (argc == 3 )
{
// Grab the element count.
const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
// Has a single argument been specified?
if ( elementCount == 1 )
{
// Set color.
Con::setData( TypeColorF, &const_cast<ColorF&>(object->getLineColor()), 0, 1, &(argv[2]) );
return;
}
// ("R G B [A]")
if ((elementCount == 3) || (elementCount == 4))
{
// Extract the color.
red = dAtof(Utility::mGetStringElement(argv[2], 0));
green = dAtof(Utility::mGetStringElement(argv[2], 1));
blue = dAtof(Utility::mGetStringElement(argv[2], 2));
// Grab the alpha if it's there.
if (elementCount > 3)
alpha = dAtof(Utility::mGetStringElement(argv[2], 3));
}
// Invalid.
else
{
Con::warnf("ShapeVector::setLineColor() - Invalid Number of parameters!");
return;
}
}
// (R, G, B)
else if (argc >= 5)
{
red = dAtof(argv[2]);
green = dAtof(argv[3]);
blue = dAtof(argv[4]);
// Grab the alpha if it's there.
if (argc > 5)
alpha = dAtof(argv[5]);
}
// Invalid.
else
{
Con::warnf("ShapeVector::setLineColor() - Invalid Number of parameters!");
return;
}
object->setLineColor( ColorF(red, green, blue, alpha) );
}
//----------------------------------------------------------------------------
/*! Gets the fill color.
@param allowColorNames Whether to allow stock color names to be returned or not. Optional: Defaults to false.
@return (float red / float green / float blue / float alpha) The sprite blend color.
*/
ConsoleMethodWithDocs(ShapeVector, getLineColor, ConsoleString, 2, 3, (allowColorNames))
{
// Get line color.
ColorF color = object->getLineColor();
// Fetch allow color names flag.
const bool allowColorNames = (argc > 2) ? dAtob(argv[2] ) : false;
// Are color names allowed?
if ( allowColorNames )
{
// Yes, so fetch the field value.
return Con::getData( TypeColorF, &color, 0 );
}
// No, so fetch the raw color values.
return color.scriptThis();
}
//----------------------------------------------------------------------------
/*! Sets the Rendering Line Alpha (transparency).
@param alpha The alpha value.
@return No return value.
*/
ConsoleMethodWithDocs(ShapeVector, setLineAlpha, ConsoleVoid, 3, 3, (alpha))
{
// Set Line Alpha.
object->setLineAlpha( dAtof(argv[2]) );
}
//----------------------------------------------------------------------------
/*! RGBA value or ( stockColorName ) - Sets the fill color.
@param red The red value.
@param green The green value.
@param blue The blue value.
@param alpha The alpha value.
@return No return Value.
*/
ConsoleMethodWithDocs(ShapeVector, setFillColor, ConsoleVoid, 3, 3, (float red, float green, float blue, [float alpha = 1.0]))
{
// The colors.
F32 red;
F32 green;
F32 blue;
F32 alpha = 1.0f;
// Space separated.
if (argc == 3 )
{
// Grab the element count.
const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
// Has a single argument been specified?
if ( elementCount == 1 )
{
// Set color.
Con::setData( TypeColorF, &const_cast<ColorF&>(object->getFillColor()), 0, 1, &(argv[2]) );
return;
}
// ("R G B [A]")
if ((elementCount == 3) || (elementCount == 4))
{
// Extract the color.
red = dAtof(Utility::mGetStringElement(argv[2], 0));
green = dAtof(Utility::mGetStringElement(argv[2], 1));
blue = dAtof(Utility::mGetStringElement(argv[2], 2));
// Grab the alpha if it's there.
if (elementCount > 3)
alpha = dAtof(Utility::mGetStringElement(argv[2], 3));
}
// Invalid.
else
{
Con::warnf("ShapeVector::setFillColor() - Invalid Number of parameters!");
return;
}
}
// (R, G, B)
else if (argc >= 5)
{
red = dAtof(argv[2]);
green = dAtof(argv[3]);
blue = dAtof(argv[4]);
// Grab the alpha if it's there.
if (argc > 5)
alpha = dAtof(argv[5]);
}
// Invalid.
else
{
Con::warnf("ShapeVector::setFillColor() - Invalid Number of parameters!");
return;
}
object->setFillColor( ColorF(red, green, blue, alpha) );
}
//----------------------------------------------------------------------------
/*! Gets the fill color.
@param allowColorNames Whether to allow stock color names to be returned or not. Optional: Defaults to false.
@return (float red / float green / float blue / float alpha) The sprite blend color.
*/
ConsoleMethodWithDocs(ShapeVector, getFillColor, ConsoleString, 2, 3, (allowColorNames))
{
// Get line color.
ColorF color = object->getFillColor();
// Fetch allow color names flag.
const bool allowColorNames = (argc > 2) ? dAtob(argv[2] ) : false;
// Are color names allowed?
if ( allowColorNames )
{
// Yes, so fetch the field value.
return Con::getData( TypeColorF, &color, 0 );
}
// No, so fetch the raw color values.
return color.scriptThis();
}
//----------------------------------------------------------------------------
/*! Sets the Rendering Fill Alpha (transparency).
@param alpha The alpha value.
@return No return value.
*/
ConsoleMethodWithDocs(ShapeVector, setFillAlpha, ConsoleVoid, 3, 3, (alpha))
{
// Set Fill Alpha.
object->setFillAlpha( dAtof(argv[2]) );
}
//----------------------------------------------------------------------------
/*! Sets the Rendering Fill Mode.
@return No return value.
*/
ConsoleMethodWithDocs(ShapeVector, setFillMode, ConsoleVoid, 3, 3, (fillMode?))
{
// Set Fill Mode.
object->setFillMode( dAtob(argv[2]) );
}
//----------------------------------------------------------------------------
/*! Gets the Rendering Fill Mode.
@return The fill mode as a boolean value.
*/
ConsoleMethodWithDocs(ShapeVector, getFillMode, ConsoleBool, 2, 2, ())
{
return object->getFillMode();
}
//----------------------------------------------------------------------------
/*! Sets whether this shape is a circle or not.
@return The fill mode as a boolean value.
*/
ConsoleMethodWithDocs(ShapeVector, setIsCircle, ConsoleVoid, 3, 3, (isCircle?))
{
object->setIsCircle(dAtob(argv[2]));
}
//----------------------------------------------------------------------------
/*! Returns whether this shape is a circle or not.
@return The fill mode as a boolean value.
*/
ConsoleMethodWithDocs(ShapeVector, getIsCircle, ConsoleBool, 2, 2, ())
{
return object->getIsCircle();
}
//----------------------------------------------------------------------------
/*! Returns the radius of the shape if it is a circle.
@return The fill mode as a boolean value.
*/
ConsoleMethodWithDocs(ShapeVector, getCircleRadius, ConsoleBool, 2, 2, ())
{
return object->getCircleRadius();
}
//----------------------------------------------------------------------------
/*! Changes the radius of the shape if it is a circle.
@return The fill mode as a boolean value.
*/
ConsoleMethodWithDocs(ShapeVector, setCircleRadius, ConsoleVoid, 3, 3, (radius))
{
object->setCircleRadius(dAtof(argv[2]));
}
//-----------------------------------------------------------------------------
/*! Get the number of vertices on a polygon shape.
*/
ConsoleMethodWithDocs(ShapeVector, getVertexCount, ConsoleInt, 2, 2, ())
{
return object->getPolyVertexCount();
}
//-----------------------------------------------------------------------------
/*! Get a box (\width height\ that wraps around the poly vertices
*/
ConsoleMethodWithDocs(ShapeVector, getBoxFromPoints, ConsoleString, 2, 2, ())
{
Vector2 box = object->getBoxFromPoints();
// Create Returnable Buffer.
char* pBuffer = Con::getReturnBuffer(32);
// Format Buffer.
dSprintf(pBuffer, 32, "%g %g", box.x, box.y);
// Return box width and height.
return pBuffer;
}
//-----------------------------------------------------------------------------
/*! Sets shape flipping for each axis.
@param flipX Whether or not to flip the shape along the x (horizontal) axis.
@param flipY Whether or not to flip the shape along the y (vertical) axis.
@return No return value.
*/
ConsoleMethodWithDocs(ShapeVector, setFlip, ConsoleVoid, 4, 4, (bool flipX, bool flipY))
{
// Set Flip.
object->setFlip( dAtob(argv[2]), dAtob(argv[3]) );
}
//-----------------------------------------------------------------------------
/*! Gets the flip for each axis.
@return (bool flipX/bool flipY) Whether or not the shape is flipped along the x and y axis.
*/
ConsoleMethodWithDocs(ShapeVector, getFlip, ConsoleString, 2, 2, ())
{
// Create Returnable Buffer.
char* pBuffer = Con::getReturnBuffer(32);
// Format Buffer.
dSprintf(pBuffer, 32, "%d %d", object->getFlipX(), object->getFlipY());
// Return Buffer.
return pBuffer;
}
//-----------------------------------------------------------------------------
/*! Sets whether or not the shape is flipped horizontally.
@param flipX Whether or not to flip the shape along the x (horizontal) axis.
@return No return value.
*/
ConsoleMethodWithDocs(ShapeVector, setFlipX, ConsoleVoid, 3, 3, (bool flipX))
{
// Set Flip.
object->setFlipX( dAtob(argv[2]) );
}
//-----------------------------------------------------------------------------
/*! Sets whether or not the shape is flipped vertically.
@param flipY Whether or not to flip the shape along the y (vertical) axis.
@return No return value.
*/
ConsoleMethodWithDocs(ShapeVector, setFlipY, ConsoleVoid, 3, 3, (bool flipY))
{
// Set Flip.
object->setFlipY( dAtob(argv[2]) );
}
//-----------------------------------------------------------------------------
/*! Gets whether or not the shape is flipped horizontally.
@return (bool flipX) Whether or not the shape is flipped along the x axis.
*/
ConsoleMethodWithDocs(ShapeVector, getFlipX, ConsoleBool, 2, 2, ())
{
return object->getFlipX();
}
//-----------------------------------------------------------------------------
/*! Gets whether or not the shape is flipped vertically.
@return (bool flipY) Whether or not the shape is flipped along the y axis.
*/
ConsoleMethodWithDocs(ShapeVector, getFlipY, ConsoleBool, 2, 2, ())
{
return object->getFlipY();
}
ConsoleMethodGroupEndWithDocs(ShapeVector)