Skip to content

Commit

Permalink
Merge pull request #618 from TheTrackerCouncil/auto-map-update-updates
Browse files Browse the repository at this point in the history
Add new automatic map transition behavior options
  • Loading branch information
MattEqualsCoder authored Dec 16, 2024
2 parents 9bfeadc + 799f645 commit 00924ab
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MSURandomizerLibrary.Configs;
using TrackerCouncil.Smz3.Data.Options;
using TrackerCouncil.Smz3.Data.Tracking;
using TrackerCouncil.Smz3.Data.WorldData;
using TrackerCouncil.Smz3.Data.WorldData.Regions;
Expand Down Expand Up @@ -67,9 +68,9 @@ public interface ITrackerGameStateService
/// Updates the region that the player is in
/// </summary>
/// <param name="region">The region the player is in</param>
/// <param name="updateMap">Set to true to update the map for the player to match the region</param>
/// <param name="updateMap">Behavior for updating the map for the player to match the region</param>
/// <param name="resetTime">If the time should be reset if this is the first region update</param>
public void UpdateRegion(Region region, bool updateMap = false, bool resetTime = false);
public void UpdateRegion(Region region, AutoMapUpdateBehavior updateMap = AutoMapUpdateBehavior.Disabled, bool resetTime = false);

/// <summary>
/// Updates the map to display for the user
Expand Down
21 changes: 21 additions & 0 deletions src/TrackerCouncil.Smz3.Data/Options/AutoMapUpdateBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.ComponentModel;

namespace TrackerCouncil.Smz3.Data.Options;

public enum AutoMapUpdateBehavior
{
[Description("Disabled")]
Disabled,

[Description("Update Map When Changing Games")]
UpdateOnGameChange,

[Description("Update Map When Changing Regions")]
UpdateOnRegionChange,

[Description("Update Map When Changing Games or Zelda Regions")]
UpdateOnZeldaRegionChange,

[Description("Update Map When Changing Games or Metroid Regions")]
UpdateOnMetroidRegionChange,
}
4 changes: 3 additions & 1 deletion src/TrackerCouncil.Smz3.Data/Options/GeneralOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public class GeneralOptions : INotifyPropertyChanged
public SnesConnectorSettings SnesConnectorSettings { get; set; } = new();

public bool AutoTrackerChangeMap { get; set; }
public AutoMapUpdateBehavior? AutoMapUpdateBehavior { get; set; } = Options.AutoMapUpdateBehavior.Disabled;

public int UndoExpirationTime { get; set; } = 3;
public double UIScaleFactor { get; set; } = 1;

Expand Down Expand Up @@ -256,7 +258,7 @@ public bool Validate()
ChatGreetingEnabled = EnableChatGreeting,
ChatGreetingTimeLimit = ChatGreetingTimeLimit,
PollCreationEnabled = EnablePollCreation,
AutoTrackerChangeMap = AutoTrackerChangeMap,
AutoMapUpdateBehavior = AutoMapUpdateBehavior ?? Options.AutoMapUpdateBehavior.Disabled,
VoiceFrequency = TrackerVoiceFrequency,
TrackerProfiles = SelectedProfiles,
UndoExpirationTime = UndoExpirationTime,
Expand Down
8 changes: 8 additions & 0 deletions src/TrackerCouncil.Smz3.Data/Options/RandomizerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public static RandomizerOptions Load(string loadPath, string savePath, bool isYa
options.GeneralOptions.MsuTrackDisplayStyle = null;
}

// Update AutoTrackerChangeMap to AutoMapUpdateBehavior
if (options.GeneralOptions.AutoMapUpdateBehavior == null)
{
options.GeneralOptions.AutoMapUpdateBehavior = options.GeneralOptions.AutoTrackerChangeMap
? AutoMapUpdateBehavior.UpdateOnRegionChange
: AutoMapUpdateBehavior.Disabled;
}

return options;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/TrackerCouncil.Smz3.Data/Options/TrackerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public record TrackerOptions
/// <summary>
/// If auto tracker should change maps when changing locations
/// </summary>
public bool AutoTrackerChangeMap { get; set; }
public AutoMapUpdateBehavior AutoMapUpdateBehavior { get; set; }

/// <summary>
/// The frequency in which tracker will say things
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public class OptionsWindowTrackerOptions
[DynamicFormFieldFilePicker(FilePickerType.OpenFile, label: "Current song output path:", dialogText: "Select song output file")]
public string? MsuTrackOutputPath { get; set; } = "";

[DynamicFormFieldCheckBox(checkBoxText: "Auto tracker updates map automatically", groupName: "Bottom")]
public bool AutoTrackerChangeMap { get; set; }
[DynamicFormFieldComboBox(label: "Auto tracker map update behavior")]
public AutoMapUpdateBehavior AutoMapUpdateBehavior { get; set; }

[DynamicFormFieldCheckBox(checkBoxText: "Auto track viewed events", groupName: "Bottom")]
public bool AutoSaveLookAtEvents { get; set; } = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public OptionsWindowViewModel(GeneralOptions options, Dictionary<string, string>
TrackerOptions.SniAddress = options.SnesConnectorSettings.SniAddress;
TrackerOptions.TrackDisplayFormat = options.TrackDisplayFormat;
TrackerOptions.MsuTrackOutputPath = options.MsuTrackOutputPath;
TrackerOptions.AutoTrackerChangeMap = options.AutoTrackerChangeMap;
TrackerOptions.AutoMapUpdateBehavior = options.AutoMapUpdateBehavior ?? AutoMapUpdateBehavior.Disabled;
TrackerOptions.AutoSaveLookAtEvents = options.AutoSaveLookAtEvents;
TrackerOptions.TrackerHintsEnabled = options.TrackerHintsEnabled;
TrackerOptions.TrackerSpoilersEnabled = options.TrackerSpoilersEnabled;
Expand Down Expand Up @@ -103,7 +103,7 @@ public void UpdateOptions(GeneralOptions options)
options.SnesConnectorSettings.SniAddress = TrackerOptions.SniAddress;
options.TrackDisplayFormat = TrackerOptions.TrackDisplayFormat;
options.MsuTrackOutputPath = TrackerOptions.MsuTrackOutputPath;
options.AutoTrackerChangeMap = TrackerOptions.AutoTrackerChangeMap;
options.AutoMapUpdateBehavior = TrackerOptions.AutoMapUpdateBehavior;
options.AutoSaveLookAtEvents = TrackerOptions.AutoSaveLookAtEvents;
options.TrackerHintsEnabled = TrackerOptions.TrackerHintsEnabled;
options.TrackerSpoilersEnabled = TrackerOptions.TrackerSpoilersEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public bool ExecuteCheck(TrackerBase tracker, AutoTrackerMetroidState currentSta
var newRegion = tracker.World.Regions.OfType<SMRegion>().FirstOrDefault(x => x.MemoryRegionId == currentState.CurrentRegion);
if (newRegion != null)
{
tracker.GameStateTracker.UpdateRegion(newRegion, tracker.Options.AutoTrackerChangeMap, startedAtShip);
tracker.GameStateTracker.UpdateRegion(newRegion, tracker.Options.AutoMapUpdateBehavior, startedAtShip);
}
_previousMetroidRegionValue = currentState.CurrentRegion.Value;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public bool ExecuteCheck(TrackerBase trackerBase, AutoTrackerZeldaState currentS
.FirstOrDefault(x => x.StartingRooms.Count != 0 && x.StartingRooms.Contains(currentState.OverworldScreen.Value) && x.IsOverworld);
if (region == null) return false;

trackerBase.GameStateTracker.UpdateRegion(region, trackerBase.Options.AutoTrackerChangeMap);
trackerBase.GameStateTracker.UpdateRegion(region, trackerBase.Options.AutoMapUpdateBehavior);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public bool ExecuteCheck(TrackerBase trackerBase, AutoTrackerZeldaState currentS
}
}

trackerBase.GameStateTracker.UpdateRegion(region, trackerBase.Options.AutoTrackerChangeMap);
trackerBase.GameStateTracker.UpdateRegion(region, trackerBase.Options.AutoMapUpdateBehavior);
_enteredDungeons.Add(region);
return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using MSURandomizerLibrary.Configs;
using TrackerCouncil.Smz3.Abstractions;
using TrackerCouncil.Smz3.Data.Options;
using TrackerCouncil.Smz3.Data.Tracking;
using TrackerCouncil.Smz3.Data.WorldData;
using TrackerCouncil.Smz3.Data.WorldData.Regions;
Expand Down Expand Up @@ -32,7 +33,7 @@ internal class TrackerGameStateService : TrackerService, ITrackerGameStateServic
/// <param name="region">The region the player is in</param>
/// <param name="updateMap">Set to true to update the map for the player to match the region</param>
/// <param name="resetTime">If the time should be reset if this is the first region update</param>
public void UpdateRegion(Region region, bool updateMap = false, bool resetTime = false)
public void UpdateRegion(Region region, AutoMapUpdateBehavior updateMap = AutoMapUpdateBehavior.Disabled, bool resetTime = false)
{
if (region != CurrentRegion)
{
Expand All @@ -46,13 +47,50 @@ public void UpdateRegion(Region region, bool updateMap = false, bool resetTime =
true,
region.Name
);

if (updateMap != AutoMapUpdateBehavior.Disabled && !string.IsNullOrEmpty(region?.MapName))
{
if (updateMap == AutoMapUpdateBehavior.UpdateOnGameChange)
{
if (region is SMRegion && CurrentRegion is not SMRegion)
{
UpdateMap("Metroid Combined");
}
else if (region is Z3Region && CurrentRegion is not Z3Region)
{
UpdateMap("Zelda Combined");
}
}
else if (updateMap == AutoMapUpdateBehavior.UpdateOnRegionChange)
{
UpdateMap(region.MapName);
}
else if (updateMap == AutoMapUpdateBehavior.UpdateOnMetroidRegionChange)
{
if (region is Z3Region && CurrentRegion is not Z3Region)
{
UpdateMap("Zelda Combined");
}
else if (region is SMRegion)
{
UpdateMap(region.MapName);
}
}
else if (updateMap == AutoMapUpdateBehavior.UpdateOnZeldaRegionChange)
{
if (region is SMRegion && CurrentRegion is not SMRegion)
{
UpdateMap("Metroid Combined");
}
else if (region is Z3Region)
{
UpdateMap(region.MapName);
}
}
}
}

CurrentRegion = region;
if (updateMap && !string.IsNullOrEmpty(region?.MapName))
{
UpdateMap(region.MapName);
}
}

/// <summary>
Expand Down

0 comments on commit 00924ab

Please sign in to comment.