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.Transforms;
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
|
|
|
|
|
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 MovementEngine : IApiEngine
|
2019-12-17 01:55:52 +00:00
|
|
|
|
{
|
|
|
|
|
public string Name { get; } = "GamecraftModdingAPIMovementGameEngine";
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// implementations for Movement static class
|
|
|
|
|
|
2020-07-10 22:30:58 +00:00
|
|
|
|
public float3 MoveBlock(EGID blockID, float3 vector)
|
2019-12-17 01:55:52 +00:00
|
|
|
|
{
|
2020-07-10 22:30:58 +00:00
|
|
|
|
ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity<PositionEntityStruct>(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-05-13 12:02:36 +00:00
|
|
|
|
posStruct.position = vector;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
// placement grid position
|
2020-05-13 12:02:36 +00:00
|
|
|
|
gridStruct.position = vector;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
// rendered position
|
2020-05-13 12:02:36 +00:00
|
|
|
|
transStruct.position = vector;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
// collision position
|
|
|
|
|
FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Translation
|
|
|
|
|
{
|
|
|
|
|
Value = posStruct.position
|
|
|
|
|
});
|
2020-07-10 22:30:58 +00:00
|
|
|
|
entitiesDB.QueryEntity<GridConnectionsEntityStruct>(blockID).isProcessed = false;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
return posStruct.position;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 22:30:58 +00:00
|
|
|
|
public float3 GetPosition(EGID blockID)
|
2019-12-17 01:55:52 +00:00
|
|
|
|
{
|
2020-07-10 22:30:58 +00:00
|
|
|
|
ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID);
|
2020-05-13 12:02:36 +00:00
|
|
|
|
return posStruct.position;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|