chore: Added Initial Engine Code
This commit is contained in:
99
Engine.Core/Behaviour.cs
Normal file
99
Engine.Core/Behaviour.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
using Syntriax.Engine.Core.Exceptions;
|
||||
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public abstract class Behaviour : IBehaviour
|
||||
{
|
||||
public Action<IAssignableStateEnable>? OnStateEnableAssigned { get; set; } = null;
|
||||
public Action<IAssignableBehaviourController>? OnBehaviourControllerAssigned { get; set; } = null;
|
||||
|
||||
public Action<IInitialize>? OnInitialized { get; set; } = null;
|
||||
public Action<IInitialize>? OnFinalized { get; set; } = null;
|
||||
public Action<IBehaviour>? OnPriorityChanged { get; set; } = null;
|
||||
|
||||
|
||||
private IBehaviourController _behaviourController = null!;
|
||||
private IStateEnable _stateEnable = null!;
|
||||
|
||||
private bool _initialized = false;
|
||||
private int _priority = 0;
|
||||
|
||||
public IStateEnable StateEnable => _stateEnable;
|
||||
public IBehaviourController BehaviourController => _behaviourController;
|
||||
|
||||
public bool Initialized
|
||||
{
|
||||
get => _initialized;
|
||||
private set
|
||||
{
|
||||
if (value == _initialized)
|
||||
return;
|
||||
|
||||
_initialized = value;
|
||||
if (value)
|
||||
OnInitialized?.Invoke(this);
|
||||
else
|
||||
OnFinalized?.Invoke(this);
|
||||
}
|
||||
}
|
||||
|
||||
public int Priority
|
||||
{
|
||||
get => _priority;
|
||||
set
|
||||
{
|
||||
if (value == _priority)
|
||||
return;
|
||||
|
||||
_priority = value;
|
||||
OnPriorityChanged?.Invoke(this);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Assign(IStateEnable stateEnable)
|
||||
{
|
||||
if (_initialized)
|
||||
return false;
|
||||
|
||||
_stateEnable = stateEnable;
|
||||
_stateEnable.Assign(this);
|
||||
OnStateEnableAssigned?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Assign(IBehaviourController behaviourController)
|
||||
{
|
||||
if (_behaviourController is not null)
|
||||
return false;
|
||||
|
||||
_behaviourController = behaviourController;
|
||||
OnBehaviourControllerAssigned?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Initialize()
|
||||
{
|
||||
if (Initialized)
|
||||
return false;
|
||||
|
||||
NotAssignedException.Check(this, _behaviourController);
|
||||
NotAssignedException.Check(this, _stateEnable);
|
||||
|
||||
Initialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Finalize()
|
||||
{
|
||||
if (!Initialized)
|
||||
return false;
|
||||
|
||||
_behaviourController = null!;
|
||||
_stateEnable = null!;
|
||||
|
||||
Initialized = false;
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user