Skip to content

Commit

Permalink
Rework of players handling
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Aug 15, 2023
1 parent ac5729e commit 5683db0
Show file tree
Hide file tree
Showing 7 changed files with 609 additions and 542 deletions.
14 changes: 0 additions & 14 deletions CVRLua/DestructionDetector.cs

This file was deleted.

111 changes: 63 additions & 48 deletions CVRLua/Lua/LuaDefs/PlayerDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ internal static void Init()
ms_instanceProperties.Add(("avatarScale", (GetAvatarScale, null)));
ms_instanceProperties.Add(("playerHeight", (GetPlayerHeight, null)));
ms_instanceProperties.Add(("playerScale", (GetPlayerScale, null)));
ms_instanceProperties.Add(("cameraPosition", (GetCameraPosition, null)));
ms_instanceProperties.Add(("cameraRotation", (GetCameraRotation, null)));
ms_instanceProperties.Add(("viewPosition", (GetViewPosition, null)));
ms_instanceProperties.Add(("viewRotation", (GetViewRotation, null)));
ms_instanceProperties.Add(("inVR", (GetInVR, null)));
ms_instanceProperties.Add(("inFBT", (GetFBT, null)));
ms_instanceProperties.Add(("hasAvatar", (GetAvatar, null)));
Expand All @@ -59,6 +59,7 @@ internal static void Init()
ms_instanceProperties.Add(("lookVector", (GetLookVector, null)));
ms_instanceProperties.Add(("individualFingerTracking", (GetIndividualFingerTracking, null)));
ms_instanceProperties.Add(("fingerCurls", (GetFingerCurls, null)));
ms_instanceProperties.Add(("fingerSpreads", (GetFingerSpreads, null)));

ms_instanceMethods.Add((nameof(Teleport), Teleport));
ms_instanceMethods.Add((nameof(SetImmobilized), SetImmobilized));
Expand Down Expand Up @@ -232,8 +233,8 @@ static int GetName(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetName(out string l_name))
l_argReader.PushString(l_name);
if(!l_argReader.HasErrors())
l_argReader.PushString(l_player.GetName());
else
l_argReader.PushBoolean(false);

Expand All @@ -245,8 +246,8 @@ static int GetUuid(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetId(out string l_id))
l_argReader.PushString(l_id);
if(!l_argReader.HasErrors())
l_argReader.PushString(l_player.GetId());
else
l_argReader.PushBoolean(false);

Expand All @@ -259,8 +260,8 @@ static int GetPosition(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetPosition(out UnityEngine.Vector3 l_pos))
l_argReader.PushObject(new Wrappers.Vector3(l_pos));
if(!l_argReader.HasErrors())
l_argReader.PushObject(new Wrappers.Vector3(l_player.GetPosition()));
else
l_argReader.PushBoolean(false);

Expand All @@ -273,8 +274,8 @@ static int GetRotation(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetRotation(out UnityEngine.Quaternion l_rot))
l_argReader.PushObject(new Wrappers.Quaternion(l_rot));
if(!l_argReader.HasErrors())
l_argReader.PushObject(new Wrappers.Quaternion(l_player.GetRotation()));
else
l_argReader.PushBoolean(false);

Expand All @@ -287,8 +288,8 @@ static int GetAvatarHeight(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetAvatarHeight(out float l_height))
l_argReader.PushNumber(l_height);
if(!l_argReader.HasErrors())
l_argReader.PushNumber(l_player.GetAvatarHeight());
else
l_argReader.PushBoolean(false);

Expand All @@ -301,8 +302,8 @@ static int GetAvatarScale(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetAvatarScale(out float l_scale))
l_argReader.PushNumber(l_scale);
if(!l_argReader.HasErrors())
l_argReader.PushNumber(l_player.GetAvatarScale());
else
l_argReader.PushBoolean(false);

Expand All @@ -315,8 +316,8 @@ static int GetPlayerHeight(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetPlayerHeight(out float l_height))
l_argReader.PushNumber(l_height);
if(!l_argReader.HasErrors())
l_argReader.PushNumber(l_player.GetPlayerHeight());
else
l_argReader.PushBoolean(false);

Expand All @@ -329,36 +330,36 @@ static int GetPlayerScale(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetPlayerScale(out float l_scale))
l_argReader.PushNumber(l_scale);
if(!l_argReader.HasErrors())
l_argReader.PushNumber(l_player.GetPlayerScale());
else
l_argReader.PushBoolean(false);

l_argReader.LogError();
return 1;
}

static int GetCameraPosition(IntPtr p_state)
static int GetViewPosition(IntPtr p_state)
{
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetCameraPosition(out var l_pos))
l_argReader.PushObject(new Wrappers.Vector3(l_pos));
if(!l_argReader.HasErrors())
l_argReader.PushObject(new Wrappers.Vector3(l_player.GetViewPosition()));
else
l_argReader.PushBoolean(false);

l_argReader.LogError();
return 1;
}

static int GetCameraRotation(IntPtr p_state)
static int GetViewRotation(IntPtr p_state)
{
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetCameraRotation(out var l_rot))
l_argReader.PushObject(new Wrappers.Quaternion(l_rot));
if(!l_argReader.HasErrors())
l_argReader.PushObject(new Wrappers.Quaternion(l_player.GetViewRotation()));
else
l_argReader.PushBoolean(false);

Expand Down Expand Up @@ -539,8 +540,8 @@ static int GetLeftHandPosition(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetLeftHandPosition(out var l_pos))
l_argReader.PushObject(new Wrappers.Vector3(l_pos));
if(!l_argReader.HasErrors())
l_argReader.PushObject(new Wrappers.Vector3(l_player.GetLeftHandPosition()));
else
l_argReader.PushBoolean(false);

Expand All @@ -553,8 +554,8 @@ static int GetLeftHandRotation(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetLeftHandRotation(out var l_rot))
l_argReader.PushObject(new Wrappers.Quaternion(l_rot));
if(!l_argReader.HasErrors())
l_argReader.PushObject(new Wrappers.Quaternion(l_player.GetLeftHandRotation()));
else
l_argReader.PushBoolean(false);

Expand All @@ -567,8 +568,8 @@ static int GetRightHandPosition(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetRightHandPosition(out var l_pos))
l_argReader.PushObject(new Wrappers.Vector3(l_pos));
if(!l_argReader.HasErrors())
l_argReader.PushObject(new Wrappers.Vector3(l_player.GetRightHandPosition()));
else
l_argReader.PushBoolean(false);

Expand All @@ -581,8 +582,8 @@ static int GetRightHandRotation(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetRightHandRotation(out var l_rot))
l_argReader.PushObject(new Wrappers.Quaternion(l_rot));
if(!l_argReader.HasErrors())
l_argReader.PushObject(new Wrappers.Quaternion(l_player.GetRightHandRotation()));
else
l_argReader.PushBoolean(false);

Expand All @@ -595,8 +596,8 @@ static int GetLeftHandGesture(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetLeftHandGetsture(out float l_gesture))
l_argReader.PushNumber(l_gesture);
if(!l_argReader.HasErrors())
l_argReader.PushNumber(l_player.GetLeftHandGetsture());
else
l_argReader.PushBoolean(false);

Expand All @@ -609,8 +610,8 @@ static int GetRightHandGesture(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetRightHandGetsture(out float l_gesture))
l_argReader.PushNumber(l_gesture);
if(!l_argReader.HasErrors())
l_argReader.PushNumber(l_player.GetRightHandGetsture());
else
l_argReader.PushBoolean(false);

Expand All @@ -637,8 +638,8 @@ static int GetZoomFactor(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetZoomFactor(out float l_factor))
l_argReader.PushNumber(l_factor);
if(!l_argReader.HasErrors())
l_argReader.PushNumber(l_player.GetZoomFactor());
else
l_argReader.PushBoolean(false);

Expand All @@ -651,8 +652,8 @@ static int GetMovementVector(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetMovementVector(out var l_move))
l_argReader.PushObject(new Wrappers.Vector2(l_move));
if(!l_argReader.HasErrors())
l_argReader.PushObject(new Wrappers.Vector2(l_player.GetMovementVector()));
else
l_argReader.PushBoolean(false);

Expand All @@ -665,8 +666,8 @@ static int GetLookVector(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetLookVector(out var l_look))
l_argReader.PushObject(new Wrappers.Vector2(l_look));
if(!l_argReader.HasErrors())
l_argReader.PushObject(new Wrappers.Vector2(l_player.GetLookVector()));
else
l_argReader.PushBoolean(false);

Expand All @@ -693,8 +694,22 @@ static int GetFingerCurls(IntPtr p_state)
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors() && l_player.GetFingerCurls(out var l_curls))
l_argReader.PushTable(l_curls);
if(!l_argReader.HasErrors())
l_argReader.PushTable(l_player.GetFingerCurls());
else
l_argReader.PushBoolean(false);

l_argReader.LogError();
return 1;
}

static int GetFingerSpreads(IntPtr p_state)
{
var l_argReader = new LuaArgReader(p_state);
Players.Player l_player = null;
l_argReader.ReadObject(ref l_player);
if(!l_argReader.HasErrors())
l_argReader.PushTable(l_player.GetFingerSpreads());
else
l_argReader.PushBoolean(false);

Expand Down Expand Up @@ -770,8 +785,8 @@ static int GetBonePosition(IntPtr p_state)
UnityEngine.HumanBodyBones l_bone = UnityEngine.HumanBodyBones.LastBone;
l_argReader.ReadObject(ref l_player);
l_argReader.ReadEnum(ref l_bone);
if(!l_argReader.HasErrors() && l_player.GetBonePosition(l_bone, out var l_pos))
l_argReader.PushObject(new Wrappers.Vector3(l_pos));
if(!l_argReader.HasErrors())
l_argReader.PushObject(new Wrappers.Vector3(l_player.GetBonePosition(l_bone)));
else
l_argReader.PushBoolean(false);

Expand All @@ -786,8 +801,8 @@ static int GetBoneRotation(IntPtr p_state)
UnityEngine.HumanBodyBones l_bone = UnityEngine.HumanBodyBones.LastBone;
l_argReader.ReadObject(ref l_player);
l_argReader.ReadEnum(ref l_bone);
if(!l_argReader.HasErrors() && l_player.GetBoneRotation(l_bone, out var l_rot))
l_argReader.PushObject(new Wrappers.Quaternion(l_rot));
if(!l_argReader.HasErrors())
l_argReader.PushObject(new Wrappers.Quaternion(l_player.GetBoneRotation(l_bone)));
else
l_argReader.PushBoolean(false);

Expand Down
12 changes: 9 additions & 3 deletions CVRLua/LuaHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,31 @@ public enum ScriptEvent
OnEnable,
OnDisable,
OnDestroy,
OnGUI,
OnCollisionEnter,
OnCollisionExit,
OnCollisionStay,
OnTriggerEnter,
OnTriggerExit,
OnTriggerStay,
OnAnimatorIK,

OnMessage,

OnPlayerJoin,
OnPlayerLeft,

OnInteractableGrab,
OnInteractableDrop,
OnInteractableUp,
OnInteractableDown,
OnInteractableGazeEnter,
OnInteractableGazeExit,
OnPlayerJoin,
OnPlayerLeft,
OnEnterSeat,
OnExitSeat,

OnAttachmentAttach,
OnAttachmentDeattach,

OnButtonClick,
OnToggleChange,
OnSliderChange
Expand Down
Loading

0 comments on commit 5683db0

Please sign in to comment.