feat: Implemented IInitialize on GameManager

This commit is contained in:
2023-11-24 11:52:14 +03:00
parent fdb368d881
commit 5f2c551fa4
2 changed files with 65 additions and 2 deletions

View File

@@ -6,12 +6,20 @@ using Syntriax.Engine.Core.Factory;
namespace Syntriax.Engine.Core;
public class GameManager
public class GameManager : IInitialize
{
public Action<IInitialize>? OnInitialized { get; set; } = null;
public Action<IInitialize>? OnFinalized { get; set; } = null;
public Action<IAssignableStateEnable>? OnStateEnableAssigned { get; set; } = null;
private IList<IGameObject> _gameObjects = new List<IGameObject>(Constants.GAME_OBJECTS_SIZE_INITIAL);
private IList<IDrawable> _drawables = new List<IDrawable>(Constants.DRAWABLE_OBJECTS_SIZE_INITIAL);
private IStateEnable _stateEnable = null!;
private GameObjectFactory _gameObjectFactory = null!;
private bool _initialized = false;
private GameObjectFactory GameObjectFactory
{
get
@@ -22,7 +30,9 @@ public class GameManager
}
}
public bool Initialized => _initialized;
public IList<IGameObject> GameObjects => _gameObjects;
public IStateEnable StateEnable { get { if (_stateEnable is null) Assign(new StateEnableFactory().Instantiate(this)); return _stateEnable; } }
public void RegisterGameObject(IGameObject gameObject)
{
@@ -48,10 +58,38 @@ public class GameManager
return gameObject;
}
public void Initialize()
public bool Initialize()
{
if (Initialized)
return false;
foreach (var gameObject in GameObjects)
gameObject.Initialize();
OnInitialized?.Invoke(this);
return true;
}
public bool Finalize()
{
if (!Initialized)
return false;
for (int i = GameObjects.Count; i >= 0; i--)
GameObjects[i].Finalize();
OnFinalized?.Invoke(this);
return true;
}
public bool Assign(IStateEnable stateEnable)
{
if (_stateEnable is not null)
return false;
_stateEnable = stateEnable;
OnStateEnableAssigned?.Invoke(this);
return true;
}
public void Update(GameTime time)