Convert more things to use EcsObjectBase
Though the major benefit is only for blocks right now (using initializers)
This commit is contained in:
parent
6fedf90380
commit
b6b9a29a3c
4 changed files with 32 additions and 32 deletions
|
@ -431,7 +431,7 @@ namespace TechbloxModdingAPI
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
blockGroup?.RemoveInternal(this);
|
blockGroup?.RemoveInternal(this);
|
||||||
BlockEngine.GetBlockInfo<BlockGroupEntityComponent>(this).currentBlockGroup = value?.Id ?? -1;
|
BlockEngine.GetBlockInfo<BlockGroupEntityComponent>(this).currentBlockGroup = (int?) value?.Id.entityID ?? -1;
|
||||||
value?.AddInternal(this);
|
value?.AddInternal(this);
|
||||||
blockGroup = value;
|
blockGroup = value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using Gamecraft.Blocks.BlockGroups;
|
using Gamecraft.Blocks.BlockGroups;
|
||||||
|
using Svelto.ECS;
|
||||||
using Unity.Mathematics;
|
using Unity.Mathematics;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using TechbloxModdingAPI.Blocks;
|
using TechbloxModdingAPI.Blocks;
|
||||||
|
@ -13,10 +14,10 @@ namespace TechbloxModdingAPI
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A group of blocks that can be selected together. The placed version of blueprints. Dispose after usage.
|
/// A group of blocks that can be selected together. The placed version of blueprints. Dispose after usage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BlockGroup : ICollection<Block>, IDisposable
|
public class BlockGroup : EcsObjectBase, ICollection<Block>, IDisposable
|
||||||
{
|
{
|
||||||
internal static BlueprintEngine _engine = new BlueprintEngine();
|
internal static BlueprintEngine _engine = new BlueprintEngine();
|
||||||
public int Id { get; }
|
public override EGID Id { get; }
|
||||||
private readonly Block sourceBlock;
|
private readonly Block sourceBlock;
|
||||||
private readonly List<Block> blocks;
|
private readonly List<Block> blocks;
|
||||||
private float3 position, rotation;
|
private float3 position, rotation;
|
||||||
|
@ -26,7 +27,7 @@ namespace TechbloxModdingAPI
|
||||||
{
|
{
|
||||||
if (id == BlockGroupUtility.GROUP_UNASSIGNED)
|
if (id == BlockGroupUtility.GROUP_UNASSIGNED)
|
||||||
throw new BlockException("Cannot create a block group for blocks without a group!");
|
throw new BlockException("Cannot create a block group for blocks without a group!");
|
||||||
Id = id;
|
Id = new EGID((uint) id, BlockGroupExclusiveGroups.BlockGroupEntityGroup);
|
||||||
sourceBlock = block;
|
sourceBlock = block;
|
||||||
blocks = new List<Block>(GetBlocks());
|
blocks = new List<Block>(GetBlocks());
|
||||||
Block.Removed += OnBlockRemoved;
|
Block.Removed += OnBlockRemoved;
|
||||||
|
@ -168,7 +169,7 @@ namespace TechbloxModdingAPI
|
||||||
internal void AddInternal(Block item)
|
internal void AddInternal(Block item)
|
||||||
{
|
{
|
||||||
blocks.Add(item);
|
blocks.Add(item);
|
||||||
_engine.AddBlockToGroup(item.Id, Id);
|
_engine.AddBlockToGroup(item.Id, (int) Id.entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using RobocraftX.Physics;
|
using RobocraftX.Physics;
|
||||||
|
using Svelto.ECS;
|
||||||
using Svelto.ECS.EntityStructs;
|
using Svelto.ECS.EntityStructs;
|
||||||
using Techblox.FlyCam;
|
using Techblox.FlyCam;
|
||||||
using TechbloxModdingAPI.Players;
|
using TechbloxModdingAPI.Players;
|
||||||
|
@ -8,13 +9,13 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace TechbloxModdingAPI
|
namespace TechbloxModdingAPI
|
||||||
{
|
{
|
||||||
public class FlyCam
|
public class FlyCam : EcsObjectBase
|
||||||
{
|
{
|
||||||
private static FlyCamEngine Engine = new FlyCamEngine();
|
private static FlyCamEngine Engine = new FlyCamEngine();
|
||||||
|
|
||||||
public uint Id { get; }
|
public override EGID Id { get; }
|
||||||
|
|
||||||
public FlyCam(uint id) => Id = id;
|
public FlyCam(uint id) => Id = new EGID(id, Techblox.FlyCam.FlyCam.Group);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The local player's camera.
|
/// The local player's camera.
|
||||||
|
@ -26,11 +27,11 @@ namespace TechbloxModdingAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float3 Position
|
public float3 Position
|
||||||
{
|
{
|
||||||
get => Engine.GetComponent<PositionEntityStruct>(Id).Get().position;
|
get => Engine.GetComponent<PositionEntityStruct>(this).position;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Engine.GetComponent<PositionEntityStruct>(Id).Get().position = value;
|
Engine.GetComponent<PositionEntityStruct>(this).position = value;
|
||||||
Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().position = value;
|
Engine.GetComponent<RigidBodyEntityStruct>(this).position = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,11 +40,11 @@ namespace TechbloxModdingAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float3 Rotation
|
public float3 Rotation
|
||||||
{
|
{
|
||||||
get => ((Quaternion) Engine.GetComponent<RotationEntityStruct>(Id).Get().rotation).eulerAngles;
|
get => ((Quaternion) Engine.GetComponent<RotationEntityStruct>(this).rotation).eulerAngles;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Engine.GetComponent<RotationEntityStruct>(Id).Get().rotation = Quaternion.Euler(value);
|
Engine.GetComponent<RotationEntityStruct>(this).rotation = Quaternion.Euler(value);
|
||||||
Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().rotation = Quaternion.Euler(value);
|
Engine.GetComponent<RigidBodyEntityStruct>(this).rotation = Quaternion.Euler(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,8 +53,8 @@ namespace TechbloxModdingAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float3 MovementDirection
|
public float3 MovementDirection
|
||||||
{
|
{
|
||||||
get => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().movementDirection;
|
get => Engine.GetComponent<FlyCamMovementComponent>(this).movementDirection;
|
||||||
set => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().movementDirection = value;
|
set => Engine.GetComponent<FlyCamMovementComponent>(this).movementDirection = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -61,8 +62,8 @@ namespace TechbloxModdingAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Sprinting
|
public bool Sprinting
|
||||||
{
|
{
|
||||||
get => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().sprinting;
|
get => Engine.GetComponent<FlyCamMovementComponent>(this).sprinting;
|
||||||
set => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().sprinting = value;
|
set => Engine.GetComponent<FlyCamMovementComponent>(this).sprinting = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -70,8 +71,8 @@ namespace TechbloxModdingAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Speed
|
public float Speed
|
||||||
{
|
{
|
||||||
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speed;
|
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(this).speed;
|
||||||
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speed = value;
|
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(this).speed = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -79,8 +80,8 @@ namespace TechbloxModdingAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float SpeedSprintMultiplier
|
public float SpeedSprintMultiplier
|
||||||
{
|
{
|
||||||
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speedSprintMultiplier;
|
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(this).speedSprintMultiplier;
|
||||||
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speedSprintMultiplier = value;
|
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(this).speedSprintMultiplier = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -88,8 +89,8 @@ namespace TechbloxModdingAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Acceleration
|
public float Acceleration
|
||||||
{
|
{
|
||||||
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().acceleration;
|
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(this).acceleration;
|
||||||
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().acceleration = value;
|
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(this).acceleration = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -97,8 +98,8 @@ namespace TechbloxModdingAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float3 Velocity
|
public float3 Velocity
|
||||||
{
|
{
|
||||||
get => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().velocity;
|
get => Engine.GetComponent<RigidBodyEntityStruct>(this).velocity;
|
||||||
set => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().velocity = value;
|
set => Engine.GetComponent<RigidBodyEntityStruct>(this).velocity = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -106,8 +107,8 @@ namespace TechbloxModdingAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float3 AngularVelocity
|
public float3 AngularVelocity
|
||||||
{
|
{
|
||||||
get => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().angularVelocity;
|
get => Engine.GetComponent<RigidBodyEntityStruct>(this).angularVelocity;
|
||||||
set => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().angularVelocity = value;
|
set => Engine.GetComponent<RigidBodyEntityStruct>(this).angularVelocity = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
|
|
|
@ -19,11 +19,9 @@ namespace TechbloxModdingAPI.Players
|
||||||
public string Name => "TechbloxModdingAPIFlyCamEngine";
|
public string Name => "TechbloxModdingAPIFlyCamEngine";
|
||||||
public bool isRemovable => false;
|
public bool isRemovable => false;
|
||||||
|
|
||||||
public OptionalRef<T> GetComponent<T>(uint id) where T : unmanaged, IEntityComponent
|
public ref T GetComponent<T>(FlyCam cam) where T : unmanaged, IEntityComponent
|
||||||
{
|
{
|
||||||
if (entitiesDB.TryQueryEntitiesAndIndex<T>(id, Techblox.FlyCam.FlyCam.Group, out uint index, out var array))
|
return ref entitiesDB.QueryEntityOrDefault<T>(cam);
|
||||||
return new OptionalRef<T>(array, index);
|
|
||||||
return new OptionalRef<T>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue