refactor: rewritten MonoGameWindow to take in a universe as a constructor parameter

This commit is contained in:
Syntriax 2025-06-04 20:13:01 +03:00
parent beecefec1c
commit c7f63dc638

View File

@ -5,38 +5,31 @@ using Syntriax.Engine.Core;
namespace Syntriax.Engine.Integration.MonoGame; namespace Syntriax.Engine.Integration.MonoGame;
public abstract class MonoGameWindow : Game public class MonoGameWindow : Game
{ {
public GraphicsDeviceManager Graphics { get; protected set; } = null!; public GraphicsDeviceManager Graphics { get; protected set; } = null!;
public IUniverse Universe { get; protected set; } = null!; public IUniverse Universe { get; protected set; } = null!;
public ColorRGB BackgroundColor { get; set; } = new ColorRGB(35, 20, 35); public ColorRGB BackgroundColor { get; set; } = new ColorRGB(35, 20, 35);
public MonoGameWindow() public MonoGameWindow(IUniverse? universe = null)
{ {
Preserver.Preserve(); Preserver.Preserve();
Graphics = new GraphicsDeviceManager(this); Graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content"; Content.RootDirectory = "Content";
IsMouseVisible = true; IsMouseVisible = true;
Universe = new Universe(); Universe = universe ?? new Universe();
Universe.InstantiateUniverseObject().SetUniverseObject("Window Container")
.BehaviourController.AddBehaviour<MonoGameWindowContainer>(this);
} }
protected abstract void PopulateUniverse(IUniverse universe);
protected override void Initialize() protected override void Initialize()
{ {
Universe.Initialize(); Universe.Initialize();
Universe.InstantiateUniverseObject().SetUniverseObject("Window Container")
.BehaviourController.AddBehaviour<MonoGameWindowContainer>(this);
PopulateUniverse(Universe);
base.Initialize(); base.Initialize();
} }
protected override void LoadContent()
{
// TODO: use this.Content to load your game content here
}
protected override void Update(GameTime gameTime) protected override void Update(GameTime gameTime)
{ {
Universe.Update(gameTime.ToEngineTime()); Universe.Update(gameTime.ToEngineTime());