diff --git a/Awperative/Kernel/ComponentDocker/ComponentDocker.cs b/Awperative/Kernel/ComponentDocker/ComponentDocker.cs
index fe249ef..668da2f 100644
--- a/Awperative/Kernel/ComponentDocker/ComponentDocker.cs
+++ b/Awperative/Kernel/ComponentDocker/ComponentDocker.cs
@@ -27,15 +27,30 @@ public abstract partial class ComponentDocker
/// Amount of all Components in the Docker
///
public int Count => _Components.Count;
-
-
-
-
-
+
+
+
+
+
///
- /// Core of Docker, contains all of our precious Components.
+ /// 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 HashSet _Components = [];
+ internal SortedSet _Components = new(Comparer.Create((a, b) => {
+ int result = b.Priority.CompareTo(a.Priority);
+ return (result != 0) ? result : a.GetHashCode().CompareTo(b.GetHashCode());
+ }));
+
+
+
+
+
+ ///
+ /// Resorts member of Component list to match the Priority.
+ ///
+ /// Component to modify
+ /// New priority for Component
+ internal void UpdatePriority(Component __component, int __priority) { _Components.Remove(__component); __component._priority = __priority; _Components.Add(__component); }
@@ -102,7 +117,7 @@ public abstract partial class ComponentDocker
//Log Action
Debug.LogAction("Adding Component to Docker", ["Type", "Args", "Docker"],
- [typeof(__Type).ToString(), "[" + string.Join(", ", __args.SelectMany(x => x.ToString())) + "]", GetHashCode().ToString()]);
+ [typeof(__Type).ToString(), "[" + string.Join(", ", __args.Select(x => x.ToString())) + "]", GetHashCode().ToString()]);
@@ -110,7 +125,7 @@ public abstract partial class ComponentDocker
if (typeof(__Type).GetConstructor(__args.Select(x => x.GetType()).ToArray()) == null) {
Debug.LogError("Component cannot be constructed with the given arguments",
["Type", "Args"],
- [typeof(__Type).ToString(), "[" + string.Join(", ", __args.SelectMany(x => x.ToString())) + "]"]); return null;
+ [typeof(__Type).ToString(), "[" + string.Join(", ", __args.Select(x => x.ToString())) + "]"]); return null;
};
@@ -121,14 +136,14 @@ public abstract partial class ComponentDocker
try { newComponent = (__Type)Activator.CreateInstance(typeof(__Type), __args); }
catch {
Debug.LogError("Component creation failed!", ["Type", "Args", "Docker"],
- [typeof(__Type).ToString(), "[" + string.Join(", ", __args.SelectMany(x => x.ToString())) + "]", GetHashCode().ToString()]); return null;
+ [typeof(__Type).ToString(), "[" + string.Join(", ", __args.Select(x => x.ToString())) + "]", GetHashCode().ToString()]); return null;
}
//If Component is null do not add
if(newComponent == null) {
Debug.LogError("Activator created Null Component", ["Type", "Args", "Docker"],
- [typeof(__Type).ToString(), "[" + string.Join(", ", __args.SelectMany(x => x.ToString())) + "]", GetHashCode().ToString()]); return null;
+ [typeof(__Type).ToString(), "[" + string.Join(", ", __args.Select(x => x.ToString())) + "]", GetHashCode().ToString()]); return null;
}
@@ -139,7 +154,7 @@ public abstract partial class ComponentDocker
//Logs successful action!
Debug.LogState("Successfully Created Component and Attached it to Docker", ["Type", "Args", "Docker", "Component"],
- [typeof(__Type).ToString(), "[" + string.Join(", ", __args.SelectMany(x => x.ToString())) + "]", GetHashCode().ToString(), newComponent.GetHashCode().ToString()]);
+ [typeof(__Type).ToString(), "[" + string.Join(", ", __args.Select(x => x.ToString())) + "]", GetHashCode().ToString(), newComponent.GetHashCode().ToString()]);
return (__Type) newComponent;
@@ -245,6 +260,62 @@ public abstract partial class ComponentDocker
+
+ /// ///
+ /// Holds Components at Keys of their tags.
+ ///
+ internal Dictionary> _taggedComponents = [];
+
+
+
+
+ ///
+ /// Finds the first instance of a component with a given tag
+ ///
+ ///
+ ///
+ internal Component Get(string __tag) => _taggedComponents[__tag].OrderByDescending(x => x._priority).First();
+
+
+
+ ///
+ /// Finds all Components with a given tag
+ ///
+ ///
+ ///
+ internal ImmutableArray GetAll(string __tag) => [.._taggedComponents[__tag]];
+
+
+
+ ///
+ /// Finds the first Component that has all the given tags
+ ///
+ ///
+ ///
+ internal Component Get(List __tags) => GetAll(__tags)[0];
+
+
+
+ ///
+ /// Finds all Components that have all the given tags
+ ///
+ ///
+ ///
+ internal ImmutableArray GetAll(List __tags) {
+ List foundComponents = _taggedComponents[__tags[0]];
+
+ for (int i = 1; i < __tags.Count; i++) {
+ foreach (Component component in (Component[])[..foundComponents]) {
+ if (!_taggedComponents[__tags[i]].Contains(component)) foundComponents.Remove(component);
+ }
+ }
+
+ return [..foundComponents];
+ }
+
+
+
+
///
/// Searches and returns the first Component of a type found on the Docker.
@@ -309,7 +380,7 @@ public abstract partial class ComponentDocker
Debug.LogState("Found Components on Docker", ["Components", "Type", "Docker"],
- [(foundComponents.SelectMany(x => x.GetHashCode().ToString()) + "]").ToString(), typeof(__Type).ToString(), GetHashCode().ToString()]);
+ [(foundComponents.Select(x => x.GetHashCode().ToString()) + "]").ToString(), typeof(__Type).ToString(), GetHashCode().ToString()]);
return [..foundComponents];
}
diff --git a/Awperative/Kernel/ComponentInstance/Core.cs b/Awperative/Kernel/ComponentInstance/Core.cs
index e73b53e..fac9988 100644
--- a/Awperative/Kernel/ComponentInstance/Core.cs
+++ b/Awperative/Kernel/ComponentInstance/Core.cs
@@ -21,7 +21,7 @@ public abstract partial class Component : ComponentDocker
///
/// Current parent of the Component. Can be either Scene or another Component.
///
- public ComponentDocker ComponentDocker;
+ public ComponentDocker ComponentDocker { get; internal set; }
@@ -29,13 +29,15 @@ public abstract partial class Component : ComponentDocker
/// Identifiers for Components.
///
public HashSet Tags;
-
-
-
+
+
+
///
/// Order for when Components are called on. Only applies between Components on the same Docker.
///
- public int Priority;
+ public int Priority {
+ get => _priority; set => ComponentDocker.UpdatePriority(this, value);
+ } internal int _priority;
diff --git a/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfo.cs b/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfo.cs
index 92d89fa..7320ccb 100644
--- a/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfo.cs
+++ b/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfo.cs
@@ -2,7 +2,7 @@
//
// This code was generated by a tool.
//
-// Changes to this file may cause incorrect Component and will be lost if
+// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
@@ -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+843979e10b102dbae5dab3a082ccb2d1d20e571b")]
+[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4ac4c39d2fc8924d66189393fd676df2cbb69079")]
[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 2387dec..ac16413 100644
--- a/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfoInputs.cache
+++ b/Awperative/obj/Debug/net8.0/Awperative.AssemblyInfoInputs.cache
@@ -1 +1 @@
-72227f08b5781ddd9e5f497ab95377ff425e14c54db879ec9be1e644997e8e81
+0d2f3ccf3836278a524ccd7dcffa2d6d6f413b7714423dadd8fea63d443d5de6