This commit is contained in:
2025-05-30 16:05:49 +03:00
committed by Syntriax
parent 846aa75dd5
commit b5140a94de
57 changed files with 437 additions and 462 deletions

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@@ -8,11 +7,11 @@ namespace Syntriax.Engine.Core;
[System.Diagnostics.DebuggerDisplay("Behaviour Count: {behaviours.Count}")]
public class BehaviourController : BaseEntity, IBehaviourController
{
public Event<IBehaviourController, IBehaviour> OnBehaviourAdded { get; private set; } = new();
public Event<IBehaviourController, IBehaviour> OnBehaviourRemoved { get; private set; } = new();
public Event<IHasUniverseObject> OnUniverseObjectAssigned { get; private set; } = new();
public Event<IBehaviourController, IBehaviourController.BehaviourAddedArguments> OnBehaviourAdded { get; init; } = new();
public Event<IBehaviourController, IBehaviourController.BehaviourRemovedArguments> OnBehaviourRemoved { get; init; } = new();
public Event<IHasUniverseObject> OnUniverseObjectAssigned { get; init; } = new();
private readonly IList<IBehaviour> behaviours = new List<IBehaviour>(Constants.BEHAVIOURS_SIZE_INITIAL);
private readonly List<IBehaviour> behaviours = new(Constants.BEHAVIOURS_SIZE_INITIAL);
private IUniverseObject _universeObject = null!;
@@ -20,9 +19,6 @@ public class BehaviourController : BaseEntity, IBehaviourController
public int Count => behaviours.Count;
public IBehaviour this[Index index] => behaviours[index];
public int Count => behaviours.Count;
public IBehaviour this[Index index] => behaviours[index];
public T AddBehaviour<T>(T behaviour) where T : class, IBehaviour
{
InsertBehaviourByPriority(behaviour);
@@ -32,7 +28,7 @@ public class BehaviourController : BaseEntity, IBehaviourController
if (IsInitialized)
behaviour.Initialize();
behaviour.OnPriorityChanged.AddListener(OnPriorityChange);
OnBehaviourAdded?.Invoke(this, behaviour);
OnBehaviourAdded?.Invoke(this, new(behaviour));
return behaviour;
}
@@ -100,7 +96,7 @@ public class BehaviourController : BaseEntity, IBehaviourController
behaviour.OnPriorityChanged.RemoveListener(OnPriorityChange);
behaviour.Finalize();
behaviours.Remove(behaviour);
OnBehaviourRemoved?.Invoke(this, behaviour);
OnBehaviourRemoved?.Invoke(this, new(behaviour));
}
protected virtual void OnAssign(IUniverseObject universeObject) { }
@@ -149,7 +145,7 @@ public class BehaviourController : BaseEntity, IBehaviourController
behaviours.Add(behaviour);
}
private void OnPriorityChange(IBehaviour sender, int previousPriority)
private void OnPriorityChange(IBehaviour sender, IBehaviour.PriorityChangedArguments arguments)
{
behaviours.Remove(sender);
InsertBehaviourByPriority(sender);