About to remove events

This commit is contained in:
2026-02-08 15:07:02 -05:00
parent e987c8092f
commit 6f16a1170f
19 changed files with 209 additions and 168 deletions

View File

@@ -82,6 +82,16 @@ public static partial class Debug
/// <param name="__parameters"> Names of values to debug</param>
/// <param name="__values"> Values to debug</param>
public static void LogError(string __message, string[] __parameters, string[] __values) => LogGeneric(__message, "ERR", __parameters, __values);
/// <summary>
/// Writes the current message to the log file.
/// </summary>
/// <param name="__message"> Message to debug</param>
/// <param name="__condition"> Condition to debug </param>
public static void AssertError(bool __condition, string __message) => AssertGeneric(__condition, __message, "ERR", [], []);
//todo: add more asserts and overrides
@@ -102,4 +112,17 @@ public static partial class Debug
File.AppendAllText(LogFilePath, output);
}
public static void AssertGeneric(bool __condition, string __message, string __callSign, string[] __parameters, string[] __values) {
if (!__condition) return;
string output = "\n\n" + __callSign + "- \"" + __message + "\"\n STK-" + new StackTrace();
for (int i = 0; i < __parameters.Length || i < __values.Length; i++)
output += "\n " + __parameters[i] + "- " + __values[i];
File.AppendAllText(LogFilePath, output);
}
}

View File

@@ -1,124 +0,0 @@
using System;
using System.Collections.Generic;
namespace Awperative;
public sealed partial class Body
{
public Generic AddComponent<Generic>(object[] args) where Generic : Component {
if (SingletonExists<Generic>()) { Debug.LogError("Cannot add component when singleton exists!"); return null; }
Generic component = (Generic) Activator.CreateInstance(typeof(Generic), args);
if (component == null) { Debug.LogError("Failed to create component!"); return null; }
_components.Add(component);
component.Initiate(this);
ComponentCreatedEvent?.Invoke(this, new ComponentCreateEvent(component, this, Scene));
return component;
}
public Generic AddComponent<Generic>() where Generic : Component {
if (SingletonExists<Generic>())
throw new Exception("Cannot add component when singleton exists!");
Generic component = (Generic) Activator.CreateInstance(typeof(Generic));
if(component == null)
throw new Exception("Failed to create component!");
components.Add(component);
component.Initiate(this);
ComponentCreatedEvent?.Invoke(this, new ComponentCreateEvent(component, this, scene));
return component;
}
public Generic[] GetComponents<Generic>() where Generic : Component {
List<Component> foundComponents = components.FindAll(x => x.GetType() == typeof(Generic));
if(foundComponents.Count == 0)
throw new Exception("Scene has no components of that type!");
return foundComponents.ToArray() as Generic[];
}
public Generic GetComponent<Generic>() where Generic : Component {
Component foundComponent = components.Find(x => x.GetType() == typeof(Generic));
if(foundComponent == null)
throw new Exception("Scene has no components of that type!");
return foundComponent as Generic;
}
public void RemoveComponent(Component __component) {
__component.End();
components.Remove(__component);
}
public void RemoveComponents<Generic>() where Generic : Component {
Component[] foundComponents = GetComponents<Generic>();
if(foundComponents.Length == 0)
throw new Exception("Scene has no components of that type!");
foreach (Component component in foundComponents) {
component.End();
components.Remove(component);
ComponentDestroyedEvent?.Invoke(this, new ComponentDestroyEvent(component, this, scene));
}
}
public void RemoveComponent<Generic>() where Generic : Component {
Component foundComponent = GetComponent<Generic>();
if(foundComponent == null)
throw new Exception("Scene has no components of that type!");
foundComponent.End();
components.Remove(foundComponent);
ComponentDestroyedEvent?.Invoke(this ,new ComponentDestroyEvent(foundComponent, this, scene));
}
public Generic FindSingleton<Generic>() where Generic : Component
{
foreach (Component component in components)
if (component.GetType() == typeof(Generic))
if(component.EnforceSingleton)
return (Generic) component;
else
throw new Exception("Component is not a singleton");
throw new Exception("Component not found");
return null;
}
public bool SingletonExists<Generic>() where Generic : Component
{
foreach (Component __component in components)
if (__component.GetType() == typeof(Generic))
if (__component.EnforceSingleton)
return true;
else
return false;
return false;
}
public void RecompileComponentOrder() {
components.Sort((a, b) => a.Priority.CompareTo(b.Priority));
components.Reverse();
}
}

View File

@@ -0,0 +1,28 @@
using System;
namespace Awperative;
public sealed partial class Body
{
public Component AddComponent<Generic>() where Generic : Component => AddComponent<Generic>([]);
public Component AddComponent<Generic>(object[] __args) where Generic : Component {
if (SingletonExists<Generic>()) { Debug.LogError("Cannot add component when singleton exists"); return null; }
if(typeof(Generic).GetConstructor((Type[]) __args) == null) { Debug.LogError("Component does not contain a valid constructor"); return null; };
try {
Component component = (Generic)Activator.CreateInstance(typeof(Generic), __args);
if(component == null) { Debug.LogError("Failed to create component"); return null; };
_components.Add(component);
component.Initiate(this);
ComponentCreatedEvent?.Invoke(this, new ComponentCreateEvent(component, this, Scene));
return component;
}catch { Debug.LogError("Failed to create component"); return null; }
}
}

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
namespace Awperative;
public sealed partial class Body
{
public Component GetComponent<Generic>() where Generic : Component => GetComponents<Generic>()[0];
public Component[] GetComponents<Generic>() where Generic : Component {
List<Component> returnValue = [];
foreach (Component component in _components)
if (component is Generic) returnValue.Add(component);
if(returnValue.Count == 0) { Debug.LogWarning("Scene has no components of this type"); return null; }
return returnValue.ToArray();
}
public Generic FindSingleton<Generic>() where Generic : Component
{
foreach (Component component in _components)
if (component.GetType() == typeof(Generic))
if(component.EnforceSingleton)
return (Generic) component;
else
throw new Exception("Component is not a singleton");
throw new Exception("Component not found");
return null;
}
public bool SingletonExists<Generic>() where Generic : Component
{
foreach (Component __component in _components)
if (__component.GetType() == typeof(Generic))
if (__component.EnforceSingleton)
return true;
else
return false;
return false;
}
}

View File

@@ -0,0 +1,33 @@
namespace Awperative;
public sealed partial class Body
{
public void RemoveComponent(Component __component) {
if(!_components.Contains(__component)) { Debug.LogError("Body does not have a component of this type"); return; }
__component.End();
_components.Remove(__component);
}
public void RemoveComponent<Generic>() where Generic : Component {
try
{
Component foundComponent = GetComponent<Generic>();
foundComponent.End();
_components.Remove(foundComponent);
ComponentDestroyedEvent?.Invoke(this, new ComponentDestroyEvent(foundComponent, this, Scene));
}catch { Debug.LogError("Removal failed"); }
}
public void RemoveComponents<Generic>() where Generic : Component {
try {
foreach (Component component in GetComponents<Generic>()) {
component.End();
_components.Remove(component);
ComponentDestroyedEvent?.Invoke(this, new ComponentDestroyEvent(component, this, Scene));
}
}catch { Debug.LogError("Removal failed"); }
}
}

View File

@@ -5,8 +5,6 @@ namespace Awperative;
public sealed partial class Body
{
//todo: add component events to scene in v5
public event EventHandler<ComponentCreateEvent> ComponentCreatedEvent;
public event EventHandler<ComponentDestroyEvent> ComponentDestroyedEvent;
}

View File

@@ -7,13 +7,16 @@ namespace Awperative;
public sealed partial class Body
{
public void Unload() { foreach (Component component in components.ToList()) component.Unload(); }
public void Load() { foreach (Component component in components.ToList()) { component.Load(); } }
internal void Unload() { foreach (Component component in _components) component.Unload(); }
internal void Load() { foreach (Component component in _components) { component.Load(); } }
public void Update(GameTime __gameTime) { foreach (Component component in components.ToList()) { component.Update(__gameTime); } }
public void Draw(GameTime __gameTime) { foreach (Component component in components.ToList()) { component.Draw(__gameTime); } }
public void Destroy() { foreach(Component component in components.ToList()) component.Destroy(); }
public void Create() { foreach (Component component in components.ToList()) component.Create(); }
internal void Update(GameTime __gameTime) { foreach (Component component in _components) { component.Update(__gameTime); } }
internal void Draw(GameTime __gameTime) { foreach (Component component in _components) { component.Draw(__gameTime); } }
internal void Destroy() { foreach(Component component in _components) component.Destroy(); }
internal void Create() { foreach (Component component in _components) component.Create(); }
}

View File

@@ -33,7 +33,7 @@ public sealed partial class Scene
List<Body> _bodies = new List<Body>();
foreach (Body body in bodies)
if (body.tags.Contains(tag))
if (body._tags.Contains(tag))
_bodies.Add(body);
@@ -45,7 +45,7 @@ public sealed partial class Scene
public Body GetBody(string tag) {
foreach (Body body in bodies)
if (body.tags.Contains(tag))
if (body._tags.Contains(tag))
return body;
throw new Exception("No Body found with the tag " + tag);

View File

@@ -1,20 +1,20 @@
{
"format": 1,
"restore": {
"/home/avery/Programming/Awperative/Awperative/Awperative.csproj": {}
"/Users/averynorris/RiderProjects/Awperative/Awperative/Awperative.csproj": {}
},
"projects": {
"/home/avery/Programming/Awperative/Awperative/Awperative.csproj": {
"/Users/averynorris/RiderProjects/Awperative/Awperative/Awperative.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/avery/Programming/Awperative/Awperative/Awperative.csproj",
"projectUniqueName": "/Users/averynorris/RiderProjects/Awperative/Awperative/Awperative.csproj",
"projectName": "Awperative",
"projectPath": "/home/avery/Programming/Awperative/Awperative/Awperative.csproj",
"packagesPath": "/home/avery/.nuget/packages/",
"outputPath": "/home/avery/Programming/Awperative/Awperative/obj/",
"projectPath": "/Users/averynorris/RiderProjects/Awperative/Awperative/Awperative.csproj",
"packagesPath": "/Users/averynorris/.nuget/packages/",
"outputPath": "/Users/averynorris/RiderProjects/Awperative/Awperative/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/avery/.nuget/NuGet/NuGet.Config"
"/Users/averynorris/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
@@ -32,7 +32,13 @@
"warnAsError": [
"NU1605"
]
}
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.300"
},
"frameworks": {
"net8.0": {
@@ -55,12 +61,22 @@
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[8.0.20, 8.0.20]"
},
{
"name": "Microsoft.NETCore.App.Ref",
"version": "[8.0.20, 8.0.20]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/lib/dotnet/sdk/8.0.123/PortableRuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "/usr/local/share/dotnet/sdk/9.0.305/PortableRuntimeIdentifierGraph.json"
}
}
}

View File

@@ -4,12 +4,12 @@
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/home/avery/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/home/avery/.nuget/packages/</NuGetPackageFolders>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/Users/averynorris/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/Users/averynorris/.nuget/packages/</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.14.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/home/avery/.nuget/packages/" />
<SourceRoot Include="/Users/averynorris/.nuget/packages/" />
</ItemGroup>
</Project>

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+6032a04ad97895ae66261315ee00dc458991fddb")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e987c8092f471ce03238b8612f7201ea93407653")]
[assembly: System.Reflection.AssemblyProductAttribute("Awperative")]
[assembly: System.Reflection.AssemblyTitleAttribute("Awperative")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@@ -1 +1 @@
b425b3bf0701917a4ebea9a237727c5966a9c5c39530e5ed5a453056bfdf1602
048fb6054ed9b529ea18f588fbae06b4c18cb6b3b2b0f2dfb5e7cef86db14863

View File

@@ -8,6 +8,8 @@ build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = Awperative
build_property.ProjectDir = /home/avery/Programming/Awperative/Awperative/
build_property.ProjectDir = /Users/averynorris/RiderProjects/Awperative/Awperative/
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.EffectiveAnalysisLevelStyle = 8.0
build_property.EnableCodeStyleSeverity =

View File

@@ -273,19 +273,19 @@
]
},
"packageFolders": {
"/home/avery/.nuget/packages/": {}
"/Users/averynorris/.nuget/packages/": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/avery/Programming/Awperative/Awperative/Awperative.csproj",
"projectUniqueName": "/Users/averynorris/RiderProjects/Awperative/Awperative/Awperative.csproj",
"projectName": "Awperative",
"projectPath": "/home/avery/Programming/Awperative/Awperative/Awperative.csproj",
"packagesPath": "/home/avery/.nuget/packages/",
"outputPath": "/home/avery/Programming/Awperative/Awperative/obj/",
"projectPath": "/Users/averynorris/RiderProjects/Awperative/Awperative/Awperative.csproj",
"packagesPath": "/Users/averynorris/.nuget/packages/",
"outputPath": "/Users/averynorris/RiderProjects/Awperative/Awperative/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/avery/.nuget/NuGet/NuGet.Config"
"/Users/averynorris/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
@@ -303,7 +303,13 @@
"warnAsError": [
"NU1605"
]
}
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.300"
},
"frameworks": {
"net8.0": {
@@ -326,12 +332,22 @@
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[8.0.20, 8.0.20]"
},
{
"name": "Microsoft.NETCore.App.Ref",
"version": "[8.0.20, 8.0.20]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/lib/dotnet/sdk/8.0.123/PortableRuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "/usr/local/share/dotnet/sdk/9.0.305/PortableRuntimeIdentifierGraph.json"
}
}
}

View File

@@ -1,15 +1,17 @@
{
"version": 2,
"dgSpecHash": "oHHZKOBBLTE=",
"dgSpecHash": "rY6Za5NlkX4=",
"success": true,
"projectFilePath": "/home/avery/Programming/Awperative/Awperative/Awperative.csproj",
"projectFilePath": "/Users/averynorris/RiderProjects/Awperative/Awperative/Awperative.csproj",
"expectedPackageFiles": [
"/home/avery/.nuget/packages/monogame.framework.desktopgl/3.8.4.1/monogame.framework.desktopgl.3.8.4.1.nupkg.sha512",
"/home/avery/.nuget/packages/monogame.library.openal/1.24.3.2/monogame.library.openal.1.24.3.2.nupkg.sha512",
"/home/avery/.nuget/packages/monogame.library.sdl/2.32.2.1/monogame.library.sdl.2.32.2.1.nupkg.sha512",
"/home/avery/.nuget/packages/nvorbis/0.10.4/nvorbis.0.10.4.nupkg.sha512",
"/home/avery/.nuget/packages/system.memory/4.5.3/system.memory.4.5.3.nupkg.sha512",
"/home/avery/.nuget/packages/system.valuetuple/4.5.0/system.valuetuple.4.5.0.nupkg.sha512"
"/Users/averynorris/.nuget/packages/monogame.framework.desktopgl/3.8.4.1/monogame.framework.desktopgl.3.8.4.1.nupkg.sha512",
"/Users/averynorris/.nuget/packages/monogame.library.openal/1.24.3.2/monogame.library.openal.1.24.3.2.nupkg.sha512",
"/Users/averynorris/.nuget/packages/monogame.library.sdl/2.32.2.1/monogame.library.sdl.2.32.2.1.nupkg.sha512",
"/Users/averynorris/.nuget/packages/nvorbis/0.10.4/nvorbis.0.10.4.nupkg.sha512",
"/Users/averynorris/.nuget/packages/system.memory/4.5.3/system.memory.4.5.3.nupkg.sha512",
"/Users/averynorris/.nuget/packages/system.valuetuple/4.5.0/system.valuetuple.4.5.0.nupkg.sha512",
"/Users/averynorris/.nuget/packages/microsoft.netcore.app.ref/8.0.20/microsoft.netcore.app.ref.8.0.20.nupkg.sha512",
"/Users/averynorris/.nuget/packages/microsoft.aspnetcore.app.ref/8.0.20/microsoft.aspnetcore.app.ref.8.0.20.nupkg.sha512"
],
"logs": []
}

View File

@@ -1 +1 @@
"restore":{"projectUniqueName":"/home/avery/Programming/Awperative/Awperative/Awperative.csproj","projectName":"Awperative","projectPath":"/home/avery/Programming/Awperative/Awperative/Awperative.csproj","outputPath":"/home/avery/Programming/Awperative/Awperative/obj/","projectStyle":"PackageReference","originalTargetFrameworks":["net8.0"],"sources":{"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net8.0":{"targetAlias":"net8.0","projectReferences":{}}},"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net8.0":{"targetAlias":"net8.0","dependencies":{"MonoGame.Framework.DesktopGL":{"suppressParent":"All","target":"Package","version":"[3.8.*, )"}},"imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"/usr/lib/dotnet/sdk/8.0.123/PortableRuntimeIdentifierGraph.json"}}
"restore":{"projectUniqueName":"/Users/averynorris/RiderProjects/Awperative/Awperative/Awperative.csproj","projectName":"Awperative","projectPath":"/Users/averynorris/RiderProjects/Awperative/Awperative/Awperative.csproj","outputPath":"/Users/averynorris/RiderProjects/Awperative/Awperative/obj/","projectStyle":"PackageReference","originalTargetFrameworks":["net8.0"],"sources":{"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net8.0":{"targetAlias":"net8.0","projectReferences":{}}},"warningProperties":{"warnAsError":["NU1605"]},"restoreAuditProperties":{"enableAudit":"true","auditLevel":"low","auditMode":"direct"},"SdkAnalysisLevel":"9.0.300"}"frameworks":{"net8.0":{"targetAlias":"net8.0","dependencies":{"MonoGame.Framework.DesktopGL":{"suppressParent":"All","target":"Package","version":"[3.8.*, )"}},"imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"downloadDependencies":[{"name":"Microsoft.AspNetCore.App.Ref","version":"[8.0.20, 8.0.20]"},{"name":"Microsoft.NETCore.App.Ref","version":"[8.0.20, 8.0.20]"}],"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"/usr/local/share/dotnet/sdk/9.0.305/PortableRuntimeIdentifierGraph.json"}}

View File

@@ -1 +1 @@
17701648299693068
17705737329502274