2025-08-07 22:01:34 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2010-01-29 13:13:18 -08:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2010-01-29 13:13:18 -08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2010-01-29 13:13:18 -08:00
|
|
|
* 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
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-29 13:13:18 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "ICmpFootprint.h"
|
|
|
|
|
|
2025-08-07 22:01:34 -07:00
|
|
|
#include "maths/FixedVector3D.h"
|
|
|
|
|
#include "scriptinterface/ScriptConversions.h"
|
|
|
|
|
#include "scriptinterface/ScriptRequest.h"
|
2010-01-29 13:13:18 -08:00
|
|
|
#include "simulation2/system/InterfaceScripted.h"
|
|
|
|
|
|
2025-08-07 22:01:34 -07:00
|
|
|
#include <js/PropertyAndElement.h>
|
|
|
|
|
#include <js/RootingAPI.h>
|
|
|
|
|
#include <js/TypeDecls.h>
|
|
|
|
|
#include <jsapi.h>
|
|
|
|
|
#include <string>
|
2010-04-29 16:36:05 -07:00
|
|
|
|
2017-01-19 18:25:19 -08:00
|
|
|
JS::Value ICmpFootprint::GetShape_wrapper() const
|
2010-05-01 02:48:39 -07:00
|
|
|
{
|
|
|
|
|
EShape shape;
|
|
|
|
|
entity_pos_t size0, size1, height;
|
|
|
|
|
GetShape(shape, size0, size1, height);
|
|
|
|
|
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
ScriptRequest rq(GetSimContext().GetScriptInterface());
|
2010-05-01 02:48:39 -07:00
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedObject obj(rq.cx, JS_NewPlainObject(rq.cx));
|
2010-05-01 02:48:39 -07:00
|
|
|
if (!obj)
|
2015-01-24 06:46:52 -08:00
|
|
|
return JS::UndefinedValue();
|
2010-05-01 02:48:39 -07:00
|
|
|
|
|
|
|
|
if (shape == CIRCLE)
|
|
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue ptype(rq.cx);
|
|
|
|
|
JS::RootedValue pradius(rq.cx);
|
|
|
|
|
JS::RootedValue pheight(rq.cx);
|
2021-05-13 02:43:33 -07:00
|
|
|
Script::ToJSVal<std::string>(rq, &ptype, "circle");
|
|
|
|
|
Script::ToJSVal(rq, &pradius, size0);
|
|
|
|
|
Script::ToJSVal(rq, &pheight, height);
|
2020-11-13 05:18:22 -08:00
|
|
|
JS_SetProperty(rq.cx, obj, "type", ptype);
|
|
|
|
|
JS_SetProperty(rq.cx, obj, "radius", pradius);
|
|
|
|
|
JS_SetProperty(rq.cx, obj, "height", pheight);
|
2010-05-01 02:48:39 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue ptype(rq.cx);
|
|
|
|
|
JS::RootedValue pwidth(rq.cx);
|
|
|
|
|
JS::RootedValue pdepth(rq.cx);
|
|
|
|
|
JS::RootedValue pheight(rq.cx);
|
2021-05-13 02:43:33 -07:00
|
|
|
Script::ToJSVal<std::string>(rq, &ptype, "square");
|
|
|
|
|
Script::ToJSVal(rq, &pwidth, size0);
|
|
|
|
|
Script::ToJSVal(rq, &pdepth, size1);
|
|
|
|
|
Script::ToJSVal(rq, &pheight, height);
|
2020-11-13 05:18:22 -08:00
|
|
|
JS_SetProperty(rq.cx, obj, "type", ptype);
|
|
|
|
|
JS_SetProperty(rq.cx, obj, "width", pwidth);
|
|
|
|
|
JS_SetProperty(rq.cx, obj, "depth", pdepth);
|
|
|
|
|
JS_SetProperty(rq.cx, obj, "height", pheight);
|
2010-05-01 02:48:39 -07:00
|
|
|
}
|
|
|
|
|
|
2015-01-24 06:46:52 -08:00
|
|
|
return JS::ObjectValue(*obj);
|
2010-05-01 02:48:39 -07:00
|
|
|
}
|
|
|
|
|
|
2010-01-29 13:13:18 -08:00
|
|
|
BEGIN_INTERFACE_WRAPPER(Footprint)
|
2021-05-01 01:01:30 -07:00
|
|
|
DEFINE_INTERFACE_METHOD("PickSpawnPoint", ICmpFootprint, PickSpawnPoint)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("PickSpawnPointBothPass", ICmpFootprint, PickSpawnPointBothPass)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("GetShape", ICmpFootprint, GetShape_wrapper)
|
2010-01-29 13:13:18 -08:00
|
|
|
END_INTERFACE_WRAPPER(Footprint)
|