diff --git a/SotnRandoTools/src/Constants/Paths.cs b/SotnRandoTools/src/Constants/Paths.cs index 50e0753..0696c7c 100644 --- a/SotnRandoTools/src/Constants/Paths.cs +++ b/SotnRandoTools/src/Constants/Paths.cs @@ -64,6 +64,7 @@ public static class Paths public const string OverlayPath = @"\ExternalTools\SotnRandoTools\TrackerOverlay\"; public const string ChangeLogPath = @"\ExternalTools\SotnRandoTools\ChangeLog.txt"; + public const string PresetPath = "./ExternalTools/SotnRandoTools/Presets/"; public const string CasualPresetPath = "./ExternalTools/SotnRandoTools/Presets/casual.json"; public const string SpeedrunPresetPath = "./ExternalTools/SotnRandoTools/Presets/speedrun.json"; public const string BatMasterPresetPath = "./ExternalTools/SotnRandoTools/Presets/bat-master.json"; diff --git a/SotnRandoTools/src/CoopForm.cs b/SotnRandoTools/src/CoopForm.cs index 29eeb7e..bd30cc1 100644 --- a/SotnRandoTools/src/CoopForm.cs +++ b/SotnRandoTools/src/CoopForm.cs @@ -151,7 +151,10 @@ public void UpdateCoop() private void CoopForm_Load(object sender, EventArgs e) { - this.Location = toolConfig.Coop.Location; + if (SystemInformation.VirtualScreen.Width > toolConfig.Coop.Location.X && SystemInformation.VirtualScreen.Height > toolConfig.Coop.Location.Y) + { + this.Location = toolConfig.Coop.Location; + } this.portNumeric.Value = toolConfig.Coop.DefaultPort; this.targetIp.Text = toolConfig.Coop.DefaultServer; inputService.Polling++; diff --git a/SotnRandoTools/src/RandoTracker/Tracker.cs b/SotnRandoTools/src/RandoTracker/Tracker.cs index edf66da..1976b50 100644 --- a/SotnRandoTools/src/RandoTracker/Tracker.cs +++ b/SotnRandoTools/src/RandoTracker/Tracker.cs @@ -591,8 +591,42 @@ private void InitializeAllLocks() private void LoadLocks(string presetFilePath, bool outOfLogic = false, bool overwriteLocks = false) { - var presetLocations = JObject.Parse(File.ReadAllText(presetFilePath))["lockLocation"]; - foreach (var location in presetLocations) + if (!File.Exists(presetFilePath)) + { + guardedExtension = toolConfig.Tracker.CustomLocationsGuarded; + equipmentExtension = toolConfig.Tracker.CustomLocationsEquipment; + spreadExtension = toolConfig.Tracker.CustomLocationsSpread; + if (equipmentExtension) + { + equipmentExtension = true; + SetEquipmentProgression(); + } + return; + } + + JObject preset = JObject.Parse(File.ReadAllText(presetFilePath)); + string relicLocationsExtension = (preset.GetValue("relicLocationsExtension") ?? "gaurded").ToString(); + JToken? presetLocations = preset["lockLocation"]; + + switch (relicLocationsExtension) + { + case "equipment": + equipmentExtension = true; + SetEquipmentProgression(); + break; + case "spread": + spreadExtension = true; + break; + case "false": + guardedExtension = false; + break; + default: + guardedExtension = true; + break; + } + + + foreach (JObject location in presetLocations) { string name = location["location"].ToString().Replace(" ", String.Empty).ToLower(); var trackerLocation = locations.Where(x => x.Name.Replace(" ", String.Empty).ToLower() == name).FirstOrDefault(); @@ -610,7 +644,7 @@ private void LoadLocks(string presetFilePath, bool outOfLogic = false, bool over } } - foreach (var lockSet in location["locks"]) + foreach (JToken lockSet in location["locks"]) { if (outOfLogic) { @@ -819,48 +853,7 @@ private void GetSeedData() SeedInfo = seedName + "(" + preset + ")"; Console.WriteLine("Randomizer seed information: " + SeedInfo); SaveSeedInfo(SeedInfo); - switch (preset) - { - case "adventure": - equipmentExtension = true; - SetEquipmentProgression(); - break; - case "expedition": - equipmentExtension = true; - SetEquipmentProgression(); - break; - case "glitch": - equipmentExtension = true; - relics[25].Progression = false; - SetEquipmentProgression(); - break; - case "og": - guardedExtension = false; - break; - case "guarded-og": - guardedExtension = true; - break; - case "speedrun": - LoadLocks(Paths.SpeedrunPresetPath); - break; - case "open-casual": - case "bat-master": - LoadLocks(Paths.BatMasterPresetPath, false, true); - spreadExtension = true; - break; - case "custom": - guardedExtension = toolConfig.Tracker.CustomLocationsGuarded; - equipmentExtension = toolConfig.Tracker.CustomLocationsEquipment; - spreadExtension = toolConfig.Tracker.CustomLocationsSpread; - if (equipmentExtension) - { - guardedExtension = true; - SetEquipmentProgression(); - } - break; - default: - break; - } + LoadLocks(Paths.PresetPath + preset + ".json", false, true); PrepareMapLocations(); } diff --git a/SotnRandoTools/src/ToolMainForm.cs b/SotnRandoTools/src/ToolMainForm.cs index 7ba7b73..d05ff5c 100644 --- a/SotnRandoTools/src/ToolMainForm.cs +++ b/SotnRandoTools/src/ToolMainForm.cs @@ -107,7 +107,10 @@ private void InitializeConfig() private void ToolMainForm_Load(object sender, EventArgs e) { - this.Location = toolConfig.Location; + if (SystemInformation.VirtualScreen.Width > toolConfig.Location.X && SystemInformation.VirtualScreen.Height > toolConfig.Location.Y) + { + this.Location = toolConfig.Location; + } aboutPanel = new AboutPanel(); aboutPanel.Location = new Point(0, PanelOffset); diff --git a/SotnRandoTools/src/TrackerForm.cs b/SotnRandoTools/src/TrackerForm.cs index dea87ba..5453ea8 100644 --- a/SotnRandoTools/src/TrackerForm.cs +++ b/SotnRandoTools/src/TrackerForm.cs @@ -54,7 +54,11 @@ private void TrackerForm_Load(object sender, EventArgs e) { this.TopMost = toolConfig.Tracker.AlwaysOnTop; this.Size = new Size(toolConfig.Tracker.Width, toolConfig.Tracker.Height); - this.Location = toolConfig.Tracker.Location; + + if (SystemInformation.VirtualScreen.Width > toolConfig.Tracker.Location.X && SystemInformation.VirtualScreen.Height > toolConfig.Tracker.Location.Y) + { + this.Location = toolConfig.Tracker.Location; + } drawingSurface = new Bitmap(this.Width, this.Height); Graphics internalGraphics = Graphics.FromImage(drawingSurface); @@ -85,8 +89,11 @@ private void TrackerForm_Resize(object sender, EventArgs e) this.formGraphics = new GraphicsAdapter(internalGraphics); } - toolConfig.Tracker.Width = this.Width; - toolConfig.Tracker.Height = this.Height; + if (this.Width <= this.MaximumSize.Width && this.Height <= this.MaximumSize.Height) + { + toolConfig.Tracker.Width = this.Width; + toolConfig.Tracker.Height = this.Height; + } if (tracker is not null && formGraphics is not null) { diff --git a/SotnRandoTools/src/Utils/FileExtensions.cs b/SotnRandoTools/src/Utils/FileExtensions.cs deleted file mode 100644 index d434f2e..0000000 --- a/SotnRandoTools/src/Utils/FileExtensions.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using System.Threading; - -namespace SotnRandoTools.Utils -{ - public static class FileExtensions - { - private const uint retries = 10; - - private static bool WaitForFile(string fullPath, uint retries) - { - if (String.IsNullOrEmpty(fullPath)) throw new ArgumentNullException(nameof(fullPath)); - if (retries == 0 && retries < 100) throw new ArgumentOutOfRangeException(nameof(fullPath)); - - Thread.Sleep(50); - for (int numTries = 0; numTries < retries; numTries++) - { - try - { - IEquatable fs = File.ReadLines(fullPath).FirstOrDefault(); - return true; - } - catch (IOException e) - { - Console.WriteLine(e.Message + "with code: " + e.HResult); - Thread.Sleep(50); - } - } - return false; - } - - public static string GetLastLine(string fullPath) - { - if (String.IsNullOrEmpty(fullPath)) throw new ArgumentNullException(nameof(fullPath)); - - string lastLine = ""; - if (!File.Exists(fullPath)) - { - return ""; - } - if (WaitForFile(fullPath, retries)) - { - lastLine = File.ReadLines(fullPath).LastOrDefault(); - } - return lastLine; - } - - public static string GetText(string fullPath) - { - if (String.IsNullOrEmpty(fullPath)) throw new ArgumentNullException(nameof(fullPath)); - - string text = ""; - if (!File.Exists(fullPath)) - { - return ""; - } - if (WaitForFile(fullPath, retries)) - { - text = File.ReadAllText(fullPath); - } - return text; - } - - public static string[]? GetLines(string fullPath) - { - if (String.IsNullOrEmpty(fullPath)) throw new ArgumentNullException(nameof(fullPath)); - - if (!File.Exists(fullPath)) - { - return null; - } - if (WaitForFile(fullPath, retries)) - { - return File.ReadLines(fullPath).ToArray(); - } - return null; - } - } -}