forked from aldelaro5/LiveSplit.BugFables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBugFablesComponent.cs
92 lines (79 loc) · 2.38 KB
/
BugFablesComponent.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
using LiveSplit.Model;
using LiveSplit.UI;
using LiveSplit.UI.Components;
using LiveSplit.BugFables.UI;
using System.Xml;
using System.Windows.Forms;
using System;
namespace LiveSplit.BugFables
{
public class BugFablesComponent : LogicComponent
{
private LiveSplitState liveSplitState;
private TimerModel timerModel;
private GameMemory gameMemory;
private LiveSplitLogic logic;
private SettingsUserControl settingsUserControl;
public BugFablesComponent(LiveSplitState state)
{
liveSplitState = state;
timerModel = new TimerModel();
timerModel.CurrentState = liveSplitState;
gameMemory = new GameMemory();
settingsUserControl = new SettingsUserControl(state);
logic = new LiveSplitLogic(gameMemory, settingsUserControl);
liveSplitState.OnReset += OnReset;
liveSplitState.OnStart += OnStart;
}
private void OnStart(object sender, EventArgs e)
{
logic.ResetLogic();
}
public void OnReset(object sender, TimerPhase t)
{
logic.ResetLogic();
}
public override string ComponentName => BugFablesFactory.AutosplitterName;
public override void Dispose()
{
liveSplitState.OnStart -= OnStart;
liveSplitState.OnReset -= OnReset;
}
public override XmlNode GetSettings(XmlDocument document)
{
XmlNode result = settingsUserControl.SaveSettings(document);
if (settingsUserControl.settingsHasChanged)
{
logic.ResetLogic();
settingsUserControl.settingsHasChanged = false;
}
return result;
}
public override Control GetSettingsControl(LayoutMode mode)
{
return settingsUserControl;
}
public override void SetSettings(XmlNode settings)
{
settingsUserControl.LoadSettings(settings);
logic.ResetLogic();
}
public override void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
{
if (!gameMemory.ProcessHook())
return;
if (logic.ShouldStart())
{
logic.ResetLogic();
if (liveSplitState.CurrentPhase == TimerPhase.Running)
timerModel.Reset();
timerModel.Start();
}
if (liveSplitState.CurrentPhase == TimerPhase.Running)
{
if (logic.ShouldSplit(liveSplitState.CurrentSplitIndex, liveSplitState.Run.Count))
timerModel.Split();
}
}
}
}