using RobocraftX.Common; using RobocraftX.UECS; using Svelto.ECS; using Svelto.ECS.EntityStructs; using Unity.Mathematics; using UnityEngine; using GamecraftModdingAPI.Utility; using GamecraftModdingAPI.Engines; namespace GamecraftModdingAPI.Blocks { /// /// Engine which executes block movement actions /// public class RotationEngine : IApiEngine { public string Name { get; } = "GamecraftModdingAPIRotationGameEngine"; 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 public float3 RotateBlock(uint blockID, Vector3 vector) { ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); // main (persistent) position Quaternion newRotation = (Quaternion)rotStruct.rotation; newRotation.eulerAngles += vector; rotStruct.rotation = (quaternion)newRotation; // placement grid rotation Quaternion newGridRotation = (Quaternion)gridStruct.rotation; newGridRotation.eulerAngles += vector; gridStruct.rotation = (quaternion)newGridRotation; // rendered position Quaternion newTransRotation = (Quaternion)rotStruct.rotation; newTransRotation.eulerAngles += vector; transStruct.rotation = newTransRotation; // collision position FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Unity.Transforms.Rotation { Value = rotStruct.rotation }); entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP).isProcessed = false; return ((Quaternion)rotStruct.rotation).eulerAngles; } public float3 GetRotation(uint blockID) { ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); return ((Quaternion) rotStruct.rotation).eulerAngles; } } }