Skip to content

Commit

Permalink
Check if saved window locations are viable. Check if window size is i…
Browse files Browse the repository at this point in the history
…n-bounds before saving to config. Improve metadata parsing for presets.
  • Loading branch information
TalicZealot committed Jul 24, 2023
1 parent c9eabe7 commit 53a17cf
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 131 deletions.
1 change: 1 addition & 0 deletions SotnRandoTools/src/Constants/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 4 additions & 1 deletion SotnRandoTools/src/CoopForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
83 changes: 38 additions & 45 deletions SotnRandoTools/src/RandoTracker/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
{
Expand Down Expand Up @@ -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();
}

Expand Down
5 changes: 4 additions & 1 deletion SotnRandoTools/src/ToolMainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 10 additions & 3 deletions SotnRandoTools/src/TrackerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
81 changes: 0 additions & 81 deletions SotnRandoTools/src/Utils/FileExtensions.cs

This file was deleted.

0 comments on commit 53a17cf

Please sign in to comment.