Line data Source code
1 : /* Copyright (C) 2021 Wildfire Games.
2 : * This file is part of 0 A.D.
3 : *
4 : * 0 A.D. is free software: you can redistribute it and/or modify
5 : * it under the terms of the GNU General Public License as published by
6 : * the Free Software Foundation, either version 2 of the License, or
7 : * (at your option) any later version.
8 : *
9 : * 0 A.D. is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : * GNU General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License
15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 : */
17 :
18 : #include "precompiled.h"
19 :
20 : #include "ICmpFootprint.h"
21 :
22 : #include "simulation2/system/InterfaceScripted.h"
23 :
24 : #include "simulation2/system/SimContext.h"
25 : #include "maths/FixedVector3D.h"
26 :
27 0 : JS::Value ICmpFootprint::GetShape_wrapper() const
28 : {
29 : EShape shape;
30 0 : entity_pos_t size0, size1, height;
31 0 : GetShape(shape, size0, size1, height);
32 :
33 0 : ScriptRequest rq(GetSimContext().GetScriptInterface());
34 :
35 0 : JS::RootedObject obj(rq.cx, JS_NewPlainObject(rq.cx));
36 0 : if (!obj)
37 0 : return JS::UndefinedValue();
38 :
39 0 : if (shape == CIRCLE)
40 : {
41 0 : JS::RootedValue ptype(rq.cx);
42 0 : JS::RootedValue pradius(rq.cx);
43 0 : JS::RootedValue pheight(rq.cx);
44 0 : Script::ToJSVal<std::string>(rq, &ptype, "circle");
45 0 : Script::ToJSVal(rq, &pradius, size0);
46 0 : Script::ToJSVal(rq, &pheight, height);
47 0 : JS_SetProperty(rq.cx, obj, "type", ptype);
48 0 : JS_SetProperty(rq.cx, obj, "radius", pradius);
49 0 : JS_SetProperty(rq.cx, obj, "height", pheight);
50 : }
51 : else
52 : {
53 0 : JS::RootedValue ptype(rq.cx);
54 0 : JS::RootedValue pwidth(rq.cx);
55 0 : JS::RootedValue pdepth(rq.cx);
56 0 : JS::RootedValue pheight(rq.cx);
57 0 : Script::ToJSVal<std::string>(rq, &ptype, "square");
58 0 : Script::ToJSVal(rq, &pwidth, size0);
59 0 : Script::ToJSVal(rq, &pdepth, size1);
60 0 : Script::ToJSVal(rq, &pheight, height);
61 0 : JS_SetProperty(rq.cx, obj, "type", ptype);
62 0 : JS_SetProperty(rq.cx, obj, "width", pwidth);
63 0 : JS_SetProperty(rq.cx, obj, "depth", pdepth);
64 0 : JS_SetProperty(rq.cx, obj, "height", pheight);
65 : }
66 :
67 0 : return JS::ObjectValue(*obj);
68 : }
69 :
70 1 : BEGIN_INTERFACE_WRAPPER(Footprint)
71 : DEFINE_INTERFACE_METHOD("PickSpawnPoint", ICmpFootprint, PickSpawnPoint)
72 : DEFINE_INTERFACE_METHOD("PickSpawnPointBothPass", ICmpFootprint, PickSpawnPointBothPass)
73 : DEFINE_INTERFACE_METHOD("GetShape", ICmpFootprint, GetShape_wrapper)
74 235 : END_INTERFACE_WRAPPER(Footprint)
|