-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathNoClippy.cs
126 lines (109 loc) · 4.21 KB
/
NoClippy.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using Dalamud.Game.Text;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
namespace NoClippy
{
public class NoClippy : IDalamudPlugin
{
public static NoClippy Plugin { get; private set; }
public static Configuration Config { get; private set; }
public NoClippy(IDalamudPluginInterface pluginInterface)
{
Plugin = this;
DalamudApi.Initialize(this, pluginInterface);
Config = (Configuration)DalamudApi.PluginInterface.GetPluginConfig() ?? new();
Config.Initialize();
try
{
Game.Initialize();
DalamudApi.Framework.Update += Update;
DalamudApi.PluginInterface.UiBuilder.Draw += PluginUI.Draw;
DalamudApi.PluginInterface.UiBuilder.OpenConfigUi += ConfigUI.ToggleVisible;
Modules.Modules.Initialize();
}
catch (Exception e)
{
PrintError("Failed to load!");
DalamudApi.LogError(e.ToString());
}
}
[Command("/noclippy")]
[HelpMessage("/noclippy [on|off|toggle|dry|help] - Toggles the config window if no option is specified.")]
private void OnNoClippy(string command, string argument)
{
switch (argument)
{
case "on":
case "toggle" when !Config.EnableAnimLockComp:
case "t" when !Config.EnableAnimLockComp:
Config.EnableAnimLockComp = true;
Config.Save();
PrintEcho("Enabled animation lock compensation!");
break;
case "off":
case "toggle" when Config.EnableAnimLockComp:
case "t" when Config.EnableAnimLockComp:
Config.EnableAnimLockComp = false;
Config.Save();
PrintEcho("Disabled animation lock compensation!");
break;
case "dry":
case "d":
PrintEcho($"Dry run is now {((Config.EnableDryRun = !Config.EnableDryRun) ? "enabled" : "disabled")}.");
Config.Save();
break;
case "":
ConfigUI.ToggleVisible();
break;
default:
PrintEcho("Invalid usage: Command must be \"/noclippy <option>\"." +
"\non / off / toggle - Enables or disables animation lock compensation." +
"\ndry - Toggles dry run (will not override the animation lock).");
break;
}
}
public static void PrintEcho(string message) => DalamudApi.ChatGui.Print($"[NoClippy] {message}");
public static void PrintError(string message) => DalamudApi.ChatGui.PrintError($"[NoClippy] {message}");
public static void PrintLog(string message)
{
if (Config.LogToChat)
{
if (Config.LogChatType != XivChatType.None)
{
DalamudApi.ChatGui.Print(new XivChatEntry
{
Message = $"[NoClippy] {message}",
Type = Config.LogChatType
});
}
else
{
PrintEcho(message);
}
}
else
{
DalamudApi.LogInfo(message);
}
}
public static int F2MS(float f) => (int)Math.Round(f * 1000);
private static void Update(IFramework framework) => Game.Update();
protected virtual void Dispose(bool disposing)
{
if (!disposing) return;
Config.Save();
DalamudApi.Framework.Update -= Update;
DalamudApi.PluginInterface.UiBuilder.Draw -= PluginUI.Draw;
DalamudApi.PluginInterface.UiBuilder.OpenConfigUi -= ConfigUI.ToggleVisible;
Modules.Modules.Dispose();
Game.Dispose();
DalamudApi.Dispose();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}