2023-11-23 22:07:49 +03:00
using System ;
using System.Collections.Generic ;
using System.Diagnostics.CodeAnalysis ;
namespace Syntriax.Engine.Core.Abstract ;
/// <summary>
/// Responsible for controlling <see cref="IBehaviour"/>s and notify them accordingly about the engine's updates. Connected to an <see cref="IGameObject"/>.
/// </summary>
public interface IBehaviourController : IAssignableGameObject
{
/// <summary>
2024-01-22 22:45:40 +03:00
/// Callback triggered when the <see cref="Update()"/> is called but right before the <see cref="OnUpdate"/> action is triggered.
2023-11-30 10:39:40 +03:00
/// </summary>
2024-01-22 22:45:40 +03:00
Action < IBehaviourController > ? OnPreUpdate { get ; set ; }
2023-11-30 10:39:40 +03:00
/// <summary>
2024-01-22 22:45:40 +03:00
/// Callback triggered when the <see cref="Update()"/> is called.
2023-11-23 22:07:49 +03:00
/// </summary>
2024-01-22 22:45:40 +03:00
Action < IBehaviourController > ? OnUpdate { get ; set ; }
2023-11-23 22:07:49 +03:00
/// <summary>
2024-01-22 22:45:40 +03:00
/// Callback triggered when the <see cref="OnPreDraw()"/> is called.
2023-11-23 22:07:49 +03:00
/// </summary>
2024-01-22 22:45:40 +03:00
Action < IBehaviourController > ? OnPreDraw { get ; set ; }
2023-11-23 22:07:49 +03:00
/// <summary>
/// Callback triggered when the <see cref="IBehaviourController"/> has been registered a new <see cref="IBehaviour"/>.
/// </summary>
Action < IBehaviourController , IBehaviour > ? OnBehaviourAdded { get ; set ; }
/// <summary>
/// Callback triggered when the <see cref="IBehaviourController"/> has been removed an existing <see cref="IBehaviour"/>.
/// </summary>
Action < IBehaviourController , IBehaviour > ? OnBehaviourRemoved { get ; set ; }
/// <summary>
/// Registers the provided <see cref="IBehaviour"/> to be controlled by the <see cref="IBehaviourController"/>.
/// </summary>
/// <param name="behaviour">Uninitialized <see cref="IBehaviour"/> to be registered.</param>
/// <typeparam name="T">An implemented class of <see cref="IBehaviour"/></typeparam>
/// <returns>The provided <see cref="IBehaviour"/> class after initialization.</returns>
T AddBehaviour < T > ( T behaviour ) where T : class , IBehaviour ;
/// <summary>
/// Instantiates the provided <see cref="IBehaviour"/> type and registers it to the <see cref="IBehaviourController"/>.
/// </summary>
/// <param name="args">Constructor parameters for the given <see cref="IBehaviour"/> class.</param>
/// <typeparam name="T">An implemented class of <see cref="IBehaviour"/></typeparam>
/// <returns>The instantiated <see cref="IBehaviour"/> class after initialization.</returns>
T AddBehaviour < T > ( params object? [ ] ? args ) where T : class , IBehaviour ;
/// <summary>
/// Looks up and tries to get the <see cref="IBehaviour"/> that is controlled by the <see cref="IBehaviourController"/>.
/// </summary>
/// <param name="behaviour">If return value is <see cref="true"/> outputs the class found in the <see cref="IBehaviourController"/>. If the return value is falls, this parameter is <see cref="null"/></param>
/// <typeparam name="T">An implemented class or <see cref="interface"/></typeparam>
/// <returns>
/// <see cref="true"/>, if the type of <see cref="IBehaviour"/> is present in the <see cref="IBehaviourController"/>, <see cref="false"/> if not.
/// </returns>
bool TryGetBehaviour < T > ( [ NotNullWhen ( returnValue : true ) ] out T ? behaviour ) ;
2023-11-30 17:54:32 +03:00
/// <typeparam name="T">An implemented class or <see cref="interface"/>.</typeparam>
2023-11-23 22:07:49 +03:00
/// <returns>Returns a list of all the matching <see cref="IBehaviour"/>s found in the <see cref="IBehaviourController"/>.</returns>
2023-11-30 17:54:32 +03:00
IList < T > GetBehaviours < T > ( ) ;
2023-11-23 22:07:49 +03:00
/// <summary>
/// Removes the <see cref="IBehaviour"/> found in the <see cref="IBehaviourController"/>.
/// </summary>
/// <param name="removeAll">If all of the instances of the given Type is to be removed or not.</param>
/// <typeparam name="T">An implemented class or <see cref="interface"/> of <see cref="IBehaviour"/></typeparam>
2023-11-30 17:54:32 +03:00
void RemoveBehaviour < T > ( bool removeAll = false ) where T : class , IBehaviour ;
2023-11-23 22:07:49 +03:00
2023-11-30 17:54:32 +03:00
/// <summary>
/// Removes the <see cref="IBehaviour"/> found in the <see cref="IBehaviourController"/>.
/// </summary>
/// <param name="removeAll">If all of the instances of the given Type is to be removed or not.</param>
/// <typeparam name="T">An implemented class or <see cref="interface"/> of <see cref="IBehaviour"/></typeparam>
void RemoveBehaviour < T > ( T behaviour ) where T : class , IBehaviour ;
2023-11-23 22:07:49 +03:00
/// <summary>
/// To be called in every frame of the engine. Responsible for notifying <see cref="IBehaviour"/>'s under the <see cref="IBehaviourController"/>'s control that a new frame is happening.
/// </summary>
2024-01-22 22:45:40 +03:00
/// <param name=""><see cref=""/> information from the game.</param>
void Update ( ) ;
2023-11-23 22:07:49 +03:00
/// <summary>
/// To be called before every draw call from the engine. Responsible for notifying <see cref="IBehaviour"/>'s under the <see cref="IBehaviourController"/>'s control that the engine is about to start drawing into the screen.
/// </summary>
2024-01-22 22:45:40 +03:00
/// <param name=""><see cref=""/> information from the game.</param>
void UpdatePreDraw ( ) ;
2023-11-23 22:07:49 +03:00
}