refactor: made factories static
This commit is contained in:
parent
9f3e39e337
commit
067bc51487
@ -86,7 +86,7 @@ public abstract class BaseEntity : IEntity
|
||||
if (IsInitialized)
|
||||
return false;
|
||||
|
||||
_stateEnable ??= new Factory.StateEnableFactory().Instantiate(this);
|
||||
_stateEnable ??= Factory.StateEnableFactory.Instantiate(this);
|
||||
|
||||
InitializeInternal();
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class BehaviourController : IBehaviourController
|
||||
InsertBehaviourByPriority(behaviour);
|
||||
|
||||
behaviour.Assign(this);
|
||||
behaviour.Assign(HierarchyObject.StateEnable);
|
||||
behaviour.Assign(Factory.StateEnableFactory.Instantiate(behaviour));
|
||||
|
||||
behaviour.Initialize();
|
||||
behaviour.OnPriorityChanged += OnPriorityChange;
|
||||
@ -61,7 +61,7 @@ public class BehaviourController : IBehaviourController
|
||||
}
|
||||
|
||||
public T AddBehaviour<T>(params object?[]? args) where T : class, IBehaviour
|
||||
=> AddBehaviour(new Factory.BehaviourFactory().Instantiate<T>(_hierarchyObject, args));
|
||||
=> AddBehaviour(Factory.BehaviourFactory.Instantiate<T>(_hierarchyObject, args));
|
||||
|
||||
public T? GetBehaviour<T>()
|
||||
{
|
||||
|
@ -5,10 +5,10 @@ namespace Syntriax.Engine.Core.Factory;
|
||||
|
||||
public class BehaviourControllerFactory
|
||||
{
|
||||
public IBehaviourController Instantiate(IHierarchyObject hierarchyObject)
|
||||
public static IBehaviourController Instantiate(IHierarchyObject hierarchyObject)
|
||||
=> Instantiate<BehaviourController>(hierarchyObject);
|
||||
|
||||
public T Instantiate<T>(IHierarchyObject hierarchyObject, params object?[]? args)
|
||||
public static T Instantiate<T>(IHierarchyObject hierarchyObject, params object?[]? args)
|
||||
where T : class, IBehaviourController
|
||||
{
|
||||
T behaviourController = TypeFactory.Get<T>(args);
|
||||
|
@ -5,10 +5,10 @@ namespace Syntriax.Engine.Core.Factory;
|
||||
|
||||
public class BehaviourFactory
|
||||
{
|
||||
public T Instantiate<T>(IHierarchyObject hierarchyObject, params object?[]? args) where T : class, IBehaviour
|
||||
public static T Instantiate<T>(IHierarchyObject hierarchyObject, params object?[]? args) where T : class, IBehaviour
|
||||
=> Instantiate<T>(hierarchyObject, stateEnable: null, args);
|
||||
|
||||
public T Instantiate<T>(IHierarchyObject hierarchyObject, IStateEnable? stateEnable, params object?[]? args)
|
||||
public static T Instantiate<T>(IHierarchyObject hierarchyObject, IStateEnable? stateEnable, params object?[]? args)
|
||||
where T : class, IBehaviour
|
||||
{
|
||||
T behaviour = TypeFactory.Get<T>(args);
|
||||
|
@ -5,10 +5,10 @@ namespace Syntriax.Engine.Core.Factory;
|
||||
|
||||
public class HierarchyObjectFactory
|
||||
{
|
||||
public T Instantiate<T>(params object?[]? args) where T : class, IHierarchyObject
|
||||
public static T Instantiate<T>(params object?[]? args) where T : class, IHierarchyObject
|
||||
=> Instantiate<T>(behaviourController: null, stateEnable: null, args);
|
||||
|
||||
public T Instantiate<T>(
|
||||
public static T Instantiate<T>(
|
||||
IBehaviourController? behaviourController = null,
|
||||
IStateEnable? stateEnable = null,
|
||||
params object?[]? args
|
||||
|
@ -5,9 +5,9 @@ namespace Syntriax.Engine.Core.Factory;
|
||||
|
||||
public class StateEnableFactory
|
||||
{
|
||||
public IStateEnable Instantiate(IEntity entity) => Instantiate<StateEnable>(entity);
|
||||
public static IStateEnable Instantiate(IEntity entity) => Instantiate<StateEnable>(entity);
|
||||
|
||||
public T Instantiate<T>(IEntity entity, params object?[]? args) where T : class, IStateEnable
|
||||
public static T Instantiate<T>(IEntity entity, params object?[]? args) where T : class, IStateEnable
|
||||
{
|
||||
T stateEnable = TypeFactory.Get<T>(args);
|
||||
|
||||
|
@ -4,7 +4,7 @@ namespace Syntriax.Engine.Core.Factory;
|
||||
|
||||
public class TransformFactory
|
||||
{
|
||||
public ITransform2D Instantiate() => TypeFactory.Get<Transform2D>();
|
||||
public T Instantiate<T>(params object?[]? args) where T : class, ITransform2D
|
||||
public static ITransform2D Instantiate() => TypeFactory.Get<Transform2D>();
|
||||
public static T Instantiate<T>(params object?[]? args) where T : class, ITransform2D
|
||||
=> TypeFactory.Get<T>(args);
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ using System.Collections.Generic;
|
||||
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
using Syntriax.Engine.Core.Exceptions;
|
||||
using Syntriax.Engine.Core.Factory;
|
||||
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
@ -19,16 +18,6 @@ public class GameManager : BaseEntity, IGameManager
|
||||
|
||||
private readonly List<IHierarchyObject> _hierarchyObjects = new(Constants.GAME_OBJECTS_SIZE_INITIAL);
|
||||
|
||||
private HierarchyObjectFactory _hierarchyObjectFactory = null!;
|
||||
private HierarchyObjectFactory HierarchyObjectFactory
|
||||
{
|
||||
get
|
||||
{
|
||||
_hierarchyObjectFactory ??= new HierarchyObjectFactory();
|
||||
return _hierarchyObjectFactory;
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyList<IHierarchyObject> HierarchyObjects => _hierarchyObjects;
|
||||
|
||||
public override IStateEnable StateEnable
|
||||
@ -37,7 +26,7 @@ public class GameManager : BaseEntity, IGameManager
|
||||
{
|
||||
if (base.StateEnable is null)
|
||||
{
|
||||
Assign(new StateEnableFactory().Instantiate(this));
|
||||
Assign(Factory.StateEnableFactory.Instantiate(this));
|
||||
if (base.StateEnable is null)
|
||||
throw NotAssignedException.From(this, base.StateEnable);
|
||||
}
|
||||
@ -72,7 +61,7 @@ public class GameManager : BaseEntity, IGameManager
|
||||
|
||||
public T InstantiateHierarchyObject<T>(params object?[]? args) where T : class, IHierarchyObject
|
||||
{
|
||||
T hierarchyObject = HierarchyObjectFactory.Instantiate<T>(args);
|
||||
T hierarchyObject = Factory.HierarchyObjectFactory.Instantiate<T>(args);
|
||||
Register(hierarchyObject);
|
||||
return hierarchyObject;
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ public class HierarchyObject : BaseEntity, IHierarchyObject
|
||||
protected override void InitializeInternal()
|
||||
{
|
||||
base.InitializeInternal();
|
||||
_behaviourController ??= new Factory.BehaviourControllerFactory().Instantiate(this);
|
||||
_behaviourController ??= Factory.BehaviourControllerFactory.Instantiate(this);
|
||||
}
|
||||
|
||||
public IEnumerator<IHierarchyObject> GetEnumerator() => _children.GetEnumerator();
|
||||
|
Loading…
x
Reference in New Issue
Block a user