-
Notifications
You must be signed in to change notification settings - Fork 7
/
QualityBasedConfig.cs
49 lines (41 loc) · 1.22 KB
/
QualityBasedConfig.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
using Newtonsoft.Json;
using System;
using SObject = StardewValley.Object;
namespace Shockah.InAHeartbeat;
public sealed class QualityBasedConfig<T>
{
[JsonProperty] public T Regular { get; internal set; }
[JsonProperty] public T Silver { get; internal set; }
[JsonProperty] public T Gold { get; internal set; }
[JsonProperty] public T Iridium { get; internal set; }
public QualityBasedConfig(T regular, T silver, T gold, T iridium)
{
this.Regular = regular;
this.Silver = silver;
this.Gold = gold;
this.Iridium = iridium;
}
public T GetForQuality(int quality)
=> quality switch
{
SObject.bestQuality => Iridium,
SObject.highQuality => Gold,
SObject.medQuality => Silver,
_ => Regular
};
}
public static class QualityBasedConfigExt
{
public static T GetMin<T>(this QualityBasedConfig<T> config) where T : IComparable<T>
{
static T Min(T a, T b)
=> a.CompareTo(b) <= 0 ? a : b;
return Min(Min(config.Regular, config.Silver), Min(config.Gold, config.Iridium));
}
public static T GetMax<T>(this QualityBasedConfig<T> config) where T : IComparable<T>
{
static T Max(T a, T b)
=> a.CompareTo(b) >= 0 ? a : b;
return Max(Max(config.Regular, config.Silver), Max(config.Gold, config.Iridium));
}
}