chore: Finalize Don't Set Fields to Null Anymore

This commit is contained in:
Syntriax 2023-11-24 16:37:09 +03:00
parent 44bee2df08
commit 8a8c09f043
6 changed files with 12 additions and 16 deletions

View File

@ -54,7 +54,7 @@ public abstract class Behaviour : IBehaviour
public bool Assign(IStateEnable stateEnable)
{
if (_initialized)
if (Initialized)
return false;
_stateEnable = stateEnable;
@ -65,7 +65,7 @@ public abstract class Behaviour : IBehaviour
public bool Assign(IBehaviourController behaviourController)
{
if (_behaviourController is not null)
if (Initialized)
return false;
_behaviourController = behaviourController;
@ -90,9 +90,6 @@ public abstract class Behaviour : IBehaviour
if (!Initialized)
return false;
_behaviourController = null!;
_stateEnable = null!;
Initialized = false;
return true;
}

View File

@ -87,7 +87,7 @@ public class BehaviourController : IBehaviourController
public bool Assign(IGameObject gameObject)
{
if (_gameObject is not null)
if (GameObject.Initialized)
return false;
_gameObject = gameObject;

View File

@ -32,7 +32,7 @@ public class DrawableSpriteBehaviour : Behaviour, IDrawBehaviour, IAssignableSpr
public bool Assign(ISprite sprite)
{
if (_sprite is not null)
if (Initialized)
return false;
_sprite = sprite;

View File

@ -2,6 +2,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Syntriax.Engine.Core.Abstract;
using Syntriax.Engine.Core.Exceptions;
using Syntriax.Engine.Core.Factory;
namespace Syntriax.Engine.Core;
@ -63,6 +64,8 @@ public class GameManager : IInitialize
if (Initialized)
return false;
NotAssignedException.Check(this, StateEnable);
foreach (var gameObject in GameObjects)
gameObject.Initialize();
@ -84,7 +87,7 @@ public class GameManager : IInitialize
public bool Assign(IStateEnable stateEnable)
{
if (_stateEnable is not null)
if (Initialized)
return false;
_stateEnable = stateEnable;

View File

@ -92,17 +92,13 @@ public class GameObject : IGameObject
behaviour => behaviour.Finalize()
);
_transform = null!;
_behaviourController = null!;
_stateEnable = null!;
Initialized = false;
return true;
}
public bool Assign(IStateEnable stateEnable)
{
if (_stateEnable is not null)
if (Initialized)
return false;
_stateEnable = stateEnable;
@ -112,7 +108,7 @@ public class GameObject : IGameObject
public bool Assign(ITransform transform)
{
if (_transform is not null)
if (Initialized)
return false;
_transform = transform;
@ -122,7 +118,7 @@ public class GameObject : IGameObject
public bool Assign(IBehaviourController behaviourController)
{
if (_behaviourController is not null)
if (Initialized)
return false;
_behaviourController = behaviourController;

View File

@ -29,7 +29,7 @@ public class StateEnable : IStateEnable
public bool Assign(IEntity entity)
{
if (_entity is not null)
if (_entity is not null) // TODO: IInitialize Maybe?
return false;
_entity = entity;