Redid inserrt logic and grid registry, added an test oven, and changed .vscode settings to try and get better debugging.
This commit is contained in:
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -27,7 +27,7 @@
|
||||
"dotnet.enableXamlTools": false,
|
||||
"dotnet.formatting.organizeImportsOnFormat": true,
|
||||
"dotnet.preferCSharpExtension": true,
|
||||
// "dotnet.server.useOmnisharp": true, // You decide
|
||||
"dotnet.server.useOmnisharp": false, // You decide
|
||||
"dotnetAcquisitionExtension.enableTelemetry": false,
|
||||
"editor.semanticHighlighting.enabled": true,
|
||||
// C# doc comment colorization gets lost with semantic highlighting, but we
|
||||
@@ -164,7 +164,7 @@
|
||||
"omnisharp.enableEditorConfigSupport": true,
|
||||
"omnisharp.enableMsBuildLoadProjectsOnDemand": false,
|
||||
"omnisharp.maxFindSymbolsItems": 3000,
|
||||
"omnisharp.useModernNet": true,
|
||||
"omnisharp.useModernNet": false,
|
||||
// Remove these if you're happy with your terminal profiles.
|
||||
"terminal.integrated.defaultProfile.windows": "Git Bash",
|
||||
"terminal.integrated.profiles.windows": {
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
using ChickenGameTest;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class ConveyorBeltStraight : Node3D
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class ConveyorBeltStraight : Node3D, IProvide<IVoxelGridRegistry>
|
||||
{
|
||||
[Export] public Vector3I VoxelPos { get; set; } = default;
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
[Export] public int Width { get; set; } = default;
|
||||
public IVoxelGridRegistry Value() => Grid;
|
||||
[Dependency] protected IVoxelGridRegistry Grid => this.DependOn<IVoxelGridRegistry>();
|
||||
private VoxelGuid _guid = default;
|
||||
public GridTransform3D VoxelTransform
|
||||
{
|
||||
get => GridTransform3D.FromGodot(Transform);
|
||||
set => Transform = value.ToGodot();
|
||||
get => GridTransform3D.FromGodot(GlobalTransform);
|
||||
set => GlobalTransform = value.ToGodot();
|
||||
}
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -48,4 +53,15 @@ public partial class ConveyorBeltStraight : Node3D
|
||||
LaneSpan.One)
|
||||
];
|
||||
}
|
||||
public void OnResolved()
|
||||
{
|
||||
_guid = Grid.Register(this, VoxelTransform.Origin);
|
||||
this.Provide();
|
||||
|
||||
}
|
||||
public override void _ExitTree()
|
||||
{
|
||||
Grid.UnRegister(_guid);
|
||||
base._ExitTree();
|
||||
}
|
||||
}
|
||||
|
||||
0
src/Items/Item
Normal file
0
src/Items/Item
Normal file
@@ -14,7 +14,7 @@ public interface IBeltItem : IDisposable
|
||||
int Height { get; }
|
||||
Node3D CreateItemVisual();
|
||||
delegate void ItemRemoved(IBeltItem item);
|
||||
event ItemRemoved Disposed;
|
||||
event ItemRemoved? Disposed;
|
||||
}
|
||||
|
||||
public class TestItem() : IBeltItem
|
||||
@@ -25,9 +25,9 @@ public class TestItem() : IBeltItem
|
||||
public int Height { get; set; }
|
||||
|
||||
public Node3D CreateItemVisual() => new MeshInstance3D() { Mesh = new BoxMesh() { Size = new(.1f, .1f, .1f) } };
|
||||
bool _disposed;
|
||||
private bool _disposed;
|
||||
|
||||
public event IBeltItem.ItemRemoved Disposed;
|
||||
public event IBeltItem.ItemRemoved? Disposed;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -35,10 +35,12 @@ public class TestItem() : IBeltItem
|
||||
{
|
||||
return;
|
||||
}
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
_disposed = true;
|
||||
Disposed?.Invoke(this);
|
||||
}
|
||||
public Dictionary<string, object> PlaceHolderData = [];
|
||||
}
|
||||
|
||||
public interface IFluidItem
|
||||
|
||||
@@ -16,21 +16,26 @@ public partial class BeltPort : Node3D, IBeltPort
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
[Dependency] public IVoxelGridRegistry Grid => this.DependOn<IVoxelGridRegistry>();
|
||||
[Dependency] public IBeltPortHost InsertLogicHost => this.DependOn<IBeltPortHost>();
|
||||
public IBeltItemInsertLogic InsertLogic { get; set; } = default!;
|
||||
[Export] public Direction Face { get; set; } = default!;
|
||||
[Export] public int Width { get; set; } = default!;
|
||||
[Export] public PortAccess Access { get; set; } = default!;
|
||||
[Export] public Path3D Path { get; set; } = default!;
|
||||
[Export] public string PortName { get; set; } = "";
|
||||
[Dependency] public IItemRenderer ItemRenderer => this.DependOn<IItemRenderer>();
|
||||
public BeltPortProfile Profile => new(GridTransform3D.FromGodot(GlobalTransform), Width, Access);
|
||||
[Dependency] public IItemTransferAnimator ItemTransferAnimator => this.DependOn<IItemTransferAnimator>(() => new CurveItemTransfer() { Curve3D = Path.Curve, Tree = GetTree(), ItemRenderer = ItemRenderer, Transform3D = GlobalTransform });
|
||||
private VoxelGuid _guid = new(Guid.Empty);
|
||||
public void OnResolved()
|
||||
{
|
||||
if (Engine.IsEditorHint())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Grid.Register<IBeltPort>(this, [.. (this as IBeltPort).Points()]);
|
||||
InsertLogic ??= InsertLogicHost.ResolveInsertLogic(this);
|
||||
_guid = Grid.Register<IBeltPort>(this, [.. (this as IBeltPort).Points()]);
|
||||
GD.Print(_guid);
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
@@ -42,7 +47,7 @@ public partial class BeltPort : Node3D, IBeltPort
|
||||
for (int i = 0; i < _itemsDummys.Count; i++)
|
||||
{
|
||||
_itemsDummys[i] = (_itemsDummys[i].i + (float)delta, _itemsDummys[i].beltItem);
|
||||
GD.Print(_itemsDummys[i].i);
|
||||
// GD.Print(_itemsDummys[i].i);
|
||||
ItemRenderer.UpdateTransform(_itemsDummys[i].beltItem, GlobalTransform * Path.Curve.SampleBakedWithRotation(_itemsDummys[i].i));
|
||||
if (_itemsDummys[i].i > Path.Curve.GetBakedLength())
|
||||
{
|
||||
@@ -52,26 +57,81 @@ public partial class BeltPort : Node3D, IBeltPort
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanAccept(IBeltItem item, LaneSpan laneSpan, float beltT)
|
||||
public override void _ExitTree()
|
||||
{
|
||||
return true;
|
||||
throw new System.NotImplementedException();
|
||||
|
||||
if (Engine.IsEditorHint())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Grid.UnRegister(_guid);
|
||||
base._ExitTree();
|
||||
}
|
||||
|
||||
public bool CanAccept(IBeltItem item, LaneSpan laneSpan, float beltT) => Access.HasFlag(PortAccess.In) && InsertLogic.CanAccept(this, item);
|
||||
List<(float i, IBeltItem beltItem)> _itemsDummys = [];
|
||||
|
||||
public bool TryInsert(IBeltItem item, LaneSpan laneSpan, float beltT)
|
||||
public bool TryInsert(IBeltItem item, LaneSpan laneSpan, float beltT) => CanAccept(item, laneSpan, beltT) && InsertLogic.CanInsert(this, item);
|
||||
// {
|
||||
// var tween = ItemTransferAnimator.StartTransfer(new(item, beltT) { LaneSpan = laneSpan }, () => GD.Print("Done"));
|
||||
// // GD.Print("gg "+laneSpan);
|
||||
// tween.TweenCallback(Callable.From(item.Dispose));
|
||||
// // GD.Print(laneSpan);
|
||||
// // GD.Print(item.ToString());
|
||||
// // _itemsDummys.Add((0,item));
|
||||
// // item.Dispose();
|
||||
// return true;
|
||||
// throw new System.NotImplementedException();
|
||||
// }
|
||||
}
|
||||
|
||||
public interface IBeltItemInsertLogic
|
||||
{
|
||||
bool CanInsert(IBeltPort beltPort, IBeltItem item);
|
||||
bool CanAccept(IBeltPort beltPort, IBeltItem item);
|
||||
}
|
||||
public interface IBeltPortHost
|
||||
{
|
||||
IBeltItemInsertLogic ResolveInsertLogic(IBeltPort port);
|
||||
}
|
||||
public class BeltPortHost : IBeltPortHost
|
||||
{
|
||||
private readonly List<(Func<IBeltPort, bool> match, Func<IBeltItemInsertLogic> factory)> _bindings
|
||||
= new();
|
||||
|
||||
public BeltPortHost Bind(
|
||||
Func<IBeltPort, bool> match,
|
||||
Func<IBeltItemInsertLogic> factory)
|
||||
{
|
||||
var tween = ItemTransferAnimator.StartTransfer(new(item, beltT) { LaneSpan = laneSpan }, () => GD.Print("Done"));
|
||||
// GD.Print("gg "+laneSpan);
|
||||
tween.TweenCallback(Callable.From(item.Dispose));
|
||||
// GD.Print(laneSpan);
|
||||
// GD.Print(item.ToString());
|
||||
// _itemsDummys.Add((0,item));
|
||||
// item.Dispose();
|
||||
return true;
|
||||
throw new System.NotImplementedException();
|
||||
_bindings.Add((match, factory));
|
||||
return this;
|
||||
}
|
||||
private HashSet<IBeltPort> _ports = [];
|
||||
public IBeltItemInsertLogic? Default;
|
||||
|
||||
/// <summary>
|
||||
/// Resolve the insert logic for a port. If no matching bind exists then the default is returned if supplied. Other wise throws an Exception.
|
||||
/// </summary>
|
||||
/// <param name="port"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public IBeltItemInsertLogic ResolveInsertLogic(IBeltPort port)
|
||||
{
|
||||
_ports.Add(port);
|
||||
foreach (var (match, factory) in _bindings)
|
||||
{
|
||||
if (match(port))
|
||||
{
|
||||
return factory();
|
||||
}
|
||||
}
|
||||
if (Default is null)
|
||||
{
|
||||
throw new Exception($"{nameof(port)} does not have any binding attached that accepts it.");
|
||||
}
|
||||
return Default;
|
||||
}
|
||||
public IEnumerable<IBeltPort> GetPorts() => _ports;
|
||||
}
|
||||
public interface IItemTransferAnimator
|
||||
{
|
||||
|
||||
@@ -254,6 +254,19 @@ public record BeltTOffset(float T) : BeltT();
|
||||
|
||||
public static class ConveyorExtensions
|
||||
{
|
||||
|
||||
public static IOption<IBeltPort> GetPortFacing(this IBeltPort slot, IVoxelGridRegistry gridRegistry)
|
||||
{
|
||||
var toCheck = new List<Vector3I>();
|
||||
for (int i = 0; i < slot.Profile.Width; i++)
|
||||
{
|
||||
toCheck.Add(slot.Profile.LocalOffset.LocalToWorld(Vector3I.Forward));
|
||||
}
|
||||
return gridRegistry
|
||||
.Get<IBeltPort>([.. toCheck])
|
||||
.Where(port => port.Profile.LocalOffset.TransformDirection(Vector3I.Forward) == slot.Profile.LocalOffset.TransformDirection(Vector3I.Back))
|
||||
.FirstOrNone();
|
||||
}
|
||||
public static BeltDirection DirectionTo(this ConveyorEnd end) => end switch
|
||||
{
|
||||
ConveyorEnd.Start => BeltDirection.TowardStart,
|
||||
|
||||
81
src/VoxelGrid/OvenTest.cs
Normal file
81
src/VoxelGrid/OvenTest.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
namespace ChickenGameTest;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using SJK.Functional;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class OvenTest : Node3D, IProvide<IBeltPortHost>, IProvide<IVoxelGridRegistry>
|
||||
{
|
||||
private BeltPortHost _insertLogic;
|
||||
public IBeltPortHost Value() => _insertLogic;
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
[Dependency] public IVoxelGridRegistry GridRegistry => this.DependOn<IVoxelGridRegistry>();
|
||||
IVoxelGridRegistry IProvide<IVoxelGridRegistry>.Value() => GridRegistry;
|
||||
public GridTransform3D VoxelTransform
|
||||
{
|
||||
get => GridTransform3D.FromGodot(GlobalTransform);
|
||||
set => GlobalTransform = value.ToGodot();
|
||||
}
|
||||
private Dictionary<string, object>? _placeholderItem = null;
|
||||
private VoxelGuid _guid = default;
|
||||
public void OnResolved()
|
||||
{
|
||||
_insertLogic = new BeltPortHost();
|
||||
_insertLogic.Bind(port => port is BeltPort beltPort && beltPort.PortName == "Input", () => new DelegateInsertBeltItemLogic(canAccept, canInsert));
|
||||
_insertLogic.Bind(port => port is BeltPort beltPort && beltPort.PortName == "OutPut", () => new DelegateInsertBeltItemLogic((_, _) => false, (_, _) => false));
|
||||
bool canAccept(IBeltPort port, IBeltItem item) => _placeholderItem is null;
|
||||
bool canInsert(IBeltPort beltPort, IBeltItem item)
|
||||
{
|
||||
_placeholderItem = (item as TestItem).PlaceHolderData;
|
||||
item.Dispose();
|
||||
GD.Print("Added Item");
|
||||
return true;
|
||||
}
|
||||
_guid = GridRegistry.Register(this, VoxelTransform.Origin);
|
||||
this.Provide();
|
||||
|
||||
var time = new Timer() { Autostart = true, OneShot = false, WaitTime = .1 };
|
||||
AddChild(time);
|
||||
|
||||
time.Timeout += () =>
|
||||
{
|
||||
if (_placeholderItem is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_placeholderItem.GetValue("temp").IfSome(some => _placeholderItem["temp"] = (float)some + 1);
|
||||
if (_placeholderItem.GetValue("temp").Map(f => ((float)f) < 5).Or(true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var port = _insertLogic.GetPorts().FirstOrNone(port => port is BeltPort beltPort && beltPort.PortName == "OutPut").Bind(f => f.GetPortFacing(GridRegistry));
|
||||
if (port.HasValue(out var v) && _placeholderItem is not null && v.TryInsert(new TestItem() { PlaceHolderData = _placeholderItem }, LaneSpan.One, 0))
|
||||
{
|
||||
_placeholderItem = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
public override void _ExitTree()
|
||||
{
|
||||
GridRegistry.UnRegister(_guid);
|
||||
base._ExitTree();
|
||||
}
|
||||
}
|
||||
public class DelegateInsertBeltItemLogic : IBeltItemInsertLogic
|
||||
{
|
||||
private readonly Func<IBeltPort, IBeltItem, bool> _canAccept;
|
||||
private readonly Func<IBeltPort, IBeltItem, bool> _canInsert;
|
||||
|
||||
public DelegateInsertBeltItemLogic(Func<IBeltPort, IBeltItem, bool> canAccept, Func<IBeltPort, IBeltItem, bool> canInsert)
|
||||
{
|
||||
_canAccept = canAccept;
|
||||
_canInsert = canInsert;
|
||||
}
|
||||
|
||||
public bool CanAccept(IBeltPort beltPort, IBeltItem item) => _canAccept(beltPort, item);
|
||||
public bool CanInsert(IBeltPort beltPort, IBeltItem item) => _canInsert(beltPort, item);
|
||||
}
|
||||
1
src/VoxelGrid/OvenTest.cs.uid
Normal file
1
src/VoxelGrid/OvenTest.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cnkblltup5guy
|
||||
@@ -255,9 +255,10 @@ public partial class TestItemConveyor : Node, IMovementConveyor
|
||||
foreach (var item in GetPorts())
|
||||
{
|
||||
var points = item.Points();
|
||||
GridRegistry.Register(item, [.. points]);
|
||||
var guid = GridRegistry.Register(item, [.. points]);
|
||||
TreeExiting += () => GridRegistry.UnRegister(guid);
|
||||
}
|
||||
StartPort.TryInsert(new TestItem(), LaneSpan.Shifted(LaneSpan.One, 0), 0);
|
||||
StartPort.TryInsert(new TestItem() { PlaceHolderData = new() { ["temp"] = 0f } }, LaneSpan.Shifted(LaneSpan.One, 0), 0);
|
||||
}
|
||||
//ChatGPT Assisted
|
||||
public BeltObstacle GetDistanceToNextItem(
|
||||
@@ -402,18 +403,7 @@ public partial class TestItemConveyor : Node, IMovementConveyor
|
||||
? cp.ToOption()
|
||||
: None<ConveyorPort>.Of());
|
||||
}
|
||||
public IOption<IBeltPort> GetPortFacing(IBeltPort slot)
|
||||
{
|
||||
var toCheck = new List<Vector3I>();
|
||||
for (int i = 0; i < slot.Profile.Width; i++)
|
||||
{
|
||||
toCheck.Add(slot.Profile.LocalOffset.LocalToWorld(Vector3I.Forward));
|
||||
}
|
||||
return GridRegistry
|
||||
.Get<IBeltPort>([.. toCheck])
|
||||
.Where(port => port.Profile.LocalOffset.TransformDirection(Vector3I.Forward) == slot.Profile.LocalOffset.TransformDirection(Vector3I.Back))
|
||||
.FirstOrNone();
|
||||
}
|
||||
public IOption<IBeltPort> GetPortFacing(IBeltPort slot) => slot.GetPortFacing(GridRegistry);
|
||||
private IOption<LaneSpan> MapLaneOrFail(
|
||||
IBeltPort from,
|
||||
IBeltPort to,
|
||||
@@ -451,10 +441,10 @@ public partial class TestItemConveyor : Node, IMovementConveyor
|
||||
newStart = Math.Max(mapped.Start, newStart);
|
||||
newEnd = Math.Min(mapped.End, newEnd);
|
||||
|
||||
GD.Print(incoming, new LaneSpan((ushort)newStart, (ushort)newEnd));
|
||||
// GD.Print(incoming, new LaneSpan((ushort)newStart, (ushort)newEnd));
|
||||
if (newStart >= newEnd)
|
||||
{
|
||||
GD.Print("none");
|
||||
// GD.Print("none");
|
||||
return None<LaneSpan>.Of();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class VoxelGridNode : Node3D, IProvide<IVoxelGridRegistry>, IProv
|
||||
IItemRenderer IProvide<IItemRenderer>.Value() => _itemRenderer;
|
||||
public override void _Ready()
|
||||
{
|
||||
GD.Print();
|
||||
// GD.Print();
|
||||
base._Ready();
|
||||
_voxelGridRegistry = new VoxelRegistry();
|
||||
_itemRenderer = new TestItemRendered();
|
||||
@@ -30,5 +30,20 @@ public partial class VoxelGridNode : Node3D, IProvide<IVoxelGridRegistry>, IProv
|
||||
AddChild(timer);//TEST
|
||||
// timer.Timeout += _itemRenderer.Tick;//TEST
|
||||
this.Provide();
|
||||
|
||||
}
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed("ui_up"))
|
||||
{
|
||||
foreach (var item in GetChildren())
|
||||
{
|
||||
if (item is ConveyorBeltStraight conveyor)
|
||||
{
|
||||
var node = conveyor.GetNode("Node") as TestItemConveyor;
|
||||
node.IsReversed = !node.IsReversed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
[gd_scene format=3 uid="uid://dfacxkkkc0v10"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dcrb286hmpli" path="res://src/VoxelGrid/VoxelGridNode.cs" id="1_tsdpe"]
|
||||
[ext_resource type="Script" uid="uid://cnkblltup5guy" path="res://src/VoxelGrid/OvenTest.cs" id="3_r7dgx"]
|
||||
[ext_resource type="PackedScene" uid="uid://h00mq2srsbfa" path="res://assets/kenney_conveyor-kit/Models/GLB format/door.glb" id="5_wk2t5"]
|
||||
[ext_resource type="Script" uid="uid://ee5aoxi8mjnw" path="res://src/VoxelGrid/BeltPort.cs" id="6_2wkfx"]
|
||||
[ext_resource type="PackedScene" uid="uid://c4h7mwnfrdesg" path="res://src/Conveyors/ConveyorBeltStraight/ConveyorBeltStraight.tscn" id="6_mxaon"]
|
||||
|
||||
@@ -53,6 +55,34 @@ Width = 1
|
||||
transform = Transform3D(1.3113416e-07, 0, -1, 0, 1, 0, 1, 0, 1.3113416e-07, 3, 0, 1)
|
||||
Width = 1
|
||||
|
||||
[node name="ConveyorBeltStraight9" parent="." unique_id=1449572266 instance=ExtResource("6_mxaon")]
|
||||
transform = Transform3D(1.3113416e-07, 0, -1, 0, 1, 0, 1, 0, 1.3113416e-07, 5, 0, 1)
|
||||
Width = 1
|
||||
|
||||
[node name="ConveyorBeltStraight10" parent="." unique_id=68139731 instance=ExtResource("6_mxaon")]
|
||||
transform = Transform3D(1.3113416e-07, 0, -1, 0, 1, 0, 1, 0, 1.3113416e-07, 6, 0, 1)
|
||||
Width = 1
|
||||
|
||||
[node name="ConveyorBeltStraight11" parent="." unique_id=358641682 instance=ExtResource("6_mxaon")]
|
||||
transform = Transform3D(1.3113416e-07, 0, -1, 0, 1, 0, 1, 0, 1.3113416e-07, 7, 0, 1)
|
||||
Width = 1
|
||||
|
||||
[node name="ConveyorBeltStraight12" parent="." unique_id=310565328 instance=ExtResource("6_mxaon")]
|
||||
transform = Transform3D(1.3113416e-07, 0, -1, 0, 1, 0, 1, 0, 1.3113416e-07, 8, 0, 1)
|
||||
Width = 1
|
||||
|
||||
[node name="ConveyorBeltStraight17" parent="." unique_id=111805683 instance=ExtResource("6_mxaon")]
|
||||
transform = Transform3D(1, 0, 1.7484555e-07, 0, 1, 0, -1.7484555e-07, 0, 1, 9, 0, 1)
|
||||
Width = 1
|
||||
|
||||
[node name="ConveyorBeltStraight18" parent="." unique_id=971476244 instance=ExtResource("6_mxaon")]
|
||||
transform = Transform3D(1, 0, 1.7484555e-07, 0, 1, 0, -1.7484555e-07, 0, 1, 9, 0, 0)
|
||||
Width = 1
|
||||
|
||||
[node name="ConveyorBeltStraight19" parent="." unique_id=87035771 instance=ExtResource("6_mxaon")]
|
||||
transform = Transform3D(1, 0, 1.7484555e-07, 0, 1, 0, -1.7484555e-07, 0, 1, 9, 0, -1)
|
||||
Width = 1
|
||||
|
||||
[node name="ConveyorBeltStraight24" parent="." unique_id=904248251 instance=ExtResource("6_mxaon")]
|
||||
transform = Transform3D(1.3113416e-07, 0, -1, 0, 1, 0, 1, 0, 1.3113416e-07, 2, 0, 1)
|
||||
Width = 1
|
||||
@@ -81,13 +111,36 @@ Width = 1
|
||||
transform = Transform3D(1.3113416e-07, 0, -1, 0, 1, 0, 1, 0, 1.3113416e-07, -3, 0, 1)
|
||||
Width = 1
|
||||
|
||||
[node name="Node3D2" type="Node3D" parent="." unique_id=1815100025 node_paths=PackedStringArray("Path")]
|
||||
transform = Transform3D(1.3113416e-07, 0, 1, 0, 1, 0, -1, 0, 1.3113416e-07, 4, 0, 1)
|
||||
[node name="OvenTest" type="Node3D" parent="." unique_id=824176002]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4, 0, 0)
|
||||
script = ExtResource("3_r7dgx")
|
||||
|
||||
[node name="Node3D2" type="Node3D" parent="OvenTest" unique_id=1815100025 node_paths=PackedStringArray("Path")]
|
||||
transform = Transform3D(1.3113416e-07, 0, 1, 0, 1, 0, -1, 0, 1.3113416e-07, 0, 0, 0)
|
||||
script = ExtResource("6_2wkfx")
|
||||
Face = 4
|
||||
Width = 1
|
||||
Access = 3
|
||||
Path = NodePath("Path3D")
|
||||
PortName = "Input"
|
||||
|
||||
[node name="Path3D" type="Path3D" parent="Node3D2" unique_id=1525648764]
|
||||
[node name="Path3D" type="Path3D" parent="OvenTest/Node3D2" unique_id=1525648764]
|
||||
curve = SubResource("Curve3D_mxaon")
|
||||
|
||||
[node name="door3" parent="OvenTest/Node3D2" unique_id=351624885 instance=ExtResource("5_wk2t5")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -7.870017e-08, 0, -0.6001501)
|
||||
|
||||
[node name="Node3D3" type="Node3D" parent="OvenTest" unique_id=1033202746 node_paths=PackedStringArray("Path")]
|
||||
transform = Transform3D(-2.1855693e-07, 0, -1, 0, 1, 0, 1, 0, -2.1855693e-07, 0, 0, 1)
|
||||
script = ExtResource("6_2wkfx")
|
||||
Face = 4
|
||||
Width = 1
|
||||
Access = 3
|
||||
Path = NodePath("Path3D2")
|
||||
PortName = "OutPut"
|
||||
|
||||
[node name="Path3D2" type="Path3D" parent="OvenTest/Node3D3" unique_id=739562310]
|
||||
curve = SubResource("Curve3D_mxaon")
|
||||
|
||||
[node name="door4" parent="OvenTest/Node3D3" unique_id=1602265662 instance=ExtResource("5_wk2t5")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.9604645e-08, 0, -0.3998499)
|
||||
|
||||
@@ -8,18 +8,21 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ChickenGameTest;
|
||||
using SJK.Functional;
|
||||
|
||||
public interface IVoxelGridRegistry
|
||||
{
|
||||
void Register<T>(T voxelNode, params Vector3I[] positions);
|
||||
void UnRegister<T>(T voxelNode, params Vector3I[] positions);
|
||||
void UnRegister(Guid id);
|
||||
VoxelGuid Register<T>(T voxelNode, params Vector3I[] positions) where T : class;
|
||||
void UnRegister(VoxelGuid id);
|
||||
IEnumerable<T> Get<T>(Vector3I voxelPos);
|
||||
IEnumerable<T> Get<T>(params Vector3I[] voxelPos);
|
||||
|
||||
}
|
||||
public readonly record struct VoxelGuid(Guid Id);
|
||||
public sealed class VoxelRegistry : IVoxelGridRegistry
|
||||
{
|
||||
private readonly Dictionary<Guid, VoxelEntry> _voxelPositions = new();
|
||||
private readonly record struct VoxelEntry(object Item, Vector3I[] Entries);
|
||||
private Dictionary<Vector3I, ICollection<object>> _data;
|
||||
public VoxelRegistry()
|
||||
{
|
||||
@@ -48,7 +51,7 @@ public sealed class VoxelRegistry : IVoxelGridRegistry
|
||||
}
|
||||
}
|
||||
|
||||
public void Register<T>(T voxelNode, params Vector3I[] positions)
|
||||
public VoxelGuid Register<T>(T voxelNode, params Vector3I[] positions) where T : class
|
||||
{
|
||||
void register(Vector3I pos, T point)
|
||||
{
|
||||
@@ -61,29 +64,21 @@ public sealed class VoxelRegistry : IVoxelGridRegistry
|
||||
}
|
||||
foreach (var pos in positions)
|
||||
{
|
||||
if (positions.Length > 1)
|
||||
{
|
||||
GD.Print("hhhhhhhhh ", pos);
|
||||
}
|
||||
register(pos, voxelNode);//TODO Acount For Rotation
|
||||
}
|
||||
var guid = new VoxelGuid(Guid.NewGuid());
|
||||
_voxelPositions[guid.Id] = new(voxelNode, positions);
|
||||
return guid;
|
||||
}
|
||||
public void UnRegister(Guid id) => throw new NotImplementedException();
|
||||
public void UnRegister<T>(T voxelNode, params Vector3I[] positions)
|
||||
public void UnRegister(VoxelGuid id) =>
|
||||
_voxelPositions.GetValue(id.Id).IfSome(e =>
|
||||
{
|
||||
void unRegister(Vector3I pos, T point)
|
||||
foreach (var item in e.Entries)
|
||||
{
|
||||
if (!_data.TryGetValue(pos, out var entrys))
|
||||
{
|
||||
return;
|
||||
}
|
||||
entrys.Remove(point);
|
||||
}
|
||||
foreach (var item in positions)
|
||||
{
|
||||
unRegister(item, voxelNode);
|
||||
}
|
||||
_data.GetValue(item).IfSome(i => i.Remove(e.Item));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public enum Direction
|
||||
|
||||
Reference in New Issue
Block a user