Browse Source

Fix fake input

tags/v2.0.0
NorbiPeti 3 years ago
parent
commit
cc4850a073
Signed by: NorbiPeti <szatmari.norbert.peter@gmail.com> GPG Key ID: DBA4C4549A927E56
3 changed files with 77 additions and 31 deletions
  1. +35
    -21
      GamecraftModdingAPI/Input/FakeInput.cs
  2. +37
    -8
      GamecraftModdingAPI/Input/FakeInputEngine.cs
  3. +5
    -2
      GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs

+ 35
- 21
GamecraftModdingAPI/Input/FakeInput.cs View File

@@ -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)
{
inputEngine.SendCustomInput(input);
}

/// <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();
}
inputEngine.SendCustomInput(input, playerID);
{
playerID = inputEngine.GetLocalPlayerID();
}
inputEngine.SendCustomPlayerInput(input, playerID);
}

public static LocalInputEntityStruct GetInput(uint playerID = uint.MaxValue)
public static LocalInputEntityStruct GetInput()
{
return inputEngine.GetInput();
}

public static LocalPlayerInputEntityStruct GetPlayerInput(uint playerID = uint.MaxValue)
{
if (playerID == uint.MaxValue)
{
playerID = inputEngine.GetLocalPlayerID();
}
return inputEngine.GetInput(playerID);
{
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()


+ 37
- 8
GamecraftModdingAPI/Input/FakeInputEngine.cs View File

@@ -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 = 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);
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);


+ 5
- 2
GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs View File

@@ -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…
Cancel
Save