feat: Implemented IInitialize on GameManager

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

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Engine.Core", "Engine.Core.csproj", "{6C1AF4B1-60B0-4225-9A96-F597BC04E9D0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6C1AF4B1-60B0-4225-9A96-F597BC04E9D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C1AF4B1-60B0-4225-9A96-F597BC04E9D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C1AF4B1-60B0-4225-9A96-F597BC04E9D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C1AF4B1-60B0-4225-9A96-F597BC04E9D0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CC449885-B99C-4C71-842D-3C19A35E786F}
EndGlobalSection
EndGlobal

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)