Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SekiroTool/Enums/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public enum State
NotLoaded,
GameStart,
AppClosing,
AppStarting,
AppStart,
EventTabActivated,
}
8 changes: 7 additions & 1 deletion SekiroTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ public MainWindow()
ItemViewModel itemViewModel = new ItemViewModel(itemService, _stateService);
EventViewModel eventViewModel =
new EventViewModel(eventService, _stateService, debugDrawService, itemService, _hotkeyManager);
SettingsViewModel settingsViewModel = new SettingsViewModel(settingsService, _stateService, _hotkeyManager);
var activateOnLaunchManager = new ActivateOnLaunchManager();
ActivateOnLaunchViewModel activateOnLaunchViewModel = new ActivateOnLaunchViewModel(playerViewModel,
targetViewModel, eventViewModel, travelViewModel, activateOnLaunchManager, _stateService);
SettingsViewModel settingsViewModel = new SettingsViewModel(settingsService, _stateService, _hotkeyManager,
activateOnLaunchViewModel);

var playerTab = new PlayerTab(playerViewModel);
var travelTab = new TravelTab(travelViewModel);
Expand All @@ -103,6 +107,8 @@ public MainWindow()

settingsViewModel.ApplyStartUpOptions();

_stateService.Publish(State.AppStart);

Closing += MainWindow_Closing;

_gameLoadedTimer = new DispatcherTimer
Expand Down
86 changes: 86 additions & 0 deletions SekiroTool/Utilities/ActivateOnLaunchManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace SekiroTool.Utilities;

public class ActivateOnLaunchManager
{
private readonly Dictionary<string, string> _values = new();

public ActivateOnLaunchManager()
{
Load();
}

public bool GetBool(string actionId)
{
return _values.TryGetValue(actionId, out var v) && bool.TryParse(v, out var b) && b;
}

public void SetBool(string actionId, bool value)
{
_values[actionId] = value.ToString();
Save();
}

public int GetInt(string actionId, int defaultValue = 0)
{
return _values.TryGetValue(actionId, out var v) && int.TryParse(v, out var i) ? i : defaultValue;
}

public void SetInt(string actionId, int value)
{
_values[actionId] = value.ToString();
Save();
}

public double GetDouble(string actionId, double defaultValue = 0)
{
return _values.TryGetValue(actionId, out var v) &&
double.TryParse(v, NumberStyles.Float, CultureInfo.InvariantCulture, out var d)
? d
: defaultValue;
}

public void SetDouble(string actionId, double value)
{
_values[actionId] = value.ToString(CultureInfo.InvariantCulture);
Save();
}

public void Save()
{
try
{
SettingsManager.Default.ActivateOnLaunchActionIds = string.Join(",", _values.Select(kv => $"{kv.Key}:{kv.Value}"));
SettingsManager.Default.Save();
}
catch (Exception ex)
{
Console.WriteLine($@"Error saving activate on launch settings: {ex.Message}");
}
}

public void Load()
{
try
{
_values.Clear();
var raw = SettingsManager.Default.ActivateOnLaunchActionIds;
if (string.IsNullOrEmpty(raw)) return;

foreach (var token in raw.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
var separatorIndex = token.IndexOf(':');
if (separatorIndex <= 0) continue;
_values[token.Substring(0, separatorIndex)] = token.Substring(separatorIndex + 1);
}
}
catch (Exception ex)
{
Console.WriteLine($@"Error loading activate on launch settings: {ex.Message}");
}
}
}
2 changes: 2 additions & 0 deletions SekiroTool/Utilities/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class SettingsManager
public static SettingsManager Default => _default ??= Load();

public string HotkeyActionIds { get; set; } = "";
public bool ActivateOnLaunchEnabled { get; set; }
public string ActivateOnLaunchActionIds { get; set; } = "";
public bool EnableHotkeys { get; set; }
public bool NoLogo { get; set; }
public bool AlwaysOnTop { get; set; }
Expand Down
Loading