feat: IEntity.Id & BaseEntity
This commit is contained in:
@@ -9,22 +9,15 @@ using Syntriax.Engine.Core.Factory;
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
[System.Diagnostics.DebuggerDisplay("GameObject Count: {_gameObjects.Count}")]
|
||||
public class GameManager : IGameManager
|
||||
public class GameManager : BaseEntity, IGameManager
|
||||
{
|
||||
public Action<IGameManager, IGameObject>? OnGameObjectRegistered { get; set; } = null;
|
||||
public Action<IGameManager, IGameObject>? OnGameObjectUnRegistered { get; set; } = null;
|
||||
|
||||
public Action<IInitialize>? OnInitialized { get; set; } = null;
|
||||
public Action<IInitialize>? OnFinalized { get; set; } = null;
|
||||
public Action<IAssignable>? OnUnassigned { get; set; } = null;
|
||||
public Action<IAssignableStateEnable>? OnStateEnableAssigned { get; set; } = null;
|
||||
|
||||
|
||||
private readonly List<IGameObject> _gameObjects = new(Constants.GAME_OBJECTS_SIZE_INITIAL);
|
||||
|
||||
private IStateEnable _stateEnable = null!;
|
||||
private GameObjectFactory _gameObjectFactory = null!;
|
||||
private bool _initialized = false;
|
||||
|
||||
private GameObjectFactory GameObjectFactory
|
||||
{
|
||||
@@ -36,21 +29,20 @@ public class GameManager : IGameManager
|
||||
}
|
||||
}
|
||||
|
||||
public bool Initialized => _initialized;
|
||||
public IReadOnlyList<IGameObject> GameObjects => _gameObjects;
|
||||
|
||||
public IStateEnable StateEnable
|
||||
public override IStateEnable StateEnable
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_stateEnable is null)
|
||||
if (base.StateEnable is null)
|
||||
{
|
||||
Assign(new StateEnableFactory().Instantiate(this));
|
||||
if (_stateEnable is null)
|
||||
throw NotAssignedException.From(this, _stateEnable);
|
||||
if (base.StateEnable is null)
|
||||
throw NotAssignedException.From(this, base.StateEnable);
|
||||
}
|
||||
|
||||
return _stateEnable;
|
||||
return base.StateEnable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,52 +70,20 @@ public class GameManager : IGameManager
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
public bool Initialize()
|
||||
protected override void InitializeInternal()
|
||||
{
|
||||
if (Initialized)
|
||||
return false;
|
||||
|
||||
base.InitializeInternal();
|
||||
NotAssignedException.Check(this, StateEnable);
|
||||
|
||||
foreach (var gameObject in GameObjects)
|
||||
gameObject.Initialize();
|
||||
|
||||
_initialized = true;
|
||||
OnInitialized?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Finalize()
|
||||
protected override void FinalizeInternal()
|
||||
{
|
||||
if (!Initialized)
|
||||
return false;
|
||||
|
||||
base.FinalizeInternal();
|
||||
for (int i = GameObjects.Count; i >= 0; i--)
|
||||
GameObjects[i].Finalize();
|
||||
|
||||
OnFinalized?.Invoke(this);
|
||||
_initialized = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Assign(IStateEnable stateEnable)
|
||||
{
|
||||
if (Initialized)
|
||||
return false;
|
||||
|
||||
_stateEnable = stateEnable;
|
||||
OnStateEnableAssigned?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Unassign()
|
||||
{
|
||||
if (Initialized)
|
||||
return false;
|
||||
|
||||
_stateEnable = null!;
|
||||
OnUnassigned?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Update(EngineTime time)
|
||||
|
||||
Reference in New Issue
Block a user