Renamed To Kernel

This commit is contained in:
2026-02-16 18:00:08 -05:00
parent c81b942f2b
commit abbfe285b6
72 changed files with 230 additions and 29 deletions

View File

@@ -0,0 +1,127 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace Awperative;
/// <summary>
/// Initiating class of Awperative. Call Start() to start the kernel.
/// </summary>
/// <author> Avery Norris </author>
public static class Awperative
{
/// <summary>
/// Bottom class of Awperative. Contains the MonoGame instance.
/// </summary>
public static Base Base { get; internal set; }
/// <summary>
/// Handles graphics settings through MonoGame.
/// </summary>
public static GraphicsDeviceManager GraphicsDeviceManager { get; internal set; }
/// <summary>
/// Handles drawing sprites to the screen through MonoGame.
/// </summary>
public static SpriteBatch SpriteBatch { get; internal set; }
/// <summary>
/// Handles loading content through MonoGame.
/// </summary>
public static ContentManager ContentManager { get; internal set; }
/// <summary>
/// List of all scenes currently loaded in the kernel.
/// </summary>
public static ImmutableArray<Scene> Scenes => [.._scenes];
internal static HashSet<Scene> _scenes { get; private set; } = [];
/// <summary>
/// Creates a new Scene
/// </summary>
public static Scene CreateScene(string __name) {
if (!ContainsScene(__name)) {
Scene newScene = new Scene(__name);
_scenes.Add(newScene);
return newScene;
} else Debug.LogError("Awperative already has a Scene with that name!", ["Scene", "Name"], [GetScene(__name).GetHashCode().ToString(), __name]); return null;
}
/// <summary>
/// Finds a Scene from a given name
/// </summary>
/// <param name="__name"> Name to search for</param>
/// <returns></returns>
public static Scene GetScene(string __name) => _scenes.FirstOrDefault(scene => scene.Name == __name, null);
/// <summary>
/// Returns bool based on whether there a scene with the given name or not.
/// </summary>
/// <param name="__name"></param>
/// <returns></returns>
public static bool ContainsScene(string __name) => _scenes.Any(scene => scene.Name == __name);
/// <summary>
/// Closes a Scene
/// </summary>
/// <param name="__scene"></param>
public static void CloseScene(Scene __scene) => Scenes.Remove(GetScene(__scene.Name));
/// <summary>
/// Gets Awperative ready to roll!
/// </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() {
Debug.Initiate();
}
/// <summary>
/// Starts Awperative up! This method runs forever.
/// </summary>
public static void Run() {
Base = new Base();
Base.Run();
}
}

View File

@@ -0,0 +1,82 @@
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Awperative;
/// <summary>
/// Base class of Awperative. Carries events from MonoGame into scenes and hooks.
/// </summary>
/// <author> Avery Norris </author>
public sealed class Base : Game
{
/// <summary>
/// Start of Awperative. Please do not try to call this.
/// </summary>
internal Base() {
Awperative.GraphicsDeviceManager = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Initialize() is called when the program starts. Goes before LoadContent(). And prepares the kernel for use.
/// </summary>
/// <remarks> It is recommended not to load content in Initialize()</remarks>
protected override void Initialize() {
Awperative.ContentManager = Content;
Awperative.SpriteBatch = new SpriteBatch(GraphicsDevice);
base.Initialize();
}
/// <summary>
/// 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(Scene scene in Awperative.Scenes.ToList()) if(scene.Enabled) scene.ChainLoad(); }
/// <summary>
/// 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.Scenes.ToList()) if(scene.Enabled) scene.ChainUpdate(); base.Update(__gameTime); }
/// <summary>
/// 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.Scenes.ToList()) if(scene.Enabled) scene.ChainDraw(); base.Draw(__gameTime); }
/// <summary>
/// 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 (Scene scene in Awperative.Scenes.ToList()) if(scene.Enabled) scene.ChainUnload(); }
}