Index: source/simulation2/components/CCmpVisualActor.cpp =================================================================== --- source/simulation2/components/CCmpVisualActor.cpp +++ source/simulation2/components/CCmpVisualActor.cpp @@ -38,6 +38,7 @@ #include "graphics/Decal.h" #include "graphics/Frustum.h" #include "graphics/Model.h" +#include "graphics/ModelDef.h" #include "graphics/ObjectBase.h" #include "graphics/ObjectEntry.h" #include "graphics/Unit.h" @@ -87,6 +88,7 @@ fixed m_AnimSyncOffsetTime; std::map m_VariantSelections; + std::vector m_PropPointsPositions; u32 m_Seed; // seed used for random variations @@ -210,6 +212,20 @@ InitModel(paramNode); SelectAnimation("idle"); + + std::vector& props = m_Unit->GetModel().ToCModel()->GetModelDef()->m_PropPoints; + for (const SPropPoint& prop : props) + { + JsProp jsProp; + jsProp.m_Name = prop.m_Name.EscapeToPrintableASCII(); + jsProp.m_Position = CFixedVector3D( + fixed::FromFloat(prop.m_Position.X), + fixed::FromFloat(prop.m_Position.Y), + fixed::FromFloat(prop.m_Position.Z) + ); + + m_PropPointsPositions.push_back(jsProp); + } } virtual void Deinit() @@ -439,6 +455,8 @@ return m_AnimName; } + virtual std::vector GetPropPoints() const; + virtual void SelectAnimation(const std::string& name, bool once = false, fixed speed = fixed::FromInt(1)) { m_AnimRunThreshold = fixed::Zero(); @@ -806,3 +824,8 @@ SelectAnimation(name, false, speed); m_AnimRunThreshold = runThreshold; } + +std::vector CCmpVisualActor::GetPropPoints() const +{ + return m_PropPointsPositions; +} Index: source/simulation2/components/ICmpVisual.h =================================================================== --- source/simulation2/components/ICmpVisual.h +++ source/simulation2/components/ICmpVisual.h @@ -27,8 +27,19 @@ #include "maths/FixedVector3D.h" #include "lib/file/vfs/vfs_path.h" +#include +#include +#include + class CUnit; + +struct JsProp +{ + std::string m_Name; + CFixedVector3D m_Position; +}; + /** * The visual representation of an entity (typically an actor). */ @@ -75,6 +86,13 @@ virtual CFixedVector3D GetProjectileLaunchPoint() const = 0; /** + * Return all the prop points an entity currently have with their location + * Return type is CFixedVector3D because it is exposed to the JS interface. + * Returns (0,0,0) if no point can be found. + */ + virtual std::vector GetPropPoints() const = 0; + + /** * Returns the underlying unit of this visual actor. May return NULL to indicate that no unit exists (e.g. may happen if the * game is started without graphics rendering). * Originally intended for introspection purposes in Atlas; for other purposes, consider using a specialized getter first. Index: source/simulation2/components/ICmpVisual.cpp =================================================================== --- source/simulation2/components/ICmpVisual.cpp +++ source/simulation2/components/ICmpVisual.cpp @@ -26,6 +26,7 @@ DEFINE_INTERFACE_METHOD_CONST_0("GetAnimationName", std::string, ICmpVisual, GetAnimationName) DEFINE_INTERFACE_METHOD_CONST_0("GetProjectileActor", std::wstring, ICmpVisual, GetProjectileActor) DEFINE_INTERFACE_METHOD_CONST_0("GetProjectileLaunchPoint", CFixedVector3D, ICmpVisual, GetProjectileLaunchPoint) +DEFINE_INTERFACE_METHOD_CONST_0("GetPropPoints", std::vector, ICmpVisual, GetPropPoints) DEFINE_INTERFACE_METHOD_3("SelectAnimation", void, ICmpVisual, SelectAnimation, std::string, bool, fixed) DEFINE_INTERFACE_METHOD_1("SelectMovementAnimation", void, ICmpVisual, SelectMovementAnimation, fixed) DEFINE_INTERFACE_METHOD_1("ResetMoveAnimation", void, ICmpVisual, ResetMoveAnimation, std::string) Index: source/simulation2/scripting/EngineScriptConversions.cpp =================================================================== --- source/simulation2/scripting/EngineScriptConversions.cpp +++ source/simulation2/scripting/EngineScriptConversions.cpp @@ -28,6 +28,7 @@ #include "ps/utf16string.h" #include "simulation2/helpers/CinemaPath.h" #include "simulation2/helpers/Grid.h" +#include "simulation2/components/ICmpVisual.h" #include "simulation2/system/IComponent.h" #include "simulation2/system/ParamNode.h" @@ -375,5 +376,36 @@ return true; } +template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const JsProp& val) +{ + JSAutoRequest rq(cx); + JS::RootedObject obj(cx, JS_NewPlainObject(cx)); + + JS::RootedValue name(cx); + JS::RootedValue position(cx); + ToJSVal(cx, &name, val.m_Name); + ToJSVal(cx, &position, val.m_Position); + + JS_SetProperty(cx, obj, "name", name); + JS_SetProperty(cx, obj, "position", position); + + + ret.setObject(*obj); +} + +template<> void ScriptInterface::ToJSVal>(JSContext* cx, JS::MutableHandleValue ret, const std::vector& val) +{ + JSAutoRequest rq(cx); + JS::RootedObject objArr(cx, JS_NewArrayObject(cx, val.size())); + for (size_t i = 0; i < val.size(); ++i) + { + JS::RootedValue element(cx); + ToJSVal(cx, &element, val[i]); + JS_SetElement(cx, objArr, i, element); + } + + ret.setObject(*objArr); +} + // define vectors JSVAL_VECTOR(CFixedVector2D)