about summary refs log tree commit diff stats
path: root/AnodyneArchipelago
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-05-25 13:57:22 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2024-05-25 13:57:22 -0400
commit7cb1dd18f8b2367992cf13a8fa48c9eefd5d9ec0 (patch)
tree3b12dad780c0bfc0d0d70ceaaa864d97bf582662 /AnodyneArchipelago
parentfc2e21e429de7906652142f945e2105ab828dbe6 (diff)
downloadanodyne-archipelago-7cb1dd18f8b2367992cf13a8fa48c9eefd5d9ec0.tar.gz
anodyne-archipelago-7cb1dd18f8b2367992cf13a8fa48c9eefd5d9ec0.tar.bz2
anodyne-archipelago-7cb1dd18f8b2367992cf13a8fa48c9eefd5d9ec0.zip
Past connections are now saved
Diffstat (limited to 'AnodyneArchipelago')
-rw-r--r--AnodyneArchipelago/AnodyneArchipelago.csproj9
-rw-r--r--AnodyneArchipelago/Menu/ArchipelagoSettings.cs74
-rw-r--r--AnodyneArchipelago/Menu/MenuState.cs68
3 files changed, 149 insertions, 2 deletions
diff --git a/AnodyneArchipelago/AnodyneArchipelago.csproj b/AnodyneArchipelago/AnodyneArchipelago.csproj index a5780a0..a750332 100644 --- a/AnodyneArchipelago/AnodyneArchipelago.csproj +++ b/AnodyneArchipelago/AnodyneArchipelago.csproj
@@ -38,5 +38,14 @@
38 <Reference Include="SemanticVersioning"> 38 <Reference Include="SemanticVersioning">
39 <HintPath>..\..\BepInEx\bin\NET.Framework\net462\SemanticVersioning.dll</HintPath> 39 <HintPath>..\..\BepInEx\bin\NET.Framework\net462\SemanticVersioning.dll</HintPath>
40 </Reference> 40 </Reference>
41 <Reference Include="System.Memory">
42 <HintPath>..\..\BepInEx\bin\NET.Framework\net462\System.Memory.dll</HintPath>
43 </Reference>
44 <Reference Include="System.Text.Json">
45 <HintPath>..\..\BepInEx\bin\NET.Framework\net462\System.Text.Json.dll</HintPath>
46 </Reference>
47 <Reference Include="System.ValueTuple">
48 <HintPath>..\..\BepInEx\bin\NET.Framework\net462\System.ValueTuple.dll</HintPath>
49 </Reference>
41 </ItemGroup> 50 </ItemGroup>
42</Project> 51</Project>
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}
diff --git a/AnodyneArchipelago/Menu/MenuState.cs b/AnodyneArchipelago/Menu/MenuState.cs index 898eb94..59a4fdf 100644 --- a/AnodyneArchipelago/Menu/MenuState.cs +++ b/AnodyneArchipelago/Menu/MenuState.cs
@@ -31,6 +31,9 @@ namespace AnodyneArchipelago.Menu
31 private string _apSlot = ""; 31 private string _apSlot = "";
32 private string _apPassword = ""; 32 private string _apPassword = "";
33 33
34 private ArchipelagoSettings _archipelagoSettings;
35 private int _curPage;
36
34 private int _selectorIndex = 0; 37 private int _selectorIndex = 0;
35 38
36 private bool _fadingOut = false; 39 private bool _fadingOut = false;
@@ -44,6 +47,12 @@ namespace AnodyneArchipelago.Menu
44 Plugin.ArchipelagoManager = null; 47 Plugin.ArchipelagoManager = null;
45 } 48 }
46 49
50 _archipelagoSettings = ArchipelagoSettings.Load();
51 if (_archipelagoSettings == null)
52 {
53 _archipelagoSettings = new();
54 }
55
47 _selector = new(); 56 _selector = new();
48 _selector.Play("enabledRight"); 57 _selector.Play("enabledRight");
49 58
@@ -59,12 +68,19 @@ namespace AnodyneArchipelago.Menu
59 _settingsLabel = new(new Vector2(60f, 131f), false, $"Config", new Color(116, 140, 144)); 68 _settingsLabel = new(new Vector2(60f, 131f), false, $"Config", new Color(116, 140, 144));
60 _quitLabel = new(new Vector2(60f, 147f), false, $"Quit", new Color(116, 140, 144)); 69 _quitLabel = new(new Vector2(60f, 147f), false, $"Quit", new Color(116, 140, 144));
61 70
62 _connectionSwitcher = new(new Vector2(60f, 95f), 32f, 0, true, new string[1] { "1/1" }); 71 string[] selectorValues = new string[_archipelagoSettings.ConnectionDetails.Count + 1];
72 for (int i= 0; i < selectorValues.Length; i++)
73 {
74 selectorValues[i] = $"{i+1}/{selectorValues.Length}";
75 }
76
77 _connectionSwitcher = new(new Vector2(60f, 95f), 32f, 0, true, selectorValues);
63 _connectionSwitcher.noConfirm = true; 78 _connectionSwitcher.noConfirm = true;
64 _connectionSwitcher.noLoop = true; 79 _connectionSwitcher.noLoop = true;
65 _connectionSwitcher.ValueChangedEvent = PageValueChanged; 80 _connectionSwitcher.ValueChangedEvent = PageValueChanged;
66 81
67 SetCursorPosition(0); 82 SetCursorPosition(0);
83 SetPage(_archipelagoSettings.ConnectionDetails.Count == 0 ? 0 : 1);
68 UpdateLabels(); 84 UpdateLabels();
69 } 85 }
70 86
@@ -249,15 +265,63 @@ namespace AnodyneArchipelago.Menu
249 break; 265 break;
250 } 266 }
251 } 267 }
268 else if (KeyInput.JustPressedRebindableKey(KeyFunctions.Left))
269 {
270 if (_selectorIndex < 3 && _curPage > 0)
271 {
272 SoundManager.PlaySoundEffect("menu_move");
273
274 SetPage(_curPage - 1);
275 }
276 }
277 else if (KeyInput.JustPressedRebindableKey(KeyFunctions.Right))
278 {
279 if (_selectorIndex < 3 && _curPage < _archipelagoSettings.ConnectionDetails.Count)
280 {
281 SoundManager.PlaySoundEffect("menu_move");
282
283 SetPage(_curPage + 1);
284 }
285 }
252 } 286 }
253 287
254 private void PageValueChanged(string value, int index) 288 private void SetPage(int index)
255 { 289 {
290 _curPage = index;
291
292 if (index == 0)
293 {
294 _apServer = "";
295 _apSlot = "";
296 _apPassword = "";
297 }
298 else
299 {
300 ConnectionDetails details = _archipelagoSettings.ConnectionDetails[index - 1];
301 _apServer = details.ApServer;
302 _apSlot = details.ApSlot;
303 _apPassword = details.ApPassword;
304 }
256 305
306 _connectionSwitcher.SetValue(index);
307 UpdateLabels();
308 }
309
310 private void PageValueChanged(string value, int index)
311 {
312 SetPage(index);
257 } 313 }
258 314
259 private void OnConnected(ArchipelagoManager archipelagoManager) 315 private void OnConnected(ArchipelagoManager archipelagoManager)
260 { 316 {
317 _archipelagoSettings.AddConnection(new()
318 {
319 ApServer = _apServer,
320 ApSlot = _apSlot,
321 ApPassword = _apPassword
322 });
323 _archipelagoSettings.Save();
324
261 Plugin.ArchipelagoManager = archipelagoManager; 325 Plugin.ArchipelagoManager = archipelagoManager;
262 326
263 GlobalState.Save saveFile = GlobalState.Save.GetSave(string.Format("{0}Saves/Save_zzAP{1}_{2}.dat", GameConstants.SavePath, Plugin.ArchipelagoManager.GetSeed(), Plugin.ArchipelagoManager.GetPlayer())); 327 GlobalState.Save saveFile = GlobalState.Save.GetSave(string.Format("{0}Saves/Save_zzAP{1}_{2}.dat", GameConstants.SavePath, Plugin.ArchipelagoManager.GetSeed(), Plugin.ArchipelagoManager.GetPlayer()));