fix: sorted collector behaviours not working properly as the last object

This commit is contained in:
Syntriax 2025-04-06 10:21:10 +03:00
parent 906edf096e
commit 33a452a62e
2 changed files with 26 additions and 4 deletions

View File

@ -6,7 +6,18 @@ namespace Syntriax.Engine.Core;
public class ActiveBehaviourCollectorSorted<T> : ActiveBehaviourCollector<T> where T : class, IBehaviour
{
public Comparison<T>? SortBy { get; set; } = null;
private Comparison<T>? _sortBy = null;
public Comparison<T>? SortBy
{
get => _sortBy;
set
{
_sortBy = value;
if (value is not null)
activeBehaviours.Sort(value);
}
}
protected override void OnBehaviourAdd(IBehaviour behaviour)
{
@ -15,5 +26,5 @@ public class ActiveBehaviourCollectorSorted<T> : ActiveBehaviourCollector<T> whe
}
public ActiveBehaviourCollectorSorted() { }
public ActiveBehaviourCollectorSorted(IGameManager gameManager) : base(gameManager) { }
public ActiveBehaviourCollectorSorted(IGameManager gameManager, Comparison<T> sortBy) : base(gameManager) => SortBy = sortBy;
}

View File

@ -6,7 +6,18 @@ namespace Syntriax.Engine.Core;
public class BehaviourCollectorSorted<T> : BehaviourCollector<T> where T : class
{
public Comparison<T>? SortBy { get; set; } = null;
private Comparison<T>? _sortBy = null;
public Comparison<T>? SortBy
{
get => _sortBy;
set
{
_sortBy = value;
if (value is not null)
behaviours.Sort(value);
}
}
protected override void OnBehaviourAdd(IBehaviour behaviour)
{
@ -15,5 +26,5 @@ public class BehaviourCollectorSorted<T> : BehaviourCollector<T> where T : class
}
public BehaviourCollectorSorted() { }
public BehaviourCollectorSorted(IGameManager gameManager) : base(gameManager) { }
public BehaviourCollectorSorted(IGameManager gameManager, Comparison<T> sortBy) : base(gameManager) => SortBy = sortBy;
}