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.

95 lines
2.7KB

  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. public void Dispose()
  17. {
  18. IsReady = false;
  19. }
  20. public void Ready()
  21. {
  22. IsReady = true;
  23. }
  24. public bool SendCustomInput(LocalInputEntityStruct input)
  25. {
  26. EGID egid = CommonExclusiveGroups.GameStateEGID;
  27. if (entitiesDB.Exists<LocalInputEntityStruct>(egid))
  28. {
  29. ref LocalInputEntityStruct ies = ref entitiesDB.QueryEntity<LocalInputEntityStruct>(egid);
  30. ies = input;
  31. return true;
  32. }
  33. else return false;
  34. }
  35. public bool SendCustomPlayerInput(LocalPlayerInputEntityStruct input, uint playerID, bool remote = false)
  36. {
  37. EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
  38. if (entitiesDB.Exists<LocalPlayerInputEntityStruct>(egid))
  39. {
  40. ref LocalPlayerInputEntityStruct ies = ref entitiesDB.QueryEntity<LocalPlayerInputEntityStruct>(egid);
  41. ies = input;
  42. return true;
  43. }
  44. else return false;
  45. }
  46. public LocalInputEntityStruct GetInput()
  47. {
  48. EGID egid = CommonExclusiveGroups.GameStateEGID;
  49. if (entitiesDB.Exists<LocalInputEntityStruct>(egid))
  50. {
  51. return entitiesDB.QueryEntity<LocalInputEntityStruct>(egid);
  52. }
  53. else return default(LocalInputEntityStruct);
  54. }
  55. public LocalPlayerInputEntityStruct GetPlayerInput(uint playerID, bool remote = false)
  56. {
  57. EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
  58. if (entitiesDB.Exists<LocalPlayerInputEntityStruct>(egid))
  59. {
  60. return entitiesDB.QueryEntity<LocalPlayerInputEntityStruct>(egid);
  61. }
  62. else return default;
  63. }
  64. public ref LocalInputEntityStruct GetInputRef()
  65. {
  66. EGID egid = CommonExclusiveGroups.GameStateEGID;
  67. return ref entitiesDB.QueryEntity<LocalInputEntityStruct>(egid);
  68. }
  69. public ref LocalPlayerInputEntityStruct GetPlayerInputRef(uint playerID, bool remote = false)
  70. {
  71. EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
  72. return ref entitiesDB.QueryEntity<LocalPlayerInputEntityStruct>(egid);
  73. }
  74. public uint GetLocalPlayerID()
  75. {
  76. return LocalPlayerIDUtility.GetLocalPlayerID(entitiesDB);
  77. }
  78. }
  79. }