diff --git a/Awperative/Kernel/ComponentInstance/Behavior.md b/Awperative/Kernel/Component/Behavior.md
similarity index 100%
rename from Awperative/Kernel/ComponentInstance/Behavior.md
rename to Awperative/Kernel/Component/Behavior.md
diff --git a/Awperative/Kernel/ComponentInstance/Core.cs b/Awperative/Kernel/Component/Component.cs
similarity index 90%
rename from Awperative/Kernel/ComponentInstance/Core.cs
rename to Awperative/Kernel/Component/Component.cs
index 197ac29..e97e0fb 100644
--- a/Awperative/Kernel/ComponentInstance/Core.cs
+++ b/Awperative/Kernel/Component/Component.cs
@@ -7,12 +7,7 @@ namespace Awperative;
-///
-/// The lowest level scripting class in Awperative. Components are scene level and provide access to all scene level methods, can be applied to any docker and inherited
-/// Sadly component does not have excessive access to specific types.
-/// Anything that inherits Component is built to work in any DockerEntity, which leads to generic
-/// Assumptions. If you want to make a body specific or scene specific component both classes are available.
-///
+
public abstract partial class Component : ComponentDocker
{
@@ -109,7 +104,7 @@ public abstract partial class Component : ComponentDocker
/// Identifiers for Components.
///
public ImmutableArray Tags => [.._tags];
- internal HashSet _tags;
+ internal HashSet _tags = [];
@@ -148,6 +143,9 @@ public abstract partial class Component : ComponentDocker
if (currentComponentDocker is Component Component) {
returnValue.Add(currentComponentDocker);
currentComponentDocker = Component.ComponentDocker;
+ } else {
+ Debug.LogError("Component has a Parent that is not a Scene or Component, Please do not use the Docker class unless you know what you are doing!", ["Component", "Type", "Docker"],
+ [GetHashCode().ToString(), GetType().ToString(), ComponentDocker.GetHashCode().ToString()]);
}
}
diff --git a/Awperative/Kernel/ComponentDocker/ComponentDocker.cs b/Awperative/Kernel/ComponentDocker/ComponentDocker.cs
index bcc3663..aacacac 100644
--- a/Awperative/Kernel/ComponentDocker/ComponentDocker.cs
+++ b/Awperative/Kernel/ComponentDocker/ComponentDocker.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
@@ -10,7 +9,7 @@ namespace Awperative;
/// Base class for all Awperative Entities. Responsible for Managing hierarchy between Components and Scenes, has Extensive Component Manipulation Available.
/// Also transfers Time and Carries most of the responsibilities akin to the Component.
///
-/// Please don't inherit this I don't know why you would
+/// Please don't inherit this. I don't know why you would
/// Avery Norris
public abstract partial class ComponentDocker
{
@@ -31,16 +30,19 @@ public abstract partial class ComponentDocker
+ private readonly static Comparer _componentSorter = Comparer.Create((a, b) => {
+ int result = b.Priority.CompareTo(a.Priority);
+ return (result != 0) ? result : a.GetHashCode().CompareTo(b.GetHashCode());
+ });
+
+
///
/// Core of Docker, contains all of our precious Components. Sorts them by their priorities with highest going first.
/// If they are equal it defaults to hash codes to ensure consistent Behavior
///
- internal SortedSet _Components = new(Comparer.Create((a, b) => {
- int result = b.Priority.CompareTo(a.Priority);
- return (result != 0) ? result : a.GetHashCode().CompareTo(b.GetHashCode());
- }));
+ internal SortedSet _Components = new(_componentSorter);
@@ -126,10 +128,6 @@ public abstract partial class ComponentDocker
///
public __Type Add<__Type>(object[] __args) where __Type : Component {
- //Log Action
- Debug.LogAction("Adding Component to Docker", ["Type", "Args", "Docker"],
- [typeof(__Type).ToString(), "[" + string.Join(", ", __args.Select(x => x.ToString())) + "]", GetHashCode().ToString()]);
-
//Component does not have a constructor that matches the given args
@@ -163,11 +161,6 @@ public abstract partial class ComponentDocker
newComponent.Initiate(this);
- //Logs successful action!
- Debug.LogState("Successfully Created Component and Attached it to Docker", ["Type", "Args", "Docker", "Component"],
- [typeof(__Type).ToString(), "[" + string.Join(", ", __args.Select(x => x.ToString())) + "]", GetHashCode().ToString(), newComponent.GetHashCode().ToString()]);
-
-
return (__Type) newComponent;
}
@@ -197,21 +190,16 @@ public abstract partial class ComponentDocker
/// Components cannot transfer themselves with this Method!
public void Move(Component __component, ComponentDocker __componentDocker) {
-
-
+
+
//This allows self transfer behavior while preserving Docker's actual job, Before all other statements to prevent Double-Debugging.
if (__component == this) { __component.ComponentDocker.Move(__component, __componentDocker); return; }
-
-
-
- Debug.LogAction("Transferring Component to Different Docker", ["Component", "Type", "CurrentDocker", "NewDocker"],
- [__component.GetHashCode().ToString(), __component.GetType().ToString(), GetHashCode().ToString(), __componentDocker.GetHashCode().ToString()]);
if (__component == null) {
- Debug.LogError("Component is null!", ["Component", "Type", "CurrentDocker", "NewDocker"],
- [__component.GetHashCode().ToString(), __component.GetType().ToString(), GetHashCode().ToString(), __componentDocker.GetHashCode().ToString()]); return; }
+ Debug.LogError("Component is null!", ["CurrentDocker", "NewDocker"],
+ [GetHashCode().ToString(), __componentDocker.GetHashCode().ToString()]); return; }
@@ -229,11 +217,6 @@ public abstract partial class ComponentDocker
//Update components parent
__component.ComponentDocker = __componentDocker;
-
-
-
- Debug.LogState("Successfully Transferred Component to a new Docker" , ["Component", "Type", "CurrentDocker", "NewDocker"],
- [__component.GetHashCode().ToString(), __component.GetType().ToString(), GetHashCode().ToString(), __componentDocker.GetHashCode().ToString()]);
}
@@ -252,7 +235,7 @@ public abstract partial class ComponentDocker
///
/// List of Components to transfer
/// Docker to move Component to
- public void MoveAll(IEnumerable __Components, ComponentDocker __componentDocker) { foreach (Component Component in (Component[])[.._Components]) Move(Component, __componentDocker); }
+ public void MoveAll(IEnumerable __Components, ComponentDocker __componentDocker) { foreach (Component Component in (Component[])[..__Components]) Move(Component, __componentDocker); }
@@ -288,17 +271,15 @@ public abstract partial class ComponentDocker
/// Value to try and hash
internal void HashTaggedComponent(Component __component, string __tag) {
- if (!__component._tags.Add(__tag))
- //already has tag
- return;
+ if (!__component._tags.Add(__tag)) {
+ Debug.LogError("Component already has tag!", ["Component", "Type", "Tag", "Docker"],
+ [__component.GetHashCode().ToString(), __component.GetType().ToString(), __tag, GetHashCode().ToString()]); return;
+ }
if (_taggedComponents.TryGetValue(__tag, out SortedSet components)) {
components.Add(__component);
- } else _taggedComponents.Add(__tag, new SortedSet(Comparer.Create((a, b) => {
- int result = b.Priority.CompareTo(a.Priority);
- return (result != 0) ? result : a.GetHashCode().CompareTo(b.GetHashCode());
- })));
+ } else { _taggedComponents.Add(__tag, new SortedSet(_componentSorter)); _taggedComponents[__tag].Add(__component); }
}
@@ -310,9 +291,10 @@ public abstract partial class ComponentDocker
///
internal void UnhashTaggedComponent(Component __component, string __tag) {
- if (!__component._tags.Remove(__tag))
- //doesnt have tag
- return;
+ if (!__component._tags.Remove(__tag)) {
+ Debug.LogError("Component already doesn't have that tag!", ["Component", "Type", "Tag", "Docker"],
+ [__component.GetHashCode().ToString(), __component.GetType().ToString(), __tag, GetHashCode().ToString()]); return;
+ }
if (_taggedComponents.TryGetValue(__tag, out SortedSet components)) {
@@ -360,7 +342,7 @@ public abstract partial class ComponentDocker
///
///
///
- internal Component Get(List __tags) => GetAll(__tags)[0];
+ internal Component Get(List __tags) { ImmutableArray returnValue = GetAll(__tags); return returnValue.Length > 0 ? returnValue[0] : null; }
@@ -370,6 +352,10 @@ public abstract partial class ComponentDocker
///
///
internal ImmutableArray GetAll(List __tags) {
+
+ if (__tags.Count == 0)
+ return [];
+
SortedSet foundComponents = _taggedComponents[__tags[0]];
for (int i = 1; i < __tags.Count; i++) {
@@ -392,21 +378,14 @@ public abstract partial class ComponentDocker
///
public __Type Get<__Type>() where __Type : Component {
- Debug.LogAction("Searching for Component", ["Type", "Docker"],
- [typeof(__Type).ToString(), GetHashCode().ToString()]);
-
-
+
//Iterates through the loop and returns if a match is found
- foreach (Component component in (Component[])[.._Components]) {
- if (component is __Type foundComponent) {
- Debug.LogState("Found Component", ["Type", "Component", "Docker"],
- [typeof(__Type).ToString(), foundComponent.GetHashCode().ToString(), GetHashCode().ToString()]);
- return foundComponent;
- }
- }
+ foreach (Component component in (Component[])[.._Components])
+ if (component is __Type foundComponent) return foundComponent;
+
//Throws error if there is no Component found
Debug.LogError("Docker does not have target Component", ["Type", "Docker"],
[typeof(__Type).ToString(), GetHashCode().ToString()]); return null;
@@ -422,11 +401,9 @@ public abstract partial class ComponentDocker
/// The Type of Components to search for
///
public ImmutableArray<__Type> GetAll<__Type>() where __Type : Component {
+
+
- Debug.LogAction("Searching for all Components on Docker", ["Type", "Docker"],
- [typeof(__Type).ToString(), GetHashCode().ToString()]);
-
-
List<__Type> foundComponents = [];
@@ -445,16 +422,20 @@ public abstract partial class ComponentDocker
return [];
}
-
-
- Debug.LogState("Found Components on Docker", ["Components", "Type", "Docker"],
- [(foundComponents.Select(x => x.GetHashCode().ToString()) + "]").ToString(), typeof(__Type).ToString(), GetHashCode().ToString()]);
+
return [..foundComponents];
}
+ ///
+ /// Returns a bool based on if the Docker contains a Component with the given tag or not
+ ///
+ ///
+ ///
+ public bool Contains(string __tag) => _taggedComponents.ContainsKey(__tag);
+
///
@@ -466,8 +447,6 @@ public abstract partial class ComponentDocker
-
-
///
/// Returns a bool based on if the current __Component is owned by this Docker
///
@@ -498,17 +477,13 @@ public abstract partial class ComponentDocker
Debug.LogError("Docker does not have ownership of Component", ["Component", "Type", "CurrentDocker"],
[__component.GetHashCode().ToString(), __component.GetType().ToString(), GetHashCode().ToString()]); return;
}
-
-
-
__component.Destroy();
+ __component.ChainDestroy();
+ foreach (string tag in __component._tags) UnhashTaggedComponent(__component, tag);
+ __component.ComponentDocker = null;
+
_Components.Remove(__component);
-
-
-
- Debug.LogState("Successfully Destroyed Component", ["Component", "Type", "CurrentDocker"],
- [__component.GetHashCode().ToString(), __component.GetType().ToString(), GetHashCode().ToString()]);
}
@@ -525,7 +500,7 @@ public abstract partial class ComponentDocker
/// Destroys all Components from a given collection.
///
///
- public void RemoveAll(IEnumerable __Components) { foreach (Component component in (Component[])[.._Components]) { Remove(component); } }
+ public void RemoveAll(IEnumerable __Components) { foreach (Component component in (Component[])[..__Components]) { Remove(component); } }
@@ -540,7 +515,7 @@ public abstract partial class ComponentDocker
///
/// Destroys all Components attached to Docker
///
- public void Clear() { foreach (Component component in (Component[])[.._Components]) { Remove(component); } }
+ public void RemoveAll() { foreach (Component component in (Component[])[.._Components]) { Remove(component); } }
diff --git a/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfo.cs b/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfo.cs
index 7320ccb..787e230 100644
--- a/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfo.cs
+++ b/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfo.cs
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Awperative")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
-[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4ac4c39d2fc8924d66189393fd676df2cbb69079")]
+[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+31566cb64c790fa1b63824c749340225775b23aa")]
[assembly: System.Reflection.AssemblyProductAttribute("Awperative")]
[assembly: System.Reflection.AssemblyTitleAttribute("Awperative")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
diff --git a/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfoInputs.cache b/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfoInputs.cache
index ac16413..21a750f 100644
--- a/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfoInputs.cache
+++ b/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfoInputs.cache
@@ -1 +1 @@
-0d2f3ccf3836278a524ccd7dcffa2d6d6f413b7714423dadd8fea63d443d5de6
+aaa8c47be327a6d97038a6da33489544968edd27b0bc89d30221ecc4614fcd66