|
- 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<LocalCosmeticInputEntityComponent>(egid))
- {
- ref LocalCosmeticInputEntityComponent ies = ref entitiesDB.QueryEntity<LocalCosmeticInputEntityComponent>(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<LocalPlayerInputEntityStruct>(egid))
- {
- ref LocalPlayerInputEntityStruct ies = ref entitiesDB.QueryEntity<LocalPlayerInputEntityStruct>(egid);
- ies = input;
- return true;
- }
- else return false;
- }
-
- public LocalCosmeticInputEntityComponent GetInput()
- {
- EGID egid = CommonExclusiveGroups.GameStateEGID;
- if (entitiesDB.Exists<LocalCosmeticInputEntityComponent>(egid))
- {
- return entitiesDB.QueryEntity<LocalCosmeticInputEntityComponent>(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<LocalPlayerInputEntityStruct>(egid))
- {
- return entitiesDB.QueryEntity<LocalPlayerInputEntityStruct>(egid);
- }
- else return default;
- }
-
- public ref LocalCosmeticInputEntityComponent GetInputRef()
- {
- EGID egid = CommonExclusiveGroups.GameStateEGID;
- return ref entitiesDB.QueryEntity<LocalCosmeticInputEntityComponent>(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);
- }
-
- internal void HandleCustomInput()
- {
- if (!LocalPlayerIDUtility.DoesLocalPlayerExist(entitiesDB))
- return;
- GetPlayerInputRef(GetLocalPlayerID()).actionMask |= _localInputCache;
- _localInputCache = default;
- }
-
- public uint GetLocalPlayerID()
- {
- return LocalPlayerIDUtility.GetLocalPlayerID(entitiesDB);
- }
- }
- }
|