Fix fake input
This commit is contained in:
parent
677c8b0907
commit
cc4850a073
3 changed files with 78 additions and 32 deletions
|
@ -12,27 +12,41 @@ namespace GamecraftModdingAPI.Input
|
|||
{
|
||||
private static readonly FakeInputEngine inputEngine = new FakeInputEngine();
|
||||
|
||||
/// <summary>
|
||||
/// Customize the player input.
|
||||
/// </summary>
|
||||
/// <param name="input">The custom input.</param>
|
||||
/// <param name="playerID">The player. Omit this to use the local player.</param>
|
||||
public static void CustomInput(LocalInputEntityStruct input, uint playerID = uint.MaxValue)
|
||||
/// <summary>
|
||||
/// Customize the local input.
|
||||
/// </summary>
|
||||
/// <param name="input">The custom input.</param>
|
||||
public static void CustomInput(LocalInputEntityStruct input)
|
||||
{
|
||||
if (playerID == uint.MaxValue)
|
||||
{
|
||||
playerID = inputEngine.GetLocalPlayerID();
|
||||
}
|
||||
inputEngine.SendCustomInput(input, playerID);
|
||||
inputEngine.SendCustomInput(input);
|
||||
}
|
||||
|
||||
public static LocalInputEntityStruct GetInput(uint playerID = uint.MaxValue)
|
||||
/// <summary>
|
||||
/// Customize the player input.
|
||||
/// </summary>
|
||||
/// <param name="input">The custom input.</param>
|
||||
/// <param name="playerID">The player. Omit this to use the local player.</param>
|
||||
public static void CustomPlayerInput(LocalPlayerInputEntityStruct input, uint playerID = uint.MaxValue)
|
||||
{
|
||||
if (playerID == uint.MaxValue)
|
||||
{
|
||||
playerID = inputEngine.GetLocalPlayerID();
|
||||
}
|
||||
return inputEngine.GetInput(playerID);
|
||||
{
|
||||
playerID = inputEngine.GetLocalPlayerID();
|
||||
}
|
||||
inputEngine.SendCustomPlayerInput(input, playerID);
|
||||
}
|
||||
|
||||
public static LocalInputEntityStruct GetInput()
|
||||
{
|
||||
return inputEngine.GetInput();
|
||||
}
|
||||
|
||||
public static LocalPlayerInputEntityStruct GetPlayerInput(uint playerID = uint.MaxValue)
|
||||
{
|
||||
if (playerID == uint.MaxValue)
|
||||
{
|
||||
playerID = inputEngine.GetLocalPlayerID();
|
||||
}
|
||||
return inputEngine.GetPlayerInput(playerID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -59,7 +73,7 @@ namespace GamecraftModdingAPI.Input
|
|||
{
|
||||
playerID = inputEngine.GetLocalPlayerID();
|
||||
}
|
||||
ref LocalInputEntityStruct currentInput = ref inputEngine.GetInputRef(playerID);
|
||||
ref LocalInputEntityStruct currentInput = ref inputEngine.GetInputRef();
|
||||
//Utility.Logging.CommandLog($"Current sim frame {currentInput.frame}");
|
||||
// set inputs
|
||||
switch(hotbar)
|
||||
|
@ -107,10 +121,10 @@ namespace GamecraftModdingAPI.Input
|
|||
{
|
||||
playerID = inputEngine.GetLocalPlayerID();
|
||||
}
|
||||
ref LocalInputEntityStruct currentInput = ref inputEngine.GetInputRef(playerID);
|
||||
//Utility.Logging.CommandLog($"Current sim frame {currentInput.frame}");
|
||||
// set inputs - TODO
|
||||
/*if (toggleMode) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleTimeRunningMode;
|
||||
ref LocalPlayerInputEntityStruct currentInput = ref inputEngine.GetPlayerInputRef(playerID);
|
||||
//Utility.Logging.CommandLog($"Current sim frame {currentInput.frame}");
|
||||
// set inputs
|
||||
if (toggleMode) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleTimeRunningMode;
|
||||
if (forward) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Forward;
|
||||
if (backward) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Backward;
|
||||
if (up) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Up;
|
||||
|
@ -134,7 +148,7 @@ namespace GamecraftModdingAPI.Input
|
|||
if (rotateBlockCounterclockwise) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.RotateBlockAnticlockwise;
|
||||
if (cutSelection) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.CutSelection;
|
||||
if (copySelection) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.CopySelection;
|
||||
if (deleteSelection) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.DeleteSelection;*/
|
||||
if (deleteSelection) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.DeleteSelection;
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
|
||||
using RobocraftX.Common;
|
||||
using RobocraftX.Common.Input;
|
||||
using RobocraftX.Players;
|
||||
using Svelto.ECS;
|
||||
|
@ -29,9 +30,9 @@ namespace GamecraftModdingAPI.Input
|
|||
IsReady = true;
|
||||
}
|
||||
|
||||
public bool SendCustomInput(LocalInputEntityStruct input, uint playerID, bool remote = false)
|
||||
public bool SendCustomInput(LocalInputEntityStruct input)
|
||||
{
|
||||
EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
|
||||
EGID egid = CommonExclusiveGroups.GameStateEGID;
|
||||
if (entitiesDB.Exists<LocalInputEntityStruct>(egid))
|
||||
{
|
||||
ref LocalInputEntityStruct ies = ref entitiesDB.QueryEntity<LocalInputEntityStruct>(egid);
|
||||
|
@ -41,22 +42,50 @@ namespace GamecraftModdingAPI.Input
|
|||
else return false;
|
||||
}
|
||||
|
||||
public LocalInputEntityStruct GetInput(uint playerID, bool remote = false)
|
||||
public bool SendCustomPlayerInput(LocalPlayerInputEntityStruct input, uint playerID, bool remote = false)
|
||||
{
|
||||
EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
|
||||
if (entitiesDB.Exists<LocalInputEntityStruct>(egid))
|
||||
if (entitiesDB.Exists<LocalPlayerInputEntityStruct>(egid))
|
||||
{
|
||||
return entitiesDB.QueryEntity<LocalInputEntityStruct>(egid);
|
||||
ref LocalPlayerInputEntityStruct ies = ref entitiesDB.QueryEntity<LocalPlayerInputEntityStruct>(egid);
|
||||
ies = input;
|
||||
return true;
|
||||
}
|
||||
else return default(LocalInputEntityStruct);
|
||||
else return false;
|
||||
}
|
||||
|
||||
public ref LocalInputEntityStruct GetInputRef(uint playerID, bool remote = false)
|
||||
public LocalInputEntityStruct GetInput()
|
||||
{
|
||||
EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
|
||||
EGID egid = CommonExclusiveGroups.GameStateEGID;
|
||||
if (entitiesDB.Exists<LocalInputEntityStruct>(egid))
|
||||
{
|
||||
return entitiesDB.QueryEntity<LocalInputEntityStruct>(egid);
|
||||
}
|
||||
else return default(LocalInputEntityStruct);
|
||||
}
|
||||
|
||||
public LocalPlayerInputEntityStruct GetPlayerInput(uint playerID, bool remote = false)
|
||||
{
|
||||
EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
|
||||
if (entitiesDB.Exists<LocalPlayerInputEntityStruct>(egid))
|
||||
{
|
||||
return entitiesDB.QueryEntity<LocalPlayerInputEntityStruct>(egid);
|
||||
}
|
||||
else return default;
|
||||
}
|
||||
|
||||
public ref LocalInputEntityStruct GetInputRef()
|
||||
{
|
||||
EGID egid = CommonExclusiveGroups.GameStateEGID;
|
||||
return ref entitiesDB.QueryEntity<LocalInputEntityStruct>(egid);
|
||||
}
|
||||
|
||||
public ref LocalPlayerInputEntityStruct GetPlayerInputRef(uint playerID, bool remote = false)
|
||||
{
|
||||
EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
|
||||
return ref entitiesDB.QueryEntity<LocalPlayerInputEntityStruct>(egid);
|
||||
}
|
||||
|
||||
public uint GetLocalPlayerID()
|
||||
{
|
||||
return LocalPlayerIDUtility.GetLocalPlayerID(entitiesDB);
|
||||
|
|
|
@ -472,8 +472,11 @@ namespace GamecraftModdingAPI.Tests
|
|||
|
||||
public override void OnUpdate()
|
||||
{
|
||||
if(UnityEngine.Input.GetKeyDown(KeyCode.Backslash))
|
||||
FakeInput.CustomInput(new LocalInputEntityStruct{commandLineToggleInput = true});
|
||||
if (UnityEngine.Input.GetKeyDown(KeyCode.End))
|
||||
{
|
||||
Console.WriteLine("Pressed button to toggle console");
|
||||
FakeInput.CustomInput(new LocalInputEntityStruct {commandLineToggleInput = true});
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
|
|
Loading…
Reference in a new issue