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
|
|
|
|
|
2020-07-15 20:46:48 +00:00
|
|
|
|
internal float3 RotateBlock(EGID blockID, BlockEngine.BlockInitData data, Vector3 vector)
|
2019-12-17 01:55:52 +00:00
|
|
|
|
{
|
2020-07-15 20:46:48 +00:00
|
|
|
|
if (!entitiesDB.Exists<RotationEntityStruct>(blockID))
|
|
|
|
|
{
|
|
|
|
|
if (data.Group == null) return float3.zero;
|
|
|
|
|
var init = new EntityComponentInitializer(blockID, data.Group);
|
|
|
|
|
init.Init(new RotationEntityStruct {rotation = new Quaternion {eulerAngles = vector}});
|
|
|
|
|
init.Init(new GridRotationStruct {rotation = new Quaternion {eulerAngles = vector}});
|
|
|
|
|
init.Init(new LocalTransformEntityStruct {rotation = new Quaternion {eulerAngles = vector}});
|
|
|
|
|
return vector;
|
|
|
|
|
}
|
2020-07-10 22:30:58 +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
|
2020-07-15 20:46:48 +00:00
|
|
|
|
Quaternion newRotation = rotStruct.rotation;
|
|
|
|
|
newRotation.eulerAngles = vector;
|
|
|
|
|
rotStruct.rotation = newRotation;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
// placement grid rotation
|
2020-07-15 20:46:48 +00:00
|
|
|
|
Quaternion newGridRotation = gridStruct.rotation;
|
|
|
|
|
newGridRotation.eulerAngles = vector;
|
|
|
|
|
gridStruct.rotation = newGridRotation;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
// rendered position
|
2020-07-15 20:46:48 +00:00
|
|
|
|
Quaternion newTransRotation = rotStruct.rotation;
|
|
|
|
|
newTransRotation.eulerAngles = vector;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
transStruct.rotation = newTransRotation;
|
|
|
|
|
// collision position
|
|
|
|
|
FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Unity.Transforms.Rotation
|
|
|
|
|
{
|
|
|
|
|
Value = rotStruct.rotation
|
|
|
|
|
});
|
2020-07-10 22:30:58 +00:00
|
|
|
|
entitiesDB.QueryEntity<GridConnectionsEntityStruct>(blockID).isProcessed = false;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
return ((Quaternion)rotStruct.rotation).eulerAngles;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-15 20:46:48 +00:00
|
|
|
|
internal float3 GetRotation(EGID blockID, BlockEngine.BlockInitData data)
|
2019-12-17 01:55:52 +00:00
|
|
|
|
{
|
2020-07-15 20:46:48 +00:00
|
|
|
|
if (!entitiesDB.Exists<RotationEntityStruct>(blockID))
|
|
|
|
|
{
|
|
|
|
|
if (data.Group == null) return float3.zero;
|
|
|
|
|
var init = new EntityComponentInitializer(blockID, data.Group);
|
|
|
|
|
return init.Has<RotationEntityStruct>()
|
|
|
|
|
? (float3) ((Quaternion) init.Get<RotationEntityStruct>().rotation).eulerAngles
|
|
|
|
|
: float3.zero;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 22:30:58 +00:00
|
|
|
|
ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntity<RotationEntityStruct>(blockID);
|
2020-05-13 12:02:36 +00:00
|
|
|
|
return ((Quaternion) rotStruct.rotation).eulerAngles;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|