-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlugin.cs
More file actions
99 lines (83 loc) · 3.96 KB
/
Copy pathPlugin.cs
File metadata and controls
99 lines (83 loc) · 3.96 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using Dalamud.Game.Command;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using QuestionableJsonBuilder.Debug;
using QuestionableJsonBuilder.Services;
using QuestionableJsonBuilder.Windows;
namespace QuestionableJsonBuilder;
public sealed class Plugin : IDalamudPlugin
{
internal static IDalamudPluginInterface PluginInterface { get; private set; } = null!;
internal static ICommandManager CommandManager { get; private set; } = null!;
internal static IObjectTable ObjectTable { get; private set; } = null!;
internal static IClientState ClientState { get; private set; } = null!;
internal static IDataManager DataManager { get; private set; } = null!;
internal static IPluginLog Log { get; private set; } = null!;
internal static Configuration Configuration { get; private set; } = null!;
private const string CommandName = "/qstb";
private const int CurrentConfigVersion = 2;
private const string WorkerUrl = "https://questionable-worker.epinephren.workers.dev/";
private readonly WindowSystem windowSystem = new("QuestionableJsonBuilder");
private readonly QuestWizardController controller;
private readonly MainWindow mainWindow;
private readonly ConfigWindow configWindow;
private readonly QuestDebugWindow questDebugWindow;
private readonly HelpWindow helpWindow;
public Plugin(
IDalamudPluginInterface pluginInterface,
ICommandManager commandManager,
IObjectTable objectTable,
IClientState clientState,
IDataManager dataManager,
IPluginLog pluginLog)
{
PluginInterface = pluginInterface;
CommandManager = commandManager;
ObjectTable = objectTable;
ClientState = clientState;
DataManager = dataManager;
Log = pluginLog;
Configuration = pluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
Configuration.Initialize(pluginInterface);
if (Configuration.Version < CurrentConfigVersion ||
Configuration.RemoteQuestIndexUrl.Contains("api.github.com", StringComparison.OrdinalIgnoreCase))
{
Configuration.RemoteQuestIndexUrl = WorkerUrl;
Configuration.Version = CurrentConfigVersion;
Configuration.Save();
}
this.controller = new QuestWizardController();
this.helpWindow = new HelpWindow();
this.mainWindow = new MainWindow(this.controller, this.OpenDebugUi, this.OpenHelpUi, this.OpenConfigUi);
this.configWindow = new ConfigWindow(this.controller);
this.questDebugWindow = new QuestDebugWindow(this.controller);
this.windowSystem.AddWindow(this.mainWindow);
this.windowSystem.AddWindow(this.configWindow);
this.windowSystem.AddWindow(this.questDebugWindow);
this.windowSystem.AddWindow(this.helpWindow);
CommandManager.AddHandler(CommandName, new CommandInfo(this.OnCommand)
{
HelpMessage = "Open the Questionable JSON Builder."
});
PluginInterface.UiBuilder.Draw += this.DrawUi;
PluginInterface.UiBuilder.OpenMainUi += this.OpenMainUi;
PluginInterface.UiBuilder.OpenConfigUi += this.OpenConfigUi;
}
private void OnCommand(string command, string arguments)
=> this.OpenMainUi();
internal void DrawUi() => this.windowSystem.Draw();
internal void OpenMainUi() => this.mainWindow.IsOpen = true;
internal void OpenConfigUi() => this.configWindow.IsOpen = true;
internal void OpenDebugUi() => this.questDebugWindow.IsOpen = true;
internal void OpenHelpUi() => this.helpWindow.IsOpen = true;
public void Dispose()
{
PluginInterface.UiBuilder.Draw -= this.DrawUi;
PluginInterface.UiBuilder.OpenMainUi -= this.OpenMainUi;
PluginInterface.UiBuilder.OpenConfigUi -= this.OpenConfigUi;
CommandManager.RemoveHandler(CommandName);
this.windowSystem.RemoveAllWindows();
this.controller.Dispose();
}
}