Cleaning house

This commit is contained in:
2026-02-14 10:40:10 -05:00
parent 6cb3c2e53f
commit 44a9ce41f3
3 changed files with 54 additions and 16 deletions

View File

@@ -27,7 +27,7 @@ public abstract partial class Behavior : Docker
/// <summary>
/// Identifiers for Behaviors.
/// </summary>
public List<string> Tags;
public HashSet<string> Tags;

View File

@@ -1,9 +1,13 @@
using System.Collections.Generic;
using System.Collections.Immutable;
namespace Awperative;
public abstract partial class Behavior : Docker
{
public Scene Scene => __QueryScene();
private Scene __QueryScene() {
if (Docker is Scene scene) return scene;
@@ -12,28 +16,53 @@ public abstract partial class Behavior : Docker
return null;
}
public Docker[] Dockers => __QueryDockers();
private Docker[] __QueryDockers()
{
public ImmutableArray<Docker> Dockers => __QueryDockers();
private ImmutableArray<Docker> __QueryDockers() {
List<Docker> returnValue = [];
Docker currentDocker = Docker;
while (!(currentDocker is Scene))
{
if (currentDocker is Behavior behavior)
{
if (currentDocker is Behavior behavior) {
returnValue.Add(currentDocker);
currentDocker = behavior.Docker;
}
returnValue.Add(currentDocker);
return ImmutableArray.Create<Docker>(returnValue.ToArray());
}
public Behavior Parent => __QueryParent();
private Behavior __QueryParent() {
if (Docker is Behavior behavior)
return behavior;
return null;
}
public ImmutableArray<Behavior> Parents => __QueryBehaviors();
private ImmutableArray<Behavior> __QueryBehaviors() {
List<Behavior> returnValue = [];
Docker currentDocker = Docker;
while (!(currentDocker is Scene))
if (currentDocker is Behavior behavior) {
returnValue.Add(behavior);
currentDocker = behavior.Docker;
}
}
returnValue.Add(currentDocker);
return returnValue.ToArray();
return ImmutableArray.Create<Behavior>(returnValue.ToArray());
}
public Behavior[] Parents => __QueryParents();
}

View File

@@ -9,6 +9,7 @@ public abstract partial class Docker
internal HashSet<Behavior> _behaviors = [];
internal void Add(Behavior behavior) => _behaviors.Add(behavior);
public Behavior Add<Generic>() where Generic : Behavior => Add<Generic>([]);
public Behavior Add<Generic>(object[] __args) where Generic : Behavior {
if(typeof(Generic).GetConstructor((Type[]) __args) == null) { Debug.LogError("Component does not contain a valid constructor"); return null; };
@@ -26,6 +27,14 @@ public abstract partial class Docker
}
public void Transfer(Behavior __behavior, Docker __docker) {
if (!_behaviors.Contains(__behavior)) { Debug.LogError("Docker does not have ownership of Behavior"); return; }
__docker.Add(__behavior);
_behaviors.Remove(__behavior);
__behavior.Docker = __docker;
}