TechbloxModdingAPI/GamecraftModdingAPI/Input/FakeInputEngine.cs

95 lines
2.7 KiB
C#
Raw Normal View History

2020-04-04 18:48:12 +00:00
using System;
2021-04-19 23:23:39 +00:00
using RobocraftX.Common;
2020-04-04 18:48:12 +00:00
using RobocraftX.Common.Input;
using RobocraftX.Players;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
2020-05-12 00:28:26 +00:00
using GamecraftModdingAPI.Engines;
2020-04-04 18:48:12 +00:00
namespace GamecraftModdingAPI.Input
{
public class FakeInputEngine : IApiEngine
{
public string Name { get; } = "GamecraftModdingAPIFakeInputEngine";
public EntitiesDB entitiesDB { set; private get; }
2020-05-12 00:28:26 +00:00
public bool isRemovable => false;
2020-04-04 18:48:12 +00:00
public bool IsReady = false;
public void Dispose()
{
IsReady = false;
}
public void Ready()
{
IsReady = true;
}
2021-04-19 23:23:39 +00:00
public bool SendCustomInput(LocalInputEntityStruct input)
2020-04-04 18:48:12 +00:00
{
2021-04-19 23:23:39 +00:00
EGID egid = CommonExclusiveGroups.GameStateEGID;
if (entitiesDB.Exists<LocalInputEntityStruct>(egid))
2020-04-04 18:48:12 +00:00
{
ref LocalInputEntityStruct ies = ref entitiesDB.QueryEntity<LocalInputEntityStruct>(egid);
2020-04-04 18:48:12 +00:00
ies = input;
return true;
}
else return false;
}
2021-04-19 23:23:39 +00:00
public bool SendCustomPlayerInput(LocalPlayerInputEntityStruct input, uint playerID, bool remote = false)
2020-04-04 18:48:12 +00:00
{
EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
2021-04-19 23:23:39 +00:00
if (entitiesDB.Exists<LocalPlayerInputEntityStruct>(egid))
2020-04-04 18:48:12 +00:00
{
2021-04-19 23:23:39 +00:00
ref LocalPlayerInputEntityStruct ies = ref entitiesDB.QueryEntity<LocalPlayerInputEntityStruct>(egid);
ies = input;
return true;
2020-04-04 18:48:12 +00:00
}
2021-04-19 23:23:39 +00:00
else return false;
2020-04-04 18:48:12 +00:00
}
2021-04-19 23:23:39 +00:00
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)
2020-04-04 18:48:12 +00:00
{
2021-04-19 23:23:39 +00:00
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);
2020-04-04 18:48:12 +00:00
}
2021-04-19 23:23:39 +00:00
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);
}
2020-04-04 18:48:12 +00:00
public uint GetLocalPlayerID()
{
return LocalPlayerIDUtility.GetLocalPlayerID(entitiesDB);
}
}
}