diff --git a/QSB/HUD/MultiplayerHUDManager.cs b/QSB/HUD/MultiplayerHUDManager.cs
index d3886162..2970b741 100644
--- a/QSB/HUD/MultiplayerHUDManager.cs
+++ b/QSB/HUD/MultiplayerHUDManager.cs
@@ -94,7 +94,7 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart
if (_messages.Count > LINE_COUNT)
{
- _messages.RemoveFirstElementAndShift();
+ _messages.PopFromBack();
}
var currentLineIndex = 10;
diff --git a/QSB/HUD/PlanetTrigger.cs b/QSB/HUD/PlanetTrigger.cs
index 339e32a1..a97b12ce 100644
--- a/QSB/HUD/PlanetTrigger.cs
+++ b/QSB/HUD/PlanetTrigger.cs
@@ -16,7 +16,7 @@ public class PlanetTrigger : SectoredMonoBehaviour
}
MultiplayerHUDManager.HUDIconStack.Push(Icon);
- var top = MultiplayerHUDManager.HUDIconStack.Peek();
+ var top = MultiplayerHUDManager.HUDIconStack.PeekFront();
new PlanetMessage(top).Send();
}
@@ -28,7 +28,7 @@ public class PlanetTrigger : SectoredMonoBehaviour
}
MultiplayerHUDManager.HUDIconStack.Remove(Icon);
- var top = MultiplayerHUDManager.HUDIconStack.Peek();
+ var top = MultiplayerHUDManager.HUDIconStack.PeekFront();
new PlanetMessage(top).Send();
}
}
diff --git a/QSB/Utility/ListStack.cs b/QSB/Utility/ListStack.cs
index 98cd65c9..8a960bca 100644
--- a/QSB/Utility/ListStack.cs
+++ b/QSB/Utility/ListStack.cs
@@ -4,6 +4,9 @@ using System.Collections.Generic;
namespace QSB.Utility;
+///
+/// A LIFO collection with List<> functionality.
+///
public class ListStack : IEnumerable
{
private List _items = new();
@@ -12,14 +15,21 @@ public class ListStack : IEnumerable
private readonly bool _removeDuplicates;
+ /// If true, all elements equal to the added item will be removed prior to adding the new element.
public ListStack(bool removeDuplicates)
{
_removeDuplicates = removeDuplicates;
}
+ ///
+ /// Removes all items from the stack.
+ ///
public void Clear()
=> _items.Clear();
+ ///
+ /// Pushes an element onto the front of the stack.
+ ///
public void Push(T item)
{
if (_removeDuplicates && _items.Contains(item))
@@ -30,7 +40,10 @@ public class ListStack : IEnumerable
_items.Add(item);
}
- public T Pop()
+ ///
+ /// Pops an element off the front of the stack.
+ ///
+ public T PopFromFront()
{
if (_items.Count > 0)
{
@@ -42,7 +55,10 @@ public class ListStack : IEnumerable
return default;
}
- public T RemoveFirstElementAndShift()
+ ///
+ /// Pops an element off the back of the stack and shifts the entire stack backwards.
+ ///
+ public T PopFromBack()
{
if (_items.Count == 0)
{
@@ -50,29 +66,39 @@ public class ListStack : IEnumerable
}
var firstElement = _items[0];
-
- if (_items.Count == 0)
- {
- return firstElement;
- }
-
- // shift list left
- // allocates blehhh who cares
- _items = _items.GetRange(1, _items.Count - 1);
-
+ _items.RemoveAt(0);
return firstElement;
}
- public T Peek() => _items.Count > 0
+ ///
+ /// Returns the element at the front of the stack.
+ ///
+ public T PeekFront() => _items.Count > 0
? _items[_items.Count - 1]
: default;
+ ///
+ /// Returns the element at the back of the stack.
+ ///
+ public T PeekBack() => _items.Count > 0
+ ? _items[0]
+ : default;
+
+ ///
+ /// Removes the element at the given index, where 0 is the back of the stack. The stack will shift backwards to fill empty space.
+ ///
public void RemoveAt(int index)
=> _items.RemoveAt(index);
+ ///
+ /// Removes the first occurence (back to front) of an item.
+ ///
public bool Remove(T item)
=> _items.Remove(item);
+ ///
+ /// Removes all elements that match the given predicate.
+ ///
public int RemoveAll(Predicate match)
=> _items.RemoveAll(match);