|
- using RobocraftX.Common;
- using RobocraftX.DOTS;
- using Svelto.ECS;
- using Svelto.ECS.EntityStructs;
- using Unity.Mathematics;
- using Unity.Transforms;
-
- using TechbloxModdingAPI.Engines;
- using TechbloxModdingAPI.Utility;
-
- namespace TechbloxModdingAPI.Blocks.Engines
- {
- /// <summary>
- /// Engine which executes block movement actions
- /// </summary>
- public class MovementEngine : IApiEngine
- {
- public string Name { get; } = "TechbloxModdingAPIMovementGameEngine";
-
- public EntitiesDB entitiesDB { set; private get; }
-
- public bool isRemovable => false;
-
- public bool IsInGame = false;
-
- public void Dispose()
- {
- IsInGame = false;
- }
-
- public void Ready()
- {
- IsInGame = true;
- }
-
- // implementations for Movement static class
-
- internal float3 MoveBlock(Block block, float3 vector)
- {
- ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntityOrDefault<PositionEntityStruct>(block);
- ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntityOrDefault<GridRotationStruct>(block);
- ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntityOrDefault<LocalTransformEntityStruct>(block);
- ref DOTSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntityOrDefault<DOTSPhysicsEntityStruct>(block);
- // main (persistent) position
- posStruct.position = vector;
- // placement grid position
- gridStruct.position = vector;
- // rendered position
- transStruct.position = vector;
- // collision position
- if (phyStruct.ID != default)
- { //It exists
- FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.dotsEntity, new Translation
- {
- Value = posStruct.position
- });
- }
-
- entitiesDB.QueryEntityOrDefault<GridConnectionsEntityStruct>(block).isProcessed = false;
- return posStruct.position;
- }
-
- internal float3 GetPosition(Block block)
- {
- return entitiesDB.QueryEntityOrDefault<PositionEntityStruct>(block).position;
- }
- }
- }
|