using RobocraftX.Common; using RobocraftX.DOTS; using Svelto.ECS; using Svelto.ECS.EntityStructs; using Unity.Mathematics; using UnityEngine; using TechbloxModdingAPI.Engines; using TechbloxModdingAPI.Utility; namespace TechbloxModdingAPI.Blocks.Engines { /// /// Engine which executes block movement actions /// public class RotationEngine : IApiEngine { public string Name { get; } = "TechbloxModdingAPIRotationGameEngine"; 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 Rotation static class internal float3 RotateBlock(Block block, Vector3 vector) { ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntityOrDefault(block); ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntityOrDefault(block); ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntityOrDefault(block); var phyStruct = this.entitiesDB.QueryEntityOptional(block); // main (persistent) rotation Quaternion newRotation = rotStruct.rotation; newRotation.eulerAngles = vector; rotStruct.rotation = newRotation; // placement grid rotation gridStruct.rotation = newRotation; // rendered rotation transStruct.rotation = newRotation; // collision rotation if (phyStruct) { //It exists FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.Get().dotsEntity, new Unity.Transforms.Rotation { Value = rotStruct.rotation }); } // TODO: Connections probably need to be assigned (maybe) // They are assigned during machine processing anyway entitiesDB.QueryEntityOrDefault(block).areConnectionsAssigned = false; return ((Quaternion)rotStruct.rotation).eulerAngles; } internal float3 GetRotation(Block block) { ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntityOrDefault(block); return ((Quaternion) rotStruct.rotation).eulerAngles; } } }