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";
|
|
|
|
|
|
2020-03-12 22:36:23 +00:00
|
|
|
|
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(uint blockID, Vector3 vector)
|
|
|
|
|
{
|
|
|
|
|
ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntity<RotationEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
|
|
|
|
|
ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
|
|
|
|
|
ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
|
|
|
|
|
ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(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
|
|
|
|
|
});
|
2020-05-13 12:02:36 +00:00
|
|
|
|
entitiesDB.QueryEntity<GridConnectionsEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP).isProcessed = false;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
return ((Quaternion)rotStruct.rotation).eulerAngles;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 12:02:36 +00:00
|
|
|
|
public float3 GetRotation(uint blockID)
|
2019-12-17 01:55:52 +00:00
|
|
|
|
{
|
2020-05-13 12:02:36 +00:00
|
|
|
|
ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntity<RotationEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
|
|
|
|
|
return ((Quaternion) rotStruct.rotation).eulerAngles;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|