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.

69 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. namespace TechbloxModdingAPI.Blocks.Engines
  10. {
  11. /// <summary>
  12. /// Engine which executes block movement actions
  13. /// </summary>
  14. public class MovementEngine : IApiEngine
  15. {
  16. public string Name { get; } = "TechbloxModdingAPIMovementGameEngine";
  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 Movement static class
  29. internal float3 MoveBlock(Block block, float3 vector)
  30. {
  31. ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntityOrDefault<PositionEntityStruct>(block);
  32. ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntityOrDefault<GridRotationStruct>(block);
  33. ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntityOrDefault<LocalTransformEntityStruct>(block);
  34. var phyStruct = this.entitiesDB.QueryEntityOptional<DOTSPhysicsEntityStruct>(block);
  35. // main (persistent) position
  36. posStruct.position = vector;
  37. // placement grid position
  38. gridStruct.position = vector;
  39. // rendered position
  40. transStruct.position = vector;
  41. // collision position
  42. if (phyStruct)
  43. { //It exists
  44. FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.Get().dotsEntity, new Translation
  45. {
  46. Value = posStruct.position
  47. });
  48. }
  49. entitiesDB.QueryEntityOrDefault<GridConnectionsEntityStruct>(block).areConnectionsAssigned = false;
  50. return posStruct.position;
  51. }
  52. internal float3 GetPosition(Block block)
  53. {
  54. return entitiesDB.QueryEntityOrDefault<PositionEntityStruct>(block).position;
  55. }
  56. }
  57. }