From 7cb1dd18f8b2367992cf13a8fa48c9eefd5d9ec0 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 25 May 2024 13:57:22 -0400 Subject: Past connections are now saved --- AnodyneArchipelago/Menu/ArchipelagoSettings.cs | 74 ++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 AnodyneArchipelago/Menu/ArchipelagoSettings.cs (limited to 'AnodyneArchipelago/Menu/ArchipelagoSettings.cs') 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 @@ +using AnodyneSharp.Registry; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; + +namespace AnodyneArchipelago.Menu +{ + internal class ConnectionDetails : IEquatable + { + public string ApServer; + public string ApSlot; + public string ApPassword; + + public override bool Equals(object obj) + { + return this.Equals(obj as ConnectionDetails); + } + + public bool Equals(ConnectionDetails other) + { + return (ApServer == other.ApServer) && (ApSlot == other.ApSlot) && (ApPassword == other.ApPassword); + } + + public override int GetHashCode() + { + return (ApServer, ApSlot, ApPassword).GetHashCode(); + } + } + + internal class ArchipelagoSettings + { + public static JsonSerializerOptions serializerOptions = new JsonSerializerOptions() + { + IncludeFields = true + }; + + public List ConnectionDetails = new(); + + public static string GetFilePath() => string.Format("{0}Saves/ap_settings.dat", GameConstants.SavePath); + + public static ArchipelagoSettings Load() + { + try + { + string s = File.ReadAllText(GetFilePath()); + return JsonSerializer.Deserialize(s, serializerOptions); + } catch (Exception) + { + return null; + } + } + + public void Save() + { + File.WriteAllText(GetFilePath(), JsonSerializer.Serialize(this, serializerOptions)); + } + + public void AddConnection(ConnectionDetails connectionDetails) + { + if (ConnectionDetails.Contains(connectionDetails)) + { + ConnectionDetails.Remove(connectionDetails); + } + + ConnectionDetails.Insert(0, connectionDetails); + + if (ConnectionDetails.Count > 9) + { + ConnectionDetails.RemoveAt(ConnectionDetails.Count - 1); + } + } + } +} -- cgit 1.4.1