|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- using RobocraftX;
- using RobocraftX.Blocks;
- using RobocraftX.Blocks.Ghost;
- using RobocraftX.Common;
- using RobocraftX.Multiplayer;
- using RobocraftX.SimulationModeState;
- using RobocraftX.UECS;
- using Unity.Entities;
- using Svelto.Context;
- using Svelto.ECS;
- using Svelto.ECS.EntityStructs;
- using Unity.Transforms;
- using Unity.Mathematics;
- using UnityEngine;
-
- using GamecraftModdingAPI.Utility;
-
- namespace GamecraftModdingAPI.Blocks
- {
- /// <summary>
- /// Engine which executes block movement actions
- /// </summary>
- public class RotationEngine : IApiEngine
- {
- public string Name { get; } = "GamecraftModdingAPIRotationGameEngine";
-
- public IEntitiesDB entitiesDB { set; private get; }
-
- public bool IsInGame = false;
-
- public void Dispose()
- {
- IsInGame = false;
- }
-
- public void Ready()
- {
- IsInGame = true;
- }
-
- // implementations for Movement static class
-
- 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
- });
- return ((Quaternion)rotStruct.rotation).eulerAngles;
-
- }
-
- public float3 RotateConnectedBlocks(uint blockID, Vector3 vector)
- {
- throw new NotImplementedException();
- }
-
- public bool IsBuildMode()
- {
- return GamecraftModdingAPI.Utility.GameState.IsBuildMode();
- }
- }
- }
|