forked from tyzeron/LethalCompanyMinimap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Models.cs
154 lines (144 loc) · 4.98 KB
/
Models.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// ----------------------------------------------------------------------
// Copyright (c) Tyzeron. All Rights Reserved.
// Licensed under the GNU Affero General Public License, Version 3
// ----------------------------------------------------------------------
using System.Collections.Generic;
namespace LethalCompanyMinimap
{
public class ModUser
{
public string Version { get; set; }
public bool Comply { get; set; }
public ModUser(string version = null, bool comply = false)
{
this.Version = version;
this.Comply = comply;
}
}
public enum SyncSettingsAction
{
AlwaysAsk,
Allow,
Deny
}
public enum SettingAsHostAction
{
DontSync,
SyncIcons
}
public class HostSettingsToSync
{
public bool ShowLoots { get; set; }
public bool ShowEnemies { get; set; }
public bool ShowLivePlayers { get; set; }
public bool ShowDeadPlayers { get; set; }
public bool ShowRadarBoosters { get; set; }
public bool ShowTerminalCodes { get; set; }
public HostSettingsToSync()
{
ShowLoots = false;
ShowEnemies = false;
ShowLivePlayers = true;
ShowDeadPlayers = true;
ShowRadarBoosters = true;
ShowTerminalCodes = false;
}
public void Sync()
{
MinimapMod.minimapGUI.showLoots = ShowLoots;
MinimapMod.minimapGUI.showEnemies = ShowEnemies;
MinimapMod.minimapGUI.showLivePlayers = ShowLivePlayers;
MinimapMod.minimapGUI.showDeadPlayers = ShowDeadPlayers;
MinimapMod.minimapGUI.showRadarBoosters = ShowRadarBoosters;
MinimapMod.minimapGUI.showTerminalCodes = ShowTerminalCodes;
}
public bool IsSync()
{
return (
MinimapMod.minimapGUI.showLoots == ShowLoots
&& MinimapMod.minimapGUI.showEnemies == ShowEnemies
&& MinimapMod.minimapGUI.showLivePlayers == ShowLivePlayers
&& MinimapMod.minimapGUI.showDeadPlayers == ShowDeadPlayers
&& MinimapMod.minimapGUI.showRadarBoosters == ShowRadarBoosters
&& MinimapMod.minimapGUI.showTerminalCodes == ShowTerminalCodes
);
}
public static HostSettingsToSync Parse(string data)
{
if (string.IsNullOrEmpty(data))
{
return null;
}
string[] parsedSettings = data.Split(';');
if (parsedSettings.Length != 6)
{
return null;
}
HostSettingsToSync hostSettings = new HostSettingsToSync();
HashSet<string> expectedSettings = new HashSet<string>
{
"loots",
"enemies",
"livePlayers",
"deadPlayers",
"radarBoosters",
"terminalCodes"
};
foreach (string setting in parsedSettings)
{
string[] parsedSetting = setting.Split('=');
if (parsedSetting.Length != 2)
{
return null;
}
string rawSettingKey = parsedSetting[0].Trim();
string rawSettingValue = parsedSetting[1].Trim();
if (!expectedSettings.Remove(rawSettingKey))
{
return null; // Key is either not expected or duplicated
}
bool settingValue;
if (rawSettingValue == "show")
{
settingValue = true;
}
else if (rawSettingValue == "hide")
{
settingValue= false;
}
else
{
settingValue= false;
}
switch (rawSettingKey)
{
case "loots":
hostSettings.ShowLoots = false;
break;
case "enemies":
hostSettings.ShowEnemies = false;
break;
case "livePlayers":
hostSettings.ShowLivePlayers = settingValue;
break;
case "deadPlayers":
hostSettings.ShowDeadPlayers = settingValue;
break;
case "radarBoosters":
hostSettings.ShowRadarBoosters = settingValue;
break;
case "terminalCodes":
hostSettings.ShowTerminalCodes = false;
break;
default:
return null;
}
}
if (expectedSettings.Count > 0)
{
return null;
}
return hostSettings;
}
}
}