Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/scripting/EngineScriptConversions.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | template<> bool ScriptInterface::FromJSVal<CFixedVector3D>(const Request& rq, JS::HandleValue v, CFixedVector3D& out) | ||||
if (!JS_GetProperty(rq.cx, obj, "z", &p)) return false; | if (!JS_GetProperty(rq.cx, obj, "z", &p)) return false; | ||||
if (!FromJSVal(rq, p, out.Z)) return false; | if (!FromJSVal(rq, p, out.Z)) return false; | ||||
return true; | return true; | ||||
} | } | ||||
template<> void ScriptInterface::ToJSVal<CFixedVector3D>(const Request& rq, JS::MutableHandleValue ret, const CFixedVector3D& val) | template<> void ScriptInterface::ToJSVal<CFixedVector3D>(const Request& rq, JS::MutableHandleValue ret, const CFixedVector3D& val) | ||||
{ | { | ||||
ScriptInterface::CmptPrivate* pCmptPrivate = ScriptInterface::GetScriptInterfaceAndCBData(rq.cx); | JS::RootedObject global(rq.cx, rq.glob); | ||||
JS::RootedObject global(rq.cx, &pCmptPrivate->pScriptInterface->GetGlobalObject().toObject()); | |||||
JS::RootedValue valueVector3D(rq.cx); | JS::RootedValue valueVector3D(rq.cx); | ||||
if (!JS_GetProperty(rq.cx, global, "Vector3D", &valueVector3D)) | if (!JS_GetProperty(rq.cx, global, "Vector3D", &valueVector3D)) | ||||
FAIL_VOID("Failed to get Vector3D constructor"); | FAIL_VOID("Failed to get Vector3D constructor"); | ||||
JS::AutoValueArray<3> args(rq.cx); | JS::AutoValueArray<3> args(rq.cx); | ||||
args[0].setNumber(val.X.ToDouble()); | args[0].setNumber(val.X.ToDouble()); | ||||
args[1].setNumber(val.Y.ToDouble()); | args[1].setNumber(val.Y.ToDouble()); | ||||
args[2].setNumber(val.Z.ToDouble()); | args[2].setNumber(val.Z.ToDouble()); | ||||
Show All 16 Lines | template<> bool ScriptInterface::FromJSVal<CFixedVector2D>(const Request& rq, JS::HandleValue v, CFixedVector2D& out) | ||||
if (!JS_GetProperty(rq.cx, obj, "y", &p)) return false; | if (!JS_GetProperty(rq.cx, obj, "y", &p)) return false; | ||||
if (!FromJSVal(rq, p, out.Y)) return false; | if (!FromJSVal(rq, p, out.Y)) return false; | ||||
return true; | return true; | ||||
} | } | ||||
template<> void ScriptInterface::ToJSVal<CFixedVector2D>(const Request& rq, JS::MutableHandleValue ret, const CFixedVector2D& val) | template<> void ScriptInterface::ToJSVal<CFixedVector2D>(const Request& rq, JS::MutableHandleValue ret, const CFixedVector2D& val) | ||||
{ | { | ||||
ScriptInterface::CmptPrivate* pCmptPrivate = ScriptInterface::GetScriptInterfaceAndCBData(rq.cx); | JS::RootedObject global(rq.cx, rq.glob); | ||||
JS::RootedObject global(rq.cx, &pCmptPrivate->pScriptInterface->GetGlobalObject().toObject()); | |||||
JS::RootedValue valueVector2D(rq.cx); | JS::RootedValue valueVector2D(rq.cx); | ||||
if (!JS_GetProperty(rq.cx, global, "Vector2D", &valueVector2D)) | if (!JS_GetProperty(rq.cx, global, "Vector2D", &valueVector2D)) | ||||
FAIL_VOID("Failed to get Vector2D constructor"); | FAIL_VOID("Failed to get Vector2D constructor"); | ||||
JS::AutoValueArray<2> args(rq.cx); | JS::AutoValueArray<2> args(rq.cx); | ||||
args[0].setNumber(val.X.ToDouble()); | args[0].setNumber(val.X.ToDouble()); | ||||
args[1].setNumber(val.Y.ToDouble()); | args[1].setNumber(val.Y.ToDouble()); | ||||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator