-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPluginConfig.cs
111 lines (102 loc) · 4.26 KB
/
PluginConfig.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
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
/*
* PluginConfig.cs
* PerformanceMeter
*
* This file defines the configuration of PerformanceMeter.
*
* This code is licensed under the MIT license.
* Copyright (c) 2021-2022 JackMacWindows.
*/
using System.Runtime.CompilerServices;
using IPA.Config.Data;
using IPA.Config.Stores;
using IPA.Config.Stores.Attributes;
using IPA.Config.Stores.Converters;
using UnityEngine;
[assembly: InternalsVisibleTo(GeneratedStore.AssemblyVisibilityTarget)]
namespace PerformanceMeter {
internal class IntColorConverter : ValueConverter<Color> {
public override Color FromValue(Value value, object parent) {
if (!(value is Integer)) throw new System.ArgumentException("Input value is not an integer");
long num = (value as Integer).Value;
return new Color(((num >> 16) & 0xFF) / 255.0f, ((num >> 8) & 0xFF) / 255.0f, (num & 0xFF) / 255.0f);
}
public override Value ToValue(Color obj, object parent) {
return new Integer((long)(obj.r * 255) << 16 | (long)(obj.g * 255) << 8 | (long)(obj.b * 255));
}
}
public class PluginConfig {
public static PluginConfig Instance { get; set; }
public virtual bool enabled { get; set; } = true;
[UseConverter(typeof(NumericEnumConverter<MeasurementMode>))]
public virtual MeasurementMode mode { get; set; } = MeasurementMode.Energy;
[UseConverter(typeof(NumericEnumConverter<MeasurementSide>))]
public virtual MeasurementSide side { get; set; } = MeasurementSide.Both;
[UseConverter(typeof(IntColorConverter))]
public Color sideColor {
get {
return side switch {
MeasurementSide.Left => Color.red,
MeasurementSide.Right => Color.blue,
MeasurementSide.Both => Color.white,
_ => Color.white,
};
}
}
[UseConverter(typeof(NumericEnumConverter<MeasurementMode>))]
public virtual MeasurementMode secondaryMode { get; set; } = MeasurementMode.None;
[UseConverter(typeof(NumericEnumConverter<MeasurementSide>))]
public virtual MeasurementSide secondarySide { get; set; } = MeasurementSide.Both;
[UseConverter(typeof(IntColorConverter))]
public Color secondarySideColor {
get {
return secondarySide switch {
MeasurementSide.Left => Color.red,
MeasurementSide.Right => Color.blue,
MeasurementSide.Both => Color.white,
_ => Color.white,
};
}
}
public virtual bool showMisses { get; set; } = false;
public virtual float animationDuration { get; set; } = 3.0f;
[UseConverter(typeof(IntColorConverter))]
public virtual Color color { get; set; } = new Color(1f, 0f, 0f);
[UseConverter(typeof(IntColorConverter))]
public virtual Color secondaryColor { get; set; } = new Color(0f, 0f, 1f);
public virtual bool overrideColor { get; set; } = false;
public virtual bool overrideSecondaryColor { get; set; } = false;
public enum MeasurementMode {
Energy,
PercentModified,
PercentRaw,
CutValue,
AvgCutValue,
None
};
public enum MeasurementSide {
Left,
Right,
Both
}
/// <summary>
/// This is called whenever BSIPA reads the config from disk (including when file changes are detected).
/// </summary>
public virtual void OnReload() {
// Do stuff after config is read from disk.
}
/// <summary>
/// Call this to force BSIPA to update the config file. This is also called by BSIPA if it detects the file was modified.
/// </summary>
public virtual void Changed() {
// Do stuff when the config is changed.
Logger.log.Debug("Updated configuration");
}
/// <summary>
/// Call this to have BSIPA copy the values from <paramref name="other"/> into this config.
/// </summary>
public virtual void CopyFrom(PluginConfig other) {
// This instance's members populated from other
}
}
}