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.

86 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. using GamecraftModdingAPI.Engines;
  22. namespace GamecraftModdingAPI.Blocks
  23. {
  24. /// <summary>
  25. /// Engine which executes block movement actions
  26. /// </summary>
  27. public class RotationEngine : IApiEngine
  28. {
  29. public string Name { get; } = "GamecraftModdingAPIRotationGameEngine";
  30. public EntitiesDB entitiesDB { set; private get; }
  31. public bool isRemovable => false;
  32. public bool IsInGame = false;
  33. public void Dispose()
  34. {
  35. IsInGame = false;
  36. }
  37. public void Ready()
  38. {
  39. IsInGame = true;
  40. }
  41. // implementations for Rotation static class
  42. public float3 RotateBlock(uint blockID, Vector3 vector)
  43. {
  44. ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntity<RotationEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
  45. ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
  46. ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
  47. ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
  48. // main (persistent) position
  49. Quaternion newRotation = (Quaternion)rotStruct.rotation;
  50. newRotation.eulerAngles += vector;
  51. rotStruct.rotation = (quaternion)newRotation;
  52. // placement grid rotation
  53. Quaternion newGridRotation = (Quaternion)gridStruct.rotation;
  54. newGridRotation.eulerAngles += vector;
  55. gridStruct.rotation = (quaternion)newGridRotation;
  56. // rendered position
  57. Quaternion newTransRotation = (Quaternion)rotStruct.rotation;
  58. newTransRotation.eulerAngles += vector;
  59. transStruct.rotation = newTransRotation;
  60. // collision position
  61. FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Unity.Transforms.Rotation
  62. {
  63. Value = rotStruct.rotation
  64. });
  65. return ((Quaternion)rotStruct.rotation).eulerAngles;
  66. }
  67. public float3 RotateConnectedBlocks(uint blockID, Vector3 vector)
  68. {
  69. // TODO: Implement and figure out the math
  70. throw new NotImplementedException();
  71. }
  72. }
  73. }