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.

76 lines
2.6KB

  1. using RobocraftX.Common;
  2. using RobocraftX.DOTS;
  3. using Svelto.ECS;
  4. using Svelto.ECS.EntityStructs;
  5. using Unity.Mathematics;
  6. using UnityEngine;
  7. using TechbloxModdingAPI.Engines;
  8. using TechbloxModdingAPI.Utility;
  9. namespace TechbloxModdingAPI.Blocks.Engines
  10. {
  11. /// <summary>
  12. /// Engine which executes block movement actions
  13. /// </summary>
  14. public class RotationEngine : IApiEngine
  15. {
  16. public string Name { get; } = "TechbloxModdingAPIRotationGameEngine";
  17. public EntitiesDB entitiesDB { set; private get; }
  18. public bool isRemovable => false;
  19. public bool IsInGame = false;
  20. public void Dispose()
  21. {
  22. IsInGame = false;
  23. }
  24. public void Ready()
  25. {
  26. IsInGame = true;
  27. }
  28. // implementations for Rotation static class
  29. internal float3 RotateBlock(Block block, Vector3 vector)
  30. {
  31. ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntityOrDefault<RotationEntityStruct>(block);
  32. ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntityOrDefault<GridRotationStruct>(block);
  33. ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntityOrDefault<LocalTransformEntityStruct>(block);
  34. var phyStruct = this.entitiesDB.QueryEntityOptional<DOTSPhysicsEntityStruct>(block);
  35. // main (persistent) rotation
  36. Quaternion newRotation = rotStruct.rotation;
  37. newRotation.eulerAngles = vector;
  38. rotStruct.rotation = newRotation;
  39. // placement grid rotation
  40. gridStruct.rotation = newRotation;
  41. // rendered rotation
  42. transStruct.rotation = newRotation;
  43. // collision rotation
  44. if (phyStruct)
  45. { //It exists
  46. FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.Get().dotsEntity,
  47. new Unity.Transforms.Rotation
  48. {
  49. Value = rotStruct.rotation
  50. });
  51. }
  52. // TODO: Connections probably need to be assigned (maybe)
  53. // They are assigned during machine processing anyway
  54. entitiesDB.QueryEntityOrDefault<GridConnectionsEntityStruct>(block).areConnectionsAssigned = false;
  55. return ((Quaternion)rotStruct.rotation).eulerAngles;
  56. }
  57. internal float3 GetRotation(Block block)
  58. {
  59. ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntityOrDefault<RotationEntityStruct>(block);
  60. return ((Quaternion) rotStruct.rotation).eulerAngles;
  61. }
  62. }
  63. }