-
Notifications
You must be signed in to change notification settings - Fork 39
/
PieceTables.cs
83 lines (73 loc) · 2.77 KB
/
PieceTables.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
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
using System.Collections.Generic;
using System.Linq;
using BepInEx.Configuration;
namespace Jotunn.Configs
{
/// <summary>
/// Helper to get existing piece table names
/// </summary>
public static class PieceTables
{
/// <summary>
/// Hammer piece table
/// </summary>
public static string Hammer => "_HammerPieceTable";
/// <summary>
/// Cultivator piece table
/// </summary>
public static string Cultivator => "_CultivatorPieceTable";
/// <summary>
/// Hoe piece table
/// </summary>
public static string Hoe => "_HoePieceTable";
/// <summary>
/// Gets the human readable name to internal names map
/// </summary>
/// <returns></returns>
public static Dictionary<string, string> GetNames()
{
return NamesMap;
}
/// <summary>
/// Get a <see cref="BepInEx.Configuration.AcceptableValueList{T}"/> of all piece table names.
/// This can be used to create a <see cref="BepInEx.Configuration.ConfigEntry{T}"/> where only valid piece table can be selected.<br/><br/>
/// Example:
/// <code>
/// var pieceTableConfig = Config.Bind("Section", "Key", nameof(PieceTables.Hammer), new ConfigDescription("Description", PieceTables.GetAcceptableValueList()));
/// </code>
/// </summary>
/// <returns></returns>
public static AcceptableValueList<string> GetAcceptableValueList()
{
return AcceptableValues;
}
/// <summary>
/// Get the internal name for a piece table from its human readable name.
/// </summary>
/// <param name="pieceTable"></param>
/// <returns>
/// The matched internal name.
/// If the pieceTable parameter is null or empty, an empty string is returned.
/// Otherwise the unchanged pieceTable parameter is returned.
/// </returns>
public static string GetInternalName(string pieceTable)
{
if (string.IsNullOrEmpty(pieceTable))
{
return string.Empty;
}
if (NamesMap.TryGetValue(pieceTable, out string internalName))
{
return internalName;
}
return pieceTable;
}
private static readonly Dictionary<string, string> NamesMap = new Dictionary<string, string>
{
{ nameof(Hammer), Hammer },
{ nameof(Cultivator), Cultivator },
{ nameof(Hoe), Hoe },
};
private static readonly AcceptableValueList<string> AcceptableValues = new AcceptableValueList<string>(NamesMap.Keys.ToArray());
}
}