mirror of
https://github.com/NexusForever/NexusForever
synced 2026-08-14 00:26:05 -04:00
* Update target typing (new type to new()) https://medium.com/swlh/an-introduction-to-the-new-features-in-c-9-305dc8fb74d2 4. Target Typing Improvements * Remove new line * Remove more new lines. * Updated type targed new to var for method variables to be consistent with the rest of the code base. Co-authored-by: Rawaho <rawahodev@gmail.com>
44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace NexusForever.WorldServer.Command
|
|
{
|
|
public class ParameterQueue
|
|
{
|
|
/// <summary>
|
|
/// Returns the amount of parameters left in the queue.
|
|
/// </summary>
|
|
public uint Count => (uint)queue.Count;
|
|
|
|
/// <summary>
|
|
/// Returns the parameter at the front of the queue.
|
|
/// </summary>
|
|
public string Front => queue.Count != 0 ? queue.Peek() : null;
|
|
|
|
/// <summary>
|
|
/// Return a string representing a breadcrumb trail of previously dequeued parameters.
|
|
/// </summary>
|
|
public string BreadcrumbTrail => string.Join(' ', breadcrumbs.Reverse());
|
|
|
|
private readonly Queue<string> queue;
|
|
private readonly Stack<string> breadcrumbs = new();
|
|
|
|
/// <summary>
|
|
/// Create a new <see cref="ParameterQueue"/> from an array of parameters.
|
|
/// </summary>
|
|
public ParameterQueue(string[] commands)
|
|
{
|
|
queue = new Queue<string>(commands);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the next parameter and removes it from the queue.
|
|
/// </summary>
|
|
public string Dequeue()
|
|
{
|
|
string value = queue.Dequeue();
|
|
breadcrumbs.Push(value);
|
|
return value;
|
|
}
|
|
}
|
|
}
|