forked from Casimir255/GridTransporter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.cs
81 lines (67 loc) · 2.35 KB
/
Main.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
using GridTransporter.Configs;
using GridTransporter.UI;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using Torch;
using Torch.API;
using Torch.API.Plugins;
using Torch.API.Managers;
using Torch.Session;
using Torch.API.Session;
using Torch.Managers;
using GridTransporter.Networking;
using GridTransporter.BoundrySystem;
using GridTransporter.Utilities;
namespace GridTransporter
{
public class Main : TorchPluginBase, IWpfPlugin
{
public static Settings Config => _config?.Data;
public static Persistent<Settings> _config;
public UserControl _control;
public UserControl GetControl() => _control ?? (_control = new UserControlInterface());
public bool IsRunning = false;
private Networking.Networking Socket;
private BoundaryTask BoundryChecker;
public override void Init(ITorchBase torch)
{
string path = Path.Combine(StoragePath, "GridTransporter.cfg");
_config = Persistent<Settings>.Load(path);
TorchSessionManager TorchSession = Torch.Managers.GetManager<TorchSessionManager>();
if (TorchSession != null)
TorchSession.SessionStateChanged += TorchSession_SessionStateChanged; ;
}
private void TorchSession_SessionStateChanged(ITorchSession session, TorchSessionState newState)
{
IsRunning = newState == TorchSessionState.Loaded;
switch (newState)
{
case TorchSessionState.Loaded:
IsRunning = true;
ServerLoaded(session);
break;
case TorchSessionState.Unloading:
IsRunning = false;
PluginDispose();
break;
}
}
private void PluginDispose()
{
Socket?.Close();
BoundryChecker?.Close();
}
private void ServerLoaded(ITorchSession session)
{
PluginManager Plugins = Torch.CurrentSession.Managers.GetManager<PluginManager>();
PluginDependencyManager.InitPluginDependencyManager(Plugins);
Socket = new Networking.Networking();
BoundryChecker = new BoundaryTask();
}
}
}