Awperative Beta!

This commit is contained in:
2026-02-15 20:34:29 -05:00
parent de8e9aca44
commit 1f96b653ad
10 changed files with 91 additions and 100 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -53,16 +54,43 @@ public static class Awperative
/// <summary>
/// List of all scenes currently loaded in the kernel.
/// </summary>
public static List<Scene> LoadedScenes => _loadedScenes.ToList();
internal static HashSet<Scene> _loadedScenes { get; private set; }= [];
public static ImmutableArray<Scene> Scenes => [.._scenes];
internal static HashSet<Scene> _scenes { get; private set; } = [];
/// <summary>
/// Creates a new Scene
/// </summary>
public static void Create(string __name) { if (Contains(__name)) _scenes.Add(new Scene(__name)); else Debug.LogError("Awperative already has a Scene with that name!", ["Scene", "Name"], [Get(__name).GetHashCode().ToString(), __name]); }
/// <summary>
/// Finds a Scene from a given name
/// </summary>
/// <param name="__name"> Name to search for</param>
/// <returns></returns>
public static Scene Get(string __name) => _scenes.FirstOrDefault(scene => scene.Name == __name, null);
/// <summary>
/// List of all event hooks currently loaded in the kernel.
/// Returns bool based on whether there a scene with the given name or not.
/// </summary>
public static List<AwperativeHook> EventHooks => _eventHooks.ToList();
internal static HashSet<AwperativeHook> _eventHooks { get; private set; } = [];
/// <param name="__name"></param>
/// <returns></returns>
public static bool Contains(string __name) => _scenes.Any(scene => scene.Name == __name);
/// <summary>
/// Closes a Scene
/// </summary>
/// <param name="__scene"></param>
public static void Close(Scene __scene) => Scenes.Remove(Get(__scene.Name));
@@ -73,10 +101,7 @@ public static class Awperative
/// </summary>
/// <param name="__hooks"> List of all event hooks you wish to use. </param>
/// <remarks> You cannot add new hooks later; so make sure to register all of them in the Start() method.</remarks>
public static void Start(List<AwperativeHook> __hooks) {
_eventHooks = new HashSet<AwperativeHook>(__hooks);
public static void Start() {
Base = new Base();
Base.Run();
}

View File

@@ -1,25 +0,0 @@
namespace Awperative;
/// <summary>
/// Awperative hooks are the source of entry for scripts using Awperative. Create a hook and send into Start() to be recognized by the engine.
/// </summary>
/// <author> Avery Norris </author>
public interface AwperativeHook
{
/// <summary>
/// Called when the program starts; It is not recommended you load assets here.
/// </summary>
public void Load() {}
/// <summary>
/// Called when the program closes.
/// </summary>
public void Unload() {}
}

View File

@@ -44,10 +44,7 @@ public sealed class Base : Game
/// LoadContent() is called when the program starts; right after Initialize(). Override Load() in scripting tools or use hooks to call from this event.
/// </summary>
/// <remarks> It is recommended to load content during LoadContent()</remarks>
protected override void LoadContent() {
foreach (AwperativeHook hook in Awperative.EventHooks.ToList()) hook.Load();
foreach(Scene scene in Awperative.LoadedScenes.ToList()) scene.ChainLoad();
}
protected override void LoadContent() { foreach(Scene scene in Awperative.Scenes.ToList()) if(scene.Enabled) scene.ChainLoad(); }
@@ -57,10 +54,7 @@ public sealed class Base : Game
/// Update() is called every frame; before Draw(). Override Update() in scripting tools to call from this event.
/// </summary>
/// <remarks> Hooks are unable to receive both Update() and Draw()</remarks>
protected override void Update(GameTime __gameTime) {
foreach(Scene scene in Awperative.LoadedScenes.ToList()) scene.ChainUpdate();
base.Update(__gameTime);
}
protected override void Update(GameTime __gameTime) { foreach(Scene scene in Awperative.Scenes.ToList()) if(scene.Enabled) scene.ChainUpdate(); base.Update(__gameTime); }
@@ -70,10 +64,7 @@ public sealed class Base : Game
/// Draw() is called every frame; after Update(). Override Draw() in scripting tools to call from this event.
/// </summary>
/// <remarks> Hooks are unable to receive both Update() and Draw()</remarks>
protected override void Draw(GameTime __gameTime) {
foreach(Scene scene in Awperative.LoadedScenes.ToList()) scene.ChainDraw();
base.Draw(__gameTime);
}
protected override void Draw(GameTime __gameTime) { foreach(Scene scene in Awperative.Scenes.ToList()) if(scene.Enabled) scene.ChainDraw(); base.Draw(__gameTime); }
@@ -83,10 +74,7 @@ public sealed class Base : Game
/// EndRun() is called if the program closes. Override Terminate() in scripting tools or use hooks to call from this event.
/// </summary>
/// <remarks> This event may not trigger if the program is force closed.</remarks>
protected override void EndRun() {
foreach (AwperativeHook hook in Awperative.EventHooks.ToList()) hook.Unload();
foreach (Scene scene in Awperative.LoadedScenes.ToList()) scene.ChainUnload();
}
protected override void EndRun() { foreach (Scene scene in Awperative.Scenes.ToList()) if(scene.Enabled) scene.ChainUnload(); }