A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.1KB

  1. using System;
  2. using RobocraftX.Common;
  3. using RobocraftX.Common.Input;
  4. using RobocraftX.Players;
  5. using Svelto.ECS;
  6. using TechbloxModdingAPI.Utility;
  7. using TechbloxModdingAPI.Engines;
  8. namespace TechbloxModdingAPI.Input
  9. {
  10. public class FakeInputEngine : IApiEngine
  11. {
  12. public string Name { get; } = "TechbloxModdingAPIFakeInputEngine";
  13. public EntitiesDB entitiesDB { set; private get; }
  14. public bool isRemovable => false;
  15. public bool IsReady = false;
  16. internal ActionInput _localInputCache;
  17. public void Dispose()
  18. {
  19. IsReady = false;
  20. }
  21. public void Ready()
  22. {
  23. IsReady = true;
  24. }
  25. public bool SendCustomInput(LocalCosmeticInputEntityComponent input)
  26. {
  27. EGID egid = CommonExclusiveGroups.GameStateEGID;
  28. if (entitiesDB.Exists<LocalCosmeticInputEntityComponent>(egid))
  29. {
  30. ref LocalCosmeticInputEntityComponent ies = ref entitiesDB.QueryEntity<LocalCosmeticInputEntityComponent>(egid);
  31. ies = input;
  32. return true;
  33. }
  34. else return false;
  35. }
  36. public bool SendCustomPlayerInput(LocalPlayerInputEntityStruct input, uint playerID, bool remote = false)
  37. {
  38. EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
  39. if (entitiesDB.Exists<LocalPlayerInputEntityStruct>(egid))
  40. {
  41. ref LocalPlayerInputEntityStruct ies = ref entitiesDB.QueryEntity<LocalPlayerInputEntityStruct>(egid);
  42. ies = input;
  43. return true;
  44. }
  45. else return false;
  46. }
  47. public LocalCosmeticInputEntityComponent GetInput()
  48. {
  49. EGID egid = CommonExclusiveGroups.GameStateEGID;
  50. if (entitiesDB.Exists<LocalCosmeticInputEntityComponent>(egid))
  51. {
  52. return entitiesDB.QueryEntity<LocalCosmeticInputEntityComponent>(egid);
  53. }
  54. else return default(LocalCosmeticInputEntityComponent);
  55. }
  56. public LocalPlayerInputEntityStruct GetPlayerInput(uint playerID, bool remote = false)
  57. {
  58. EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
  59. if (entitiesDB.Exists<LocalPlayerInputEntityStruct>(egid))
  60. {
  61. return entitiesDB.QueryEntity<LocalPlayerInputEntityStruct>(egid);
  62. }
  63. else return default;
  64. }
  65. public ref LocalCosmeticInputEntityComponent GetInputRef()
  66. {
  67. EGID egid = CommonExclusiveGroups.GameStateEGID;
  68. return ref entitiesDB.QueryEntity<LocalCosmeticInputEntityComponent>(egid);
  69. }
  70. public ref LocalPlayerInputEntityStruct GetPlayerInputRef(uint playerID, bool remote = false)
  71. {
  72. EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
  73. return ref entitiesDB.QueryEntity<LocalPlayerInputEntityStruct>(egid);
  74. }
  75. internal void HandleCustomInput()
  76. {
  77. if (!LocalPlayerIDUtility.DoesLocalPlayerExist(entitiesDB))
  78. return;
  79. GetPlayerInputRef(GetLocalPlayerID()).actionMask |= _localInputCache;
  80. _localInputCache = default;
  81. }
  82. public uint GetLocalPlayerID()
  83. {
  84. return LocalPlayerIDUtility.GetLocalPlayerID(entitiesDB);
  85. }
  86. }
  87. }