|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using RobocraftX.Common;
- using RobocraftX.UECS;
- using Svelto.ECS;
- using Svelto.ECS.EntityStructs;
- using Unity.Mathematics;
- using UnityEngine;
-
- using GamecraftModdingAPI.Utility;
- using GamecraftModdingAPI.Engines;
-
- namespace GamecraftModdingAPI.Blocks
- {
- /// <summary>
- /// Engine which executes block movement actions
- /// </summary>
- 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
-
- internal float3 RotateBlock(EGID blockID, BlockEngine.BlockInitData data, Vector3 vector)
- {
- 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;
- }
- 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);
- // main (persistent) position
- Quaternion newRotation = rotStruct.rotation;
- newRotation.eulerAngles = vector;
- rotStruct.rotation = newRotation;
- // placement grid rotation
- Quaternion newGridRotation = gridStruct.rotation;
- newGridRotation.eulerAngles = vector;
- gridStruct.rotation = newGridRotation;
- // rendered position
- Quaternion newTransRotation = 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;
- return ((Quaternion)rotStruct.rotation).eulerAngles;
-
- }
-
- internal float3 GetRotation(EGID blockID, BlockEngine.BlockInitData data)
- {
- 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;
- }
-
- ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntity<RotationEntityStruct>(blockID);
- return ((Quaternion) rotStruct.rotation).eulerAngles;
- }
- }
- }
|