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.

87 lines
3.0KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using RobocraftX;
  7. using RobocraftX.Blocks;
  8. using RobocraftX.Blocks.Ghost;
  9. using RobocraftX.Common;
  10. using RobocraftX.Multiplayer;
  11. using RobocraftX.SimulationModeState;
  12. using RobocraftX.UECS;
  13. using Unity.Entities;
  14. using Svelto.Context;
  15. using Svelto.ECS;
  16. using Svelto.ECS.EntityStructs;
  17. using Unity.Transforms;
  18. using Unity.Mathematics;
  19. using UnityEngine;
  20. using GamecraftModdingAPI.Utility;
  21. namespace GamecraftModdingAPI.Blocks
  22. {
  23. /// <summary>
  24. /// Engine which executes block movement actions
  25. /// </summary>
  26. public class RotationEngine : IApiEngine
  27. {
  28. public string Name { get; } = "GamecraftModdingAPIRotationGameEngine";
  29. public IEntitiesDB entitiesDB { set; private get; }
  30. public bool IsInGame = false;
  31. public void Dispose()
  32. {
  33. IsInGame = false;
  34. }
  35. public void Ready()
  36. {
  37. IsInGame = true;
  38. }
  39. // implementations for Movement static class
  40. public float3 RotateBlock(uint blockID, Vector3 vector)
  41. {
  42. ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntity<RotationEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
  43. ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
  44. ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
  45. ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
  46. // main (persistent) position
  47. Quaternion newRotation = (Quaternion)rotStruct.rotation;
  48. newRotation.eulerAngles += vector;
  49. rotStruct.rotation = (quaternion)newRotation;
  50. // placement grid rotation
  51. Quaternion newGridRotation = (Quaternion)gridStruct.rotation;
  52. newGridRotation.eulerAngles += vector;
  53. gridStruct.rotation = (quaternion)newGridRotation;
  54. // rendered position
  55. Quaternion newTransRotation = (Quaternion)rotStruct.rotation;
  56. newTransRotation.eulerAngles += vector;
  57. transStruct.rotation = newTransRotation;
  58. // collision position
  59. FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Unity.Transforms.Rotation
  60. {
  61. Value = rotStruct.rotation
  62. });
  63. return ((Quaternion)rotStruct.rotation).eulerAngles;
  64. }
  65. public float3 RotateConnectedBlocks(uint blockID, Vector3 vector)
  66. {
  67. throw new NotImplementedException();
  68. }
  69. public bool IsBuildMode()
  70. {
  71. return GamecraftModdingAPI.Utility.GameState.IsBuildMode();
  72. }
  73. }
  74. }