-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.cs
More file actions
135 lines (125 loc) · 4.53 KB
/
API.cs
File metadata and controls
135 lines (125 loc) · 4.53 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections.Generic;
using System.Text;
namespace SimpleModMenu
{
/// <summary>
/// API class for managing custom tabs in the mod menu.
/// </summary>
/// <remarks>
/// This class provides methods to register, unregister, and manage custom tabs in the mod menu.
/// </remarks>
internal static class API
{
private static readonly List<Tab> customTabs = new List<Tab>();
/// <summary>
/// Registers a custom tab to the API.
/// </summary>
/// <param name="tab">The tab</param>
/// <exception cref="ArgumentNullException">Thrown if tab is null</exception>
public static void RegisterTab(Tab tab)
{
if (tab == null)
{
throw new ArgumentNullException(nameof(tab), "Tab cannot be null.");
}
customTabs.Add(tab);
}
/// <summary>
/// Unregisters a custom tab from the API.
/// </summary>
/// <param name="tab"> The tab to unregister.</param>
/// <exception cref="ArgumentNullException">Thrown if tab is null</exception>
public static void UnregisterTab(Tab tab)
{
if (tab == null)
{
throw new ArgumentNullException(nameof(tab), "Tab cannot be null.");
}
customTabs.Remove(tab);
}
/// <summary>
/// Unregisters a custom tab from the API.
/// </summary>
/// <param name="index"> The index of the tab to unregister.</param>
/// <exception cref="ArgumentNullException">Thrown if index is out of bounds</exception>
public static void UnregisterTab(int index)
{
if (index < 0 || index >= customTabs.Count)
{
throw new ArgumentOutOfRangeException(nameof(index), "Index is out of range.");
}
customTabs.RemoveAt(index);
}
/// <summary>
/// Checks if a tab is registered in the API.
/// </summary>
/// <param name="tab">The tab</param>
/// <returns>True if tab is registered, else false.</returns>
/// <exception cref="ArgumentNullException"></exception>
public static bool IsTabRegistered(Tab tab)
{
if (tab == null)
{
throw new ArgumentNullException(nameof(tab), "Tab cannot be null.");
}
return customTabs.Contains(tab);
}
/// <summary>
/// Gets all registered tabs in the API.
/// </summary>
/// <returns>The tabs as a IEnumerable</returns>
public static IEnumerable<Tab> GetTabs()
{
return customTabs;
}
/// <summary>
/// Gets the count of registered tabs in the API.
/// </summary>
/// <returns>The count</returns>
public static int GetTabCount()
{
return customTabs.Count;
}
/// <summary>
/// Gets a tab in the API by its index.
/// </summary>
/// <param name="index">The index</param>
/// <returns>The tab</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if index is out of bounds</exception>
public static Tab GetTab(int index)
{
if (index < 0 || index >= customTabs.Count)
{
throw new ArgumentOutOfRangeException(nameof(index), "Index is out of range.");
}
return customTabs[index];
}
/// <summary>
/// Replaces a tab in the API at the specified index with a new tab.
/// </summary>
/// <param name="index">The index</param>
/// <param name="newTab">The new tab</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown if index is out of bounds</exception>
/// <exception cref="ArgumentNullException">Thrown if the new tab is null</exception>
public static void ReplaceTab(int index, Tab newTab)
{
if (index < 0 || index >= customTabs.Count)
{
throw new ArgumentOutOfRangeException(nameof(index), "Index is out of range.");
}
if (newTab == null)
{
throw new ArgumentNullException(nameof(newTab), "New tab cannot be null.");
}
customTabs[index] = newTab;
}
/// <summary>
/// Clears all registered tabs in the API.
/// </summary>
public static void ClearTabs()
{
customTabs.Clear();
}
}
}