using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RobocraftX;
using RobocraftX.Blocks;
using RobocraftX.Blocks.Ghost;
using RobocraftX.Common;
using RobocraftX.Multiplayer;
using RobocraftX.SimulationModeState;
using RobocraftX.UECS;
using Unity.Entities;
using Svelto.Context;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Unity.Transforms;
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;
}
}
}