using System; using RobocraftX.Common; using RobocraftX.Common.Input; using RobocraftX.Players; using Svelto.ECS; using TechbloxModdingAPI.Utility; using TechbloxModdingAPI.Engines; namespace TechbloxModdingAPI.Input { public class FakeInputEngine : IApiEngine { public string Name { get; } = "TechbloxModdingAPIFakeInputEngine"; public EntitiesDB entitiesDB { set; private get; } public bool isRemovable => false; public bool IsReady = false; internal ActionInput _localInputCache; public void Dispose() { IsReady = false; } public void Ready() { IsReady = true; } public bool SendCustomInput(LocalCosmeticInputEntityComponent input) { EGID egid = CommonExclusiveGroups.GameStateEGID; if (entitiesDB.Exists(egid)) { ref LocalCosmeticInputEntityComponent ies = ref entitiesDB.QueryEntity(egid); ies = input; return true; } else return false; } public bool SendCustomPlayerInput(LocalPlayerInputEntityStruct input, uint playerID, bool remote = false) { EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers); if (entitiesDB.Exists(egid)) { ref LocalPlayerInputEntityStruct ies = ref entitiesDB.QueryEntity(egid); ies = input; return true; } else return false; } public LocalCosmeticInputEntityComponent GetInput() { EGID egid = CommonExclusiveGroups.GameStateEGID; if (entitiesDB.Exists(egid)) { return entitiesDB.QueryEntity(egid); } else return default(LocalCosmeticInputEntityComponent); } public LocalPlayerInputEntityStruct GetPlayerInput(uint playerID, bool remote = false) { EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers); if (entitiesDB.Exists(egid)) { return entitiesDB.QueryEntity(egid); } else return default; } public ref LocalCosmeticInputEntityComponent GetInputRef() { EGID egid = CommonExclusiveGroups.GameStateEGID; return ref entitiesDB.QueryEntity(egid); } public ref LocalPlayerInputEntityStruct GetPlayerInputRef(uint playerID, bool remote = false) { EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers); return ref entitiesDB.QueryEntity(egid); } internal void HandleCustomInput() { if (!LocalPlayerIDUtility.DoesLocalPlayerExist(entitiesDB)) return; GetPlayerInputRef(GetLocalPlayerID()).actionMask |= _localInputCache; _localInputCache = default; } public uint GetLocalPlayerID() { return LocalPlayerIDUtility.GetLocalPlayerID(entitiesDB); } } }