mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Merges two camera JS interface functions into the single one.
Differential Revision: https://code.wildfiregames.com/D2467 This was SVN commit r23264.
This commit is contained in:
@@ -183,20 +183,23 @@ function jumpCamera(index)
|
||||
return;
|
||||
|
||||
let threshold = Engine.ConfigDB_GetValue("user", "gui.session.camerajump.threshold");
|
||||
let cameraPivot = Engine.GetCameraPivot();
|
||||
if (g_JumpCameraLast &&
|
||||
Math.abs(Engine.CameraGetX() - position.x) < threshold &&
|
||||
Math.abs(Engine.CameraGetZ() - position.z) < threshold)
|
||||
Math.abs(cameraPivot.x - position.x) < threshold &&
|
||||
Math.abs(cameraPivot.z - position.z) < threshold)
|
||||
{
|
||||
Engine.CameraMoveTo(g_JumpCameraLast.x, g_JumpCameraLast.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_JumpCameraLast = { "x": Engine.CameraGetX(), "z": Engine.CameraGetZ() };
|
||||
g_JumpCameraLast = cameraPivot;
|
||||
Engine.CameraMoveTo(position.x, position.z);
|
||||
}
|
||||
}
|
||||
|
||||
function setJumpCamera(index)
|
||||
{
|
||||
g_JumpCameraPositions[index] = { "x": Engine.CameraGetX(), "z": Engine.CameraGetZ() };
|
||||
g_JumpCameraPositions[index] = Engine.GetCameraPivot();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -68,26 +68,17 @@ void JSI_GameView::RegisterScriptFunctions_Settings(const ScriptInterface& scrip
|
||||
|
||||
#undef REGISTER_BOOLEAN_SCRIPT_SETTING
|
||||
|
||||
/**
|
||||
* Get the current X coordinate of the camera.
|
||||
*/
|
||||
float JSI_GameView::CameraGetX(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
||||
JS::Value JSI_GameView::GetCameraPivot(ScriptInterface::CxPrivate* pCxPrivate)
|
||||
{
|
||||
if (!g_Game || !g_Game->GetView())
|
||||
return -1;
|
||||
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
CVector3D pivot(-1, -1, -1);
|
||||
if (g_Game && g_Game->GetView())
|
||||
pivot = g_Game->GetView()->GetCameraPivot();
|
||||
|
||||
return g_Game->GetView()->GetCameraPivot().X;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current Z coordinate of the camera.
|
||||
*/
|
||||
float JSI_GameView::CameraGetZ(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
||||
{
|
||||
if (!g_Game || !g_Game->GetView())
|
||||
return -1;
|
||||
|
||||
return g_Game->GetView()->GetCameraPivot().Z;
|
||||
JS::RootedValue pivotValue(cx);
|
||||
ScriptInterface::CreateObject(cx, &pivotValue, "x", pivot.X, "z", pivot.Z);
|
||||
return pivotValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,8 +165,7 @@ void JSI_GameView::RegisterScriptFunctions(const ScriptInterface& scriptInterfac
|
||||
{
|
||||
RegisterScriptFunctions_Settings(scriptInterface);
|
||||
|
||||
scriptInterface.RegisterFunction<float, &CameraGetX>("CameraGetX");
|
||||
scriptInterface.RegisterFunction<float, &CameraGetZ>("CameraGetZ");
|
||||
scriptInterface.RegisterFunction<JS::Value, &GetCameraPivot>("GetCameraPivot");
|
||||
scriptInterface.RegisterFunction<void, entity_pos_t, entity_pos_t, &CameraMoveTo>("CameraMoveTo");
|
||||
scriptInterface.RegisterFunction<void, float, float, float, &SetCameraTarget>("SetCameraTarget");
|
||||
scriptInterface.RegisterFunction<void, entity_pos_t, entity_pos_t, entity_pos_t, entity_pos_t, entity_pos_t, entity_pos_t, &SetCameraData>("SetCameraData");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2018 Wildfire Games.
|
||||
/* Copyright (C) 2019 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -36,8 +36,7 @@ namespace JSI_GameView
|
||||
DECLARE_BOOLEAN_SCRIPT_SETTING(LockCullCamera);
|
||||
DECLARE_BOOLEAN_SCRIPT_SETTING(ConstrainCamera);
|
||||
|
||||
float CameraGetX(ScriptInterface::CxPrivate* pCxPrivate);
|
||||
float CameraGetZ(ScriptInterface::CxPrivate* pCxPrivate);
|
||||
JS::Value GetCameraPivot(ScriptInterface::CxPrivate* pCxPrivate);
|
||||
void CameraMoveTo(ScriptInterface::CxPrivate* pCxPrivate, entity_pos_t x, entity_pos_t z);
|
||||
void SetCameraTarget(ScriptInterface::CxPrivate* pCxPrivate, float x, float y, float z);
|
||||
void SetCameraData(ScriptInterface::CxPrivate* pCxPrivate, entity_pos_t x, entity_pos_t y, entity_pos_t z, entity_pos_t rotx, entity_pos_t roty, entity_pos_t zoom);
|
||||
|
||||
Reference in New Issue
Block a user