diff --git a/Awperative/Kernel/ComponentDocker/ComponentDocker.cs b/Awperative/Kernel/ComponentDocker/ComponentDocker.cs
index 668da2f..bcc3663 100644
--- a/Awperative/Kernel/ComponentDocker/ComponentDocker.cs
+++ b/Awperative/Kernel/ComponentDocker/ComponentDocker.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
@@ -42,7 +43,7 @@ public abstract partial class ComponentDocker
}));
-
+
///
@@ -50,7 +51,17 @@ public abstract partial class ComponentDocker
///
/// Component to modify
/// New priority for Component
- internal void UpdatePriority(Component __component, int __priority) { _Components.Remove(__component); __component._priority = __priority; _Components.Add(__component); }
+ internal void UpdatePriority(Component __component, int __priority) {
+ foreach (String tag in __component._tags) {
+ _taggedComponents[tag].Remove(__component);
+ } _Components.Remove(__component);
+
+ __component._priority = __priority;
+
+ foreach (String tag in __component._tags) {
+ _taggedComponents[tag].Add(__component);
+ } _Components.Add(__component);
+ }
@@ -264,17 +275,69 @@ public abstract partial class ComponentDocker
/// ///
/// Holds Components at Keys of their tags.
///
- internal Dictionary> _taggedComponents = [];
+ internal Dictionary> _taggedComponents = [];
+
+ ///
+ /// Add component to its proper place in the dictionary and resort values to match priorities.
+ ///
+ /// Component to hash
+ /// Value to try and hash
+ internal void HashTaggedComponent(Component __component, string __tag) {
+
+ if (!__component._tags.Add(__tag))
+ //already has tag
+ 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());
+ })));
+ }
+
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ internal void UnhashTaggedComponent(Component __component, string __tag) {
+
+ if (!__component._tags.Remove(__tag))
+ //doesnt have tag
+ return;
+
+
+ if (_taggedComponents.TryGetValue(__tag, out SortedSet components)) {
+ components.Remove(__component);
+
+ if(components.Count == 0)
+ _taggedComponents.Remove(__tag);
+ }
+ }
+
+
+
+
+
///
/// Finds the first instance of a component with a given tag
///
///
///
- internal Component Get(string __tag) => _taggedComponents[__tag].OrderByDescending(x => x._priority).First();
+ internal Component Get(string __tag) {
+ if (_taggedComponents.TryGetValue(__tag, out SortedSet components))
+ return ((Component[])[..components])[0];
+
+ return null;
+ }
@@ -283,7 +346,12 @@ public abstract partial class ComponentDocker
///
///
///
- internal ImmutableArray GetAll(string __tag) => [.._taggedComponents[__tag]];
+ internal ImmutableArray GetAll(string __tag) {
+ if (_taggedComponents.TryGetValue(__tag, out SortedSet components))
+ return [..components];
+
+ return [];
+ }
@@ -302,7 +370,7 @@ public abstract partial class ComponentDocker
///
///
internal ImmutableArray GetAll(List __tags) {
- List foundComponents = _taggedComponents[__tags[0]];
+ SortedSet foundComponents = _taggedComponents[__tags[0]];
for (int i = 1; i < __tags.Count; i++) {
foreach (Component component in (Component[])[..foundComponents]) {
diff --git a/Awperative/Kernel/ComponentInstance/Core.cs b/Awperative/Kernel/ComponentInstance/Core.cs
index fac9988..197ac29 100644
--- a/Awperative/Kernel/ComponentInstance/Core.cs
+++ b/Awperative/Kernel/ComponentInstance/Core.cs
@@ -22,13 +22,6 @@ public abstract partial class Component : ComponentDocker
/// Current parent of the Component. Can be either Scene or another Component.
///
public ComponentDocker ComponentDocker { get; internal set; }
-
-
-
- ///
- /// Identifiers for Components.
- ///
- public HashSet Tags;
@@ -112,9 +105,31 @@ public abstract partial class Component : ComponentDocker
-
-
-
+ ///
+ /// Identifiers for Components.
+ ///
+ public ImmutableArray Tags => [.._tags];
+ internal HashSet _tags;
+
+
+
+
+
+ ///
+ /// Adds a new tag to the Component
+ ///
+ /// The tag to add
+ public void AddTag(string __tag) => ComponentDocker.HashTaggedComponent(this, __tag);
+
+
+
+
+
+ ///
+ /// Removes a tag from the Component
+ ///
+ /// The tag to remove
+ public void RemoveTag(string __tag) => ComponentDocker.UnhashTaggedComponent(this, __tag);