Syntriax.Engine/Engine.Core/Abstract/IBehaviourController.cs

94 lines
4.9 KiB
C#

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>
/// Callback triggered when the <see cref="Update()"/> is called but right before the <see cref="OnUpdate"/> action is triggered.
/// </summary>
Action<IBehaviourController>? OnPreUpdate { get; set; }
/// <summary>
/// Callback triggered when the <see cref="Update()"/> is called.
/// </summary>
Action<IBehaviourController>? OnUpdate { get; set; }
/// <summary>
/// Callback triggered when the <see cref="OnPreDraw()"/> is called.
/// </summary>
Action<IBehaviourController>? OnPreDraw { get; set; }
/// <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);
/// <typeparam name="T">An implemented class or <see cref="interface"/>.</typeparam>
/// <returns>Returns a list of all the matching <see cref="IBehaviour"/>s found in the <see cref="IBehaviourController"/>.</returns>
IList<T> GetBehaviours<T>();
/// <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>(bool removeAll = false) where T : class, IBehaviour;
/// <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;
/// <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>
/// <param name=""><see cref=""/> information from the game.</param>
void Update();
/// <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>
/// <param name=""><see cref=""/> information from the game.</param>
void UpdatePreDraw();
}