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.

73 lines
2.6KB

  1. using RobocraftX.Common;
  2. using RobocraftX.UECS;
  3. using Svelto.ECS;
  4. using Svelto.ECS.EntityStructs;
  5. using Unity.Mathematics;
  6. using UnityEngine;
  7. using GamecraftModdingAPI.Utility;
  8. using GamecraftModdingAPI.Engines;
  9. namespace GamecraftModdingAPI.Blocks
  10. {
  11. /// <summary>
  12. /// Engine which executes block movement actions
  13. /// </summary>
  14. public class RotationEngine : IApiEngine
  15. {
  16. public string Name { get; } = "GamecraftModdingAPIRotationGameEngine";
  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. public float3 RotateBlock(EGID blockID, Vector3 vector)
  30. {
  31. ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntity<RotationEntityStruct>(blockID);
  32. ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID);
  33. ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID);
  34. ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID);
  35. // main (persistent) position
  36. Quaternion newRotation = (Quaternion)rotStruct.rotation;
  37. newRotation.eulerAngles += vector;
  38. rotStruct.rotation = (quaternion)newRotation;
  39. // placement grid rotation
  40. Quaternion newGridRotation = (Quaternion)gridStruct.rotation;
  41. newGridRotation.eulerAngles += vector;
  42. gridStruct.rotation = (quaternion)newGridRotation;
  43. // rendered position
  44. Quaternion newTransRotation = (Quaternion)rotStruct.rotation;
  45. newTransRotation.eulerAngles += vector;
  46. transStruct.rotation = newTransRotation;
  47. // collision position
  48. FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Unity.Transforms.Rotation
  49. {
  50. Value = rotStruct.rotation
  51. });
  52. entitiesDB.QueryEntity<GridConnectionsEntityStruct>(blockID).isProcessed = false;
  53. return ((Quaternion)rotStruct.rotation).eulerAngles;
  54. }
  55. public float3 GetRotation(EGID blockID)
  56. {
  57. ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntity<RotationEntityStruct>(blockID);
  58. return ((Quaternion) rotStruct.rotation).eulerAngles;
  59. }
  60. }
  61. }