using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Syntriax.Engine.Core.Abstract; using Syntriax.Engine.Core.Factory; namespace Syntriax.Engine.Core; public class GameManager { public Game Game { get; private set; } = null!; private IList _gameObjects = new List(Constants.GAME_OBJECTS_SIZE_INITIAL); private GameObjectFactory _gameObjectFactory = null!; private GameObjectFactory GameObjectFactory { get { if (_gameObjectFactory is null) _gameObjectFactory = new GameObjectFactory(); return _gameObjectFactory; } } public IList GameObjects => _gameObjects; public void RegisterGameObject(IGameObject gameObject) { if (_gameObjects.Contains(gameObject)) throw new Exception($"{nameof(IGameComponent)} named {gameObject.Name} is already registered to the {nameof(GameManager)}."); _gameObjects.Add(gameObject); } public T InstantiateGameObject(params object?[]? args) where T : class, IGameObject { T gameObject = GameObjectFactory.Instantiate(args); _gameObjects.Add(gameObject); return gameObject; } // public TGameObject RegisterGameObject() // where TGameObject : class, IGameObject // where TTransform : class, ITransform // where TBehaviourController : class, IBehaviourController // where TStateEnable : class, IStateEnable // { // TGameObject gameObject = Factory.GameObjectFactory.Get(); // _gameObjects.Add(gameObject); // return gameObject; // } public void RemoveGameObject(IGameObject gameObject) { if (!_gameObjects.Contains(gameObject)) throw new Exception($"{nameof(IGameComponent)} named {gameObject.Name} is not registered to the {nameof(GameManager)}."); _gameObjects.Remove(gameObject); } }