-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginConfig.cs
More file actions
77 lines (68 loc) · 3.19 KB
/
Copy pathPluginConfig.cs
File metadata and controls
77 lines (68 loc) · 3.19 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
using System;
using System.Linq;
using HarmonyLib;
using BepInEx.Configuration;
namespace fall {
public static class PluginConfig {
private static ConfigFile configFile;
private static readonly string cmd = "fall";
private static readonly string desc = "A master toggle for Fall% mode";
private static readonly string help = new string[3] {
desc,
"\tUsage: <#F09>fall <arg?></color> ",
"\tFor a more detailed help please type <#F09>fall help</color> or <#F09>fall h</color>"
}.Join(delimiter: Environment.NewLine);
private static readonly string syntaxHelp = new string[6] {
ShellCommand.HelpColor.Value + "Syntax: <#F09>fall <arg?></color>",
"=> \tWhere <#FFF><#F09><arg></color> represents one of the following actions:</color> ",
" \t<#F90>Toggle:</color> \t<#F09>`t`</color> or <#F09>`toggle`</color>; ",
" \t<#F90>Query:</color> \t<#F09>`q`</color> or <#F09>`query`</color>; ",
" \t<#F90>Enable:</color> \t<#F09>`1`</color> or <#F09>`on`</color> or <#F09>`enable`</color>; ",
" \t<#F90>Disable:</color> \t<#F09>`0`</color> or <#F09>`off`</color> or <#F09>`disable`</color>." + "</color>",
}.Join(delimiter: Environment.NewLine);
private static ConfigEntry<bool> enableFall;
public static bool EnableFall => enableFall.Value;
public static void Init(ConfigFile config) {
configFile = config;
enableFall = configFile.Bind(
"General",
"EnableFall",
true,
desc
);
Shell.RegisterCommand(cmd, new Action<string>(Toggler), help);
}
public static void DestroyCmds() => ShellCommand.Destroy(cmd, true);
private static void Toggler(string input) {
bool before = enableFall.Value;
string[] args = input?.Trim().Split(' ').Select(s => s.Trim()).ToArray()
?? new string[1] { string.Empty };
try {
if (args.Length != 1) throw new ArgumentException();
switch (args[0]) {
case "h":
case "help":
Shell.Print(syntaxHelp);
return;
case "q":
case "query":
case "":
break;
default:
enableFall.Value = args[0] switch {
"t" or "toggle" => !enableFall.Value,
"1" or "on" or "enable" => true,
"0" or "off" or "disable" => false,
_ => throw new ArgumentException()
};
break;
}
bool changed = before != enableFall.Value;
Shell.Print($"Fall%{(changed ? " <#F09>(*Changed)</color>" : string.Empty)}: <#F90>{(enableFall.Value ? "Enabled" : "Disabled")}</color>");
if (changed) Plugin.OnToggle();
} catch (ArgumentException) {
ShellCommand.Help(cmd);
}
}
}
}