-
Notifications
You must be signed in to change notification settings - Fork 0
/
DialogueQueue.cs
29 lines (26 loc) · 1.03 KB
/
DialogueQueue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System;
using System.Collections;
using System.Collections.Generic;
namespace LogMenu
{
// Wrapper class for queue - the difference is the queue has a max amount of elements
public class DialogueQueue<T> : Queue<T>, IEnumerable<T>
{
private readonly int maxSize; // Configurable in ModConfig.js
private readonly Queue<T> queue;
public DialogueQueue(int maxSize)
{
if (maxSize <= 0) throw new ArgumentOutOfRangeException("maxSize", "The maximum size must be greater than zero.");
this.maxSize = maxSize;
this.queue = new Queue<T>();
}
public void enqueue(T item)
{
if (queue.Count >= maxSize) queue.Dequeue(); // Queue has a max size - if exceeded, remove first element from queue
queue.Enqueue(item);
}
// Makes this class iterable
public new IEnumerator<T> GetEnumerator() { return queue.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
}