about summary refs log tree commit diff stats
path: root/AnodyneArchipelago/Menu/ArchipelagoSettings.cs
diff options
context:
space:
mode:
Diffstat (limited to 'AnodyneArchipelago/Menu/ArchipelagoSettings.cs')
-rw-r--r--AnodyneArchipelago/Menu/ArchipelagoSettings.cs74
1 files changed, 74 insertions, 0 deletions
diff --git a/AnodyneArchipelago/Menu/ArchipelagoSettings.cs b/AnodyneArchipelago/Menu/ArchipelagoSettings.cs new file mode 100644 index 0000000..eff3ddf --- /dev/null +++ b/AnodyneArchipelago/Menu/ArchipelagoSettings.cs
@@ -0,0 +1,74 @@
1using AnodyneSharp.Registry;
2using System;
3using System.Collections.Generic;
4using System.IO;
5using System.Text.Json;
6
7namespace AnodyneArchipelago.Menu
8{
9 internal class ConnectionDetails : IEquatable<ConnectionDetails>
10 {
11 public string ApServer;
12 public string ApSlot;
13 public string ApPassword;
14
15 public override bool Equals(object obj)
16 {
17 return this.Equals(obj as ConnectionDetails);
18 }
19
20 public bool Equals(ConnectionDetails other)
21 {
22 return (ApServer == other.ApServer) && (ApSlot == other.ApSlot) && (ApPassword == other.ApPassword);
23 }
24
25 public override int GetHashCode()
26 {
27 return (ApServer, ApSlot, ApPassword).GetHashCode();
28 }
29 }
30
31 internal class ArchipelagoSettings
32 {
33 public static JsonSerializerOptions serializerOptions = new JsonSerializerOptions()
34 {
35 IncludeFields = true
36 };
37
38 public List<ConnectionDetails> ConnectionDetails = new();
39
40 public static string GetFilePath() => string.Format("{0}Saves/ap_settings.dat", GameConstants.SavePath);
41
42 public static ArchipelagoSettings Load()
43 {
44 try
45 {
46 string s = File.ReadAllText(GetFilePath());
47 return JsonSerializer.Deserialize<ArchipelagoSettings>(s, serializerOptions);
48 } catch (Exception)
49 {
50 return null;
51 }
52 }
53
54 public void Save()
55 {
56 File.WriteAllText(GetFilePath(), JsonSerializer.Serialize(this, serializerOptions));
57 }
58
59 public void AddConnection(ConnectionDetails connectionDetails)
60 {
61 if (ConnectionDetails.Contains(connectionDetails))
62 {
63 ConnectionDetails.Remove(connectionDetails);
64 }
65
66 ConnectionDetails.Insert(0, connectionDetails);
67
68 if (ConnectionDetails.Count > 9)
69 {
70 ConnectionDetails.RemoveAt(ConnectionDetails.Count - 1);
71 }
72 }
73 }
74}