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.

70 lines
2.2KB

  1. using RobocraftX.Common;
  2. using RobocraftX.DOTS;
  3. using Svelto.ECS;
  4. using Svelto.ECS.EntityStructs;
  5. using Unity.Mathematics;
  6. using Unity.Transforms;
  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 MovementEngine : IApiEngine
  16. {
  17. public string Name { get; } = "TechbloxModdingAPIMovementGameEngine";
  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 Movement static class
  30. internal float3 MoveBlock(Block block, float3 vector)
  31. {
  32. ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntityOrDefault<PositionEntityStruct>(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) position
  37. posStruct.position = vector;
  38. // placement grid position
  39. gridStruct.position = vector;
  40. // rendered position
  41. transStruct.position = vector;
  42. // collision position
  43. if (phyStruct)
  44. { //It exists
  45. FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.Get().dotsEntity, new Translation
  46. {
  47. Value = posStruct.position
  48. });
  49. }
  50. entitiesDB.QueryEntityOrDefault<GridConnectionsEntityStruct>(block).areConnectionsAssigned = false;
  51. return posStruct.position;
  52. }
  53. internal float3 GetPosition(Block block)
  54. {
  55. return entitiesDB.QueryEntityOrDefault<PositionEntityStruct>(block).position;
  56. }
  57. }
  58. }