-
Notifications
You must be signed in to change notification settings - Fork 11
/
DeathRecapPlugin.cs
80 lines (62 loc) · 2.58 KB
/
DeathRecapPlugin.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
using System;
using System.Collections.Generic;
using Dalamud.Game.Command;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using DeathRecap.Events;
using DeathRecap.UI;
namespace DeathRecap;
public class DeathRecapPlugin : IDalamudPlugin {
public DeathRecapWindow Window { get; }
public ConfigWindow ConfigWindow { get; }
public Configuration Configuration { get; }
public ConditionEvaluator ConditionEvaluator { get; }
public CombatEventCapture CombatEventCapture { get; }
public NotificationHandler NotificationHandler { get; }
public WindowSystem WindowSystem { get; }
public Dictionary<ulong, List<Death>> DeathsPerPlayer { get; } = new();
private DateTime lastClean = DateTime.Now;
public DeathRecapPlugin(IDalamudPluginInterface pluginInterface) {
Service.Initialize(pluginInterface);
Configuration = Configuration.Get(pluginInterface);
Window = new DeathRecapWindow(this);
ConfigWindow = new ConfigWindow(this);
ConditionEvaluator = new ConditionEvaluator(this);
CombatEventCapture = new CombatEventCapture(this);
NotificationHandler = new NotificationHandler(this);
WindowSystem = new WindowSystem("DeathRecap");
WindowSystem.AddWindow(Window);
WindowSystem.AddWindow(ConfigWindow);
WindowSystem.AddWindow(NotificationHandler);
pluginInterface.UiBuilder.Draw += () => WindowSystem.Draw();
pluginInterface.UiBuilder.OpenMainUi += () => Window.Toggle();
pluginInterface.UiBuilder.OpenConfigUi += () => ConfigWindow.Toggle();
Service.Framework.Update += FrameworkOnUpdate;
var commandInfo = new CommandInfo((_, _) => Window.Toggle()) { HelpMessage = "Open the death recap window" };
Service.CommandManager.AddHandler("/deathrecap", commandInfo);
Service.CommandManager.AddHandler("/dr", commandInfo);
#if DEBUG
try {
DummyData.AddDummyData(this);
} catch (Exception e) {
Service.PluginLog.Error(e, "Failed to add dummy data");
}
#endif
}
private void FrameworkOnUpdate(IFramework framework) {
#if !DEBUG
var now = DateTime.Now;
if ((now - lastClean).TotalSeconds >= 10) {
CombatEventCapture.CleanCombatEvents();
lastClean = now;
}
#endif
}
public void Dispose() {
CombatEventCapture.Dispose();
Service.Framework.Update -= FrameworkOnUpdate;
Service.CommandManager.RemoveHandler("/deathrecap");
Service.CommandManager.RemoveHandler("/dr");
}
}