Closing in on beta

This commit is contained in:
2026-02-15 15:42:22 -05:00
parent 31566cb64c
commit 0e21432ffb
5 changed files with 54 additions and 81 deletions

View File

@@ -7,12 +7,7 @@ namespace Awperative;
/// <summary>
/// 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.
/// </summary>
public abstract partial class Component : ComponentDocker
{
@@ -109,7 +104,7 @@ public abstract partial class Component : ComponentDocker
/// Identifiers for Components.
/// </summary>
public ImmutableArray<string> Tags => [.._tags];
internal HashSet<string> _tags;
internal HashSet<string> _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()]);
}
}

View File

@@ -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.
/// </summary>
/// <remarks> Please don't inherit this I don't know why you would</remarks>
/// <remarks> Please don't inherit this. I don't know why you would</remarks>
/// <author> Avery Norris </author>
public abstract partial class ComponentDocker
{
@@ -31,16 +30,19 @@ public abstract partial class ComponentDocker
private readonly static Comparer<Component> _componentSorter = Comparer<Component>.Create((a, b) => {
int result = b.Priority.CompareTo(a.Priority);
return (result != 0) ? result : a.GetHashCode().CompareTo(b.GetHashCode());
});
/// <summary>
/// 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
/// </summary>
internal SortedSet<Component> _Components = new(Comparer<Component>.Create((a, b) => {
int result = b.Priority.CompareTo(a.Priority);
return (result != 0) ? result : a.GetHashCode().CompareTo(b.GetHashCode());
}));
internal SortedSet<Component> _Components = new(_componentSorter);
@@ -126,10 +128,6 @@ public abstract partial class ComponentDocker
/// <returns></returns>
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;
}
@@ -204,14 +197,9 @@ public abstract partial class ComponentDocker
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
/// </summary>
/// <param name="__Components"> List of Components to transfer</param>
/// <param name="__componentDocker"> Docker to move Component to</param>
public void MoveAll(IEnumerable<Component> __Components, ComponentDocker __componentDocker) { foreach (Component Component in (Component[])[.._Components]) Move(Component, __componentDocker); }
public void MoveAll(IEnumerable<Component> __Components, ComponentDocker __componentDocker) { foreach (Component Component in (Component[])[..__Components]) Move(Component, __componentDocker); }
@@ -288,17 +271,15 @@ public abstract partial class ComponentDocker
/// <param name="__tag"> Value to try and hash</param>
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<Component> components)) {
components.Add(__component);
} else _taggedComponents.Add(__tag, new SortedSet<Component>(Comparer<Component>.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<Component>(_componentSorter)); _taggedComponents[__tag].Add(__component); }
}
@@ -310,9 +291,10 @@ public abstract partial class ComponentDocker
/// <param name="__tag"></param>
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<Component> components)) {
@@ -360,7 +342,7 @@ public abstract partial class ComponentDocker
/// </summary>
/// <param name="__tags"></param>
/// <returns></returns>
internal Component Get(List<string> __tags) => GetAll(__tags)[0];
internal Component Get(List<string> __tags) { ImmutableArray<Component> returnValue = GetAll(__tags); return returnValue.Length > 0 ? returnValue[0] : null; }
@@ -370,6 +352,10 @@ public abstract partial class ComponentDocker
/// <param name="__tags"></param>
/// <returns></returns>
internal ImmutableArray<Component> GetAll(List<string> __tags) {
if (__tags.Count == 0)
return [];
SortedSet<Component> foundComponents = _taggedComponents[__tags[0]];
for (int i = 1; i < __tags.Count; i++) {
@@ -392,19 +378,12 @@ public abstract partial class ComponentDocker
/// <returns></returns>
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
@@ -423,8 +402,6 @@ public abstract partial class ComponentDocker
/// <returns></returns>
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 = [];
@@ -447,14 +424,18 @@ public abstract partial class ComponentDocker
Debug.LogState("Found Components on Docker", ["Components", "Type", "Docker"],
[(foundComponents.Select(x => x.GetHashCode().ToString()) + "]").ToString(), typeof(__Type).ToString(), GetHashCode().ToString()]);
return [..foundComponents];
}
/// <summary>
/// Returns a bool based on if the Docker contains a Component with the given tag or not
/// </summary>
/// <param name="__tag"></param>
/// <returns></returns>
public bool Contains(string __tag) => _taggedComponents.ContainsKey(__tag);
/// <summary>
@@ -466,8 +447,6 @@ public abstract partial class ComponentDocker
/// <summary>
/// Returns a bool based on if the current __Component is owned by this Docker
/// </summary>
@@ -499,16 +478,12 @@ public abstract partial class ComponentDocker
[__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.
/// </summary>
/// <param name="__Components"></param>
public void RemoveAll(IEnumerable<Component> __Components) { foreach (Component component in (Component[])[.._Components]) { Remove(component); } }
public void RemoveAll(IEnumerable<Component> __Components) { foreach (Component component in (Component[])[..__Components]) { Remove(component); } }
@@ -540,7 +515,7 @@ public abstract partial class ComponentDocker
/// <summary>
/// Destroys all Components attached to Docker
/// </summary>
public void Clear() { foreach (Component component in (Component[])[.._Components]) { Remove(component); } }
public void RemoveAll() { foreach (Component component in (Component[])[.._Components]) { Remove(component); } }

View File

@@ -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")]

View File

@@ -1 +1 @@
0d2f3ccf3836278a524ccd7dcffa2d6d6f413b7714423dadd8fea63d443d5de6
aaa8c47be327a6d97038a6da33489544968edd27b0bc89d30221ecc4614fcd66