-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeature.cs
More file actions
54 lines (46 loc) · 1.89 KB
/
Feature.cs
File metadata and controls
54 lines (46 loc) · 1.89 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
using BepInEx.Configuration;
namespace CWAPI
{
public interface IFeature
{
string FeatureName { get; }
bool Enabled { get; }
bool Required { get; }
void CreateRequiredConfig(ConfigSection section);
void CreateConfig(ConfigSection section);
void Initialize();
}
public abstract class Feature<T> : IFeature where T : Feature<T>
{
public static T Instance { get; private set; } = default!;
private ManualLogSource? _logger;
private ConfigEntry<bool>? _enabled;
public bool Enabled => _enabled?.Value ?? Required;
internal ManualLogSource Logger => _logger ??= new ManualLogSource(LogSource, FeatureName);
public abstract BepInEx.Logging.ManualLogSource LogSource { get; }
public virtual bool Required { get; }
public abstract string FeatureName { get; }
public abstract string FeatureDescription { get; }
public Feature()
{
Instance = (T)this;
}
public void CreateRequiredConfig(ConfigSection section)
{
if (!Required)
_enabled = section.Bind(
nameof(Enabled),
true,
$"Enables feature: {FeatureDescription}"
);
}
public virtual void CreateConfig(ConfigSection section) { }
public abstract void Initialize();
public static void Debug(object data) => Instance.Logger.LogDebug(data);
public static void Message(object data) => Instance.Logger.LogMessage(data);
public static void Info(object data) => Instance.Logger.LogInfo(data);
public static void Warning(object data) => Instance.Logger.LogWarning(data);
public static void Error(object data) => Instance.Logger.LogError(data);
public static void Fatal(object data) => Instance.Logger.LogFatal(data);
}
}