Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/scripting/EngineScriptConversions.cpp
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | template<> void ScriptInterface::ToJSVal<const CParamNode*>(JSContext* cx, JS::MutableHandleValue ret, const CParamNode* const& val) | ||||
if (val) | if (val) | ||||
ToJSVal(cx, ret, *val); | ToJSVal(cx, ret, *val); | ||||
else | else | ||||
ret.setUndefined(); | ret.setUndefined(); | ||||
} | } | ||||
template<> bool ScriptInterface::FromJSVal<CColor>(JSContext* cx, JS::HandleValue v, CColor& out) | template<> bool ScriptInterface::FromJSVal<CColor>(JSContext* cx, JS::HandleValue v, CColor& out) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | |||||
if (!v.isObject()) | if (!v.isObject()) | ||||
FAIL("JS::HandleValue not an object"); | FAIL("JS::HandleValue not an object"); | ||||
JSAutoRequest rq(cx); | |||||
JS::RootedObject obj(cx, &v.toObject()); | JS::RootedObject obj(cx, &v.toObject()); | ||||
JS::RootedValue r(cx); | JS::RootedValue r(cx); | ||||
JS::RootedValue g(cx); | JS::RootedValue g(cx); | ||||
JS::RootedValue b(cx); | JS::RootedValue b(cx); | ||||
JS::RootedValue a(cx); | JS::RootedValue a(cx); | ||||
if (!JS_GetProperty(cx, obj, "r", &r) || !FromJSVal(cx, r, out.r)) | if (!JS_GetProperty(cx, obj, "r", &r) || !FromJSVal(cx, r, out.r)) | ||||
FAIL("Failed to get property CColor.r"); | FAIL("Failed to get property CColor.r"); | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | template<> void ScriptInterface::ToJSVal<Grid<u16> >(JSContext* cx, JS::MutableHandleValue ret, const Grid<u16>& val) | ||||
JS_SetProperty(cx, obj, "height", h); | JS_SetProperty(cx, obj, "height", h); | ||||
JS_SetProperty(cx, obj, "data", data); | JS_SetProperty(cx, obj, "data", data); | ||||
ret.setObject(*obj); | ret.setObject(*obj); | ||||
} | } | ||||
template<> bool ScriptInterface::FromJSVal<TNSpline>(JSContext* cx, JS::HandleValue v, TNSpline& out) | template<> bool ScriptInterface::FromJSVal<TNSpline>(JSContext* cx, JS::HandleValue v, TNSpline& out) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | |||||
if (!v.isObject()) | if (!v.isObject()) | ||||
FAIL("Argument must be an object"); | FAIL("Argument must be an object"); | ||||
JSAutoRequest rq(cx); | |||||
JS::RootedObject obj(cx, &v.toObject()); | JS::RootedObject obj(cx, &v.toObject()); | ||||
bool isArray; | bool isArray; | ||||
if (!JS_IsArrayObject(cx, obj, &isArray) || !isArray) | if (!JS_IsArrayObject(cx, obj, &isArray) || !isArray) | ||||
FAIL("Argument must be an array"); | FAIL("Argument must be an array"); | ||||
u32 numberOfNodes = 0; | u32 numberOfNodes = 0; | ||||
if (!JS_GetArrayLength(cx, obj, &numberOfNodes)) | if (!JS_GetArrayLength(cx, obj, &numberOfNodes)) | ||||
FAIL("Failed to get array length"); | FAIL("Failed to get array length"); | ||||
Show All 18 Lines | template<> bool ScriptInterface::FromJSVal<TNSpline>(JSContext* cx, JS::HandleValue v, TNSpline& out) | ||||
if (out.GetAllNodes().empty()) | if (out.GetAllNodes().empty()) | ||||
FAIL("Spline must contain at least one node"); | FAIL("Spline must contain at least one node"); | ||||
return true; | return true; | ||||
} | } | ||||
template<> bool ScriptInterface::FromJSVal<CCinemaPath>(JSContext* cx, JS::HandleValue v, CCinemaPath& out) | template<> bool ScriptInterface::FromJSVal<CCinemaPath>(JSContext* cx, JS::HandleValue v, CCinemaPath& out) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | |||||
if (!v.isObject()) | if (!v.isObject()) | ||||
FAIL("Argument must be an object"); | FAIL("Argument must be an object"); | ||||
JSAutoRequest rq(cx); | |||||
JS::RootedObject obj(cx, &v.toObject()); | JS::RootedObject obj(cx, &v.toObject()); | ||||
CCinemaData pathData; | CCinemaData pathData; | ||||
TNSpline positionSpline, targetSpline; | TNSpline positionSpline, targetSpline; | ||||
if (!FromJSProperty(cx, v, "name", pathData.m_Name)) | if (!FromJSProperty(cx, v, "name", pathData.m_Name)) | ||||
FAIL("Failed to get CCinemaPath.name property"); | FAIL("Failed to get CCinemaPath.name property"); | ||||
Show All 29 Lines |
Wildfire Games · Phabricator