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.

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