TechbloxModdingAPI/GamecraftModdingAPI/Blocks/RotationEngine.cs

73 lines
2.6 KiB
C#
Raw Normal View History

2020-05-13 14:52:21 +00:00
using RobocraftX.Common;
2019-12-17 01:55:52 +00:00
using RobocraftX.UECS;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Unity.Mathematics;
using UnityEngine;
using GamecraftModdingAPI.Utility;
2020-05-12 00:28:26 +00:00
using GamecraftModdingAPI.Engines;
2019-12-17 01:55:52 +00:00
namespace GamecraftModdingAPI.Blocks
{
/// <summary>
/// Engine which executes block movement actions
/// </summary>
2019-12-19 20:42:50 +00:00
public class RotationEngine : IApiEngine
2019-12-17 01:55:52 +00:00
{
public string Name { get; } = "GamecraftModdingAPIRotationGameEngine";
public EntitiesDB entitiesDB { set; private get; }
2019-12-17 01:55:52 +00:00
2020-05-12 00:28:26 +00:00
public bool isRemovable => false;
public bool IsInGame = false;
2019-12-17 01:55:52 +00:00
public void Dispose()
{
IsInGame = false;
}
public void Ready()
{
IsInGame = true;
}
2020-04-12 23:31:06 +00:00
// implementations for Rotation static class
2019-12-17 01:55:52 +00:00
public float3 RotateBlock(EGID blockID, Vector3 vector)
2019-12-17 01:55:52 +00:00
{
ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntity<RotationEntityStruct>(blockID);
ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID);
ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID);
ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID);
2019-12-17 01:55:52 +00:00
// 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<GridConnectionsEntityStruct>(blockID).isProcessed = false;
2019-12-17 01:55:52 +00:00
return ((Quaternion)rotStruct.rotation).eulerAngles;
}
public float3 GetRotation(EGID blockID)
2019-12-17 01:55:52 +00:00
{
ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntity<RotationEntityStruct>(blockID);
return ((Quaternion) rotStruct.rotation).eulerAngles;
2019-12-17 01:55:52 +00:00
}
}
}