Skip to content
Merged
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
77 changes: 44 additions & 33 deletions src/TrackerCouncil.Smz3.Data/Configuration/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,55 @@ namespace TrackerCouncil.Smz3.Data.Configuration;
/// </summary>
public class Configs
{
private ConfigProvider _configProvider;
private RandomizerOptions _randomizerOptions;
private ILogger<Configs> _logger;

/// <summary>
/// Constructor
/// </summary>
/// <param name="optionsFactory">The tracker options for determining the selected tracker profiles</param>
/// <param name="provider">The config provider for loading configs</param>
/// <param name="logger"></param>
public Configs(OptionsFactory optionsFactory, Smz3.Data.Configuration.ConfigProvider provider, ILogger<Configs> logger)
public Configs(OptionsFactory optionsFactory, ConfigProvider provider, ILogger<Configs> logger)
{
_configProvider = provider;
_randomizerOptions = optionsFactory.Create();
_logger = logger;
LoadConfigs();
}

public void LoadConfigs()
{
var options = optionsFactory.Create();
var profiles = options.GeneralOptions.SelectedProfiles.NonNull().Where(x => x != "Default").ToArray();
var moods = provider.GetAvailableMoods(profiles);
var profiles = _randomizerOptions.GeneralOptions.SelectedProfiles.NonNull().Where(x => x != "Default").ToArray();
var moods = _configProvider.GetAvailableMoods(profiles);
CurrentMood = moods.Random(Random.Shared);
logger.LogInformation("Tracker is feeling {Mood} today", CurrentMood);

Bosses = provider.GetBossConfig(profiles, CurrentMood);
Dungeons = provider.GetDungeonConfig(profiles, CurrentMood);
Items = provider.GetItemConfig(profiles, CurrentMood);
Locations = provider.GetLocationConfig(profiles, CurrentMood);
Regions = provider.GetRegionConfig(profiles, CurrentMood);
Requests = provider.GetRequestConfig(profiles, CurrentMood);
Responses = provider.GetResponseConfig(profiles, CurrentMood);
Rooms = provider.GetRoomConfig(profiles, CurrentMood);
Rewards = provider.GetRewardConfig(profiles, CurrentMood);
UILayouts = provider.GetUIConfig(profiles, CurrentMood);
GameLines = provider.GetGameConfig(profiles, CurrentMood);
MsuConfig = provider.GetMsuConfig(profiles, CurrentMood);
HintTileConfig = provider.GetHintTileConfig(profiles, CurrentMood);
_logger.LogInformation("Tracker is feeling {Mood} today", CurrentMood);

Bosses = _configProvider.GetBossConfig(profiles, CurrentMood);
Dungeons = _configProvider.GetDungeonConfig(profiles, CurrentMood);
Items = _configProvider.GetItemConfig(profiles, CurrentMood);
Locations = _configProvider.GetLocationConfig(profiles, CurrentMood);
Regions = _configProvider.GetRegionConfig(profiles, CurrentMood);
Requests = _configProvider.GetRequestConfig(profiles, CurrentMood);
Responses = _configProvider.GetResponseConfig(profiles, CurrentMood);
Rooms = _configProvider.GetRoomConfig(profiles, CurrentMood);
Rewards = _configProvider.GetRewardConfig(profiles, CurrentMood);
UILayouts = _configProvider.GetUIConfig(profiles, CurrentMood);
GameLines = _configProvider.GetGameConfig(profiles, CurrentMood);
MsuConfig = _configProvider.GetMsuConfig(profiles, CurrentMood);
HintTileConfig = _configProvider.GetHintTileConfig(profiles, CurrentMood);
}

/// <summary>
/// Gets the current mood.
/// </summary>
public string? CurrentMood { get; }
public string? CurrentMood { get; private set; }

/// <summary>
/// Gets a collection of trackable items.
/// </summary>
public ItemConfig Items { get; }
public ItemConfig Items { get; private set; } = null!;

/// <summary>
/// Gets the peg world peg configuration. This will be moved to UI
Expand Down Expand Up @@ -85,60 +96,60 @@ public Configs(OptionsFactory optionsFactory, Smz3.Data.Configuration.ConfigProv
/// <summary>
/// Gets a collection of configured responses.
/// </summary>
public ResponseConfig Responses { get; }
public ResponseConfig Responses { get; private set; } = null!;

/// <summary>
/// Gets a collection of basic requests and responses.
/// </summary>
public RequestConfig Requests { get; }
public RequestConfig Requests { get; private set; } = null!;

/// <summary>
/// Gets a collection of extra information about regions.
/// </summary>
public RegionConfig Regions { get; }
public RegionConfig Regions { get; private set; } = null!;

/// <summary>
/// Gets a collection of extra information about dungeons.
/// </summary>
public DungeonConfig Dungeons { get; }
public DungeonConfig Dungeons { get; private set; } = null!;

/// <summary>
/// Gets a collection of bosses.
/// </summary>
public BossConfig Bosses { get; }
public BossConfig Bosses { get; private set; } = null!;

/// <summary>
/// Gets a collection of extra information about rooms.
/// </summary>
public RoomConfig Rooms { get; }
public RoomConfig Rooms { get; private set; } = null!;

/// <summary>
/// Gets a collection of extra information about locations.
/// </summary>
public LocationConfig Locations { get; }
public LocationConfig Locations { get; private set; } = null!;

/// <summary>
/// Gets a collection of extra information about rewards
/// </summary>
public RewardConfig Rewards { get; }
public RewardConfig Rewards { get; private set; } = null!;

/// <summary>
/// Gets a collection of available UI layouts
/// </summary>
public UIConfig UILayouts { get; }
public UIConfig UILayouts { get; private set; } = null!;

/// <summary>
/// Gets the in game lines
/// </summary>
public GameLinesConfig GameLines { get; }
public GameLinesConfig GameLines { get; private set; } = null!;

/// <summary>
/// Gets the msu config
/// </summary>
public MsuConfig MsuConfig { get; }
public MsuConfig MsuConfig { get; private set; } = null!;

/// <summary>
/// Gets the hint tile config
/// </summary>
public HintTileConfig HintTileConfig { get; }
public HintTileConfig HintTileConfig { get; private set; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,18 @@ public async Task<bool> DownloadFromSourceAsync (ConfigSource configSource)
return true;
}

public void InstallDefaultConfigFolder()
public bool InstallDefaultConfigFolder()
{
var source = Path.Combine(AppContext.BaseDirectory, "Configs");
if (!Directory.Exists(source))
{
return;
return false;
}

CopyFolder(source, _targetDirectory);
Directory.Delete(source, true);
_logger.LogInformation("Copied default config folder");
return true;
}

private async Task<string?> DownloadFileAsync(GitHubReleaseAsset asset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public interface IGitHubConfigDownloaderService
{
public Task<bool> DownloadFromSourceAsync(ConfigSource configSource);

public void InstallDefaultConfigFolder();
public bool InstallDefaultConfigFolder();
}
10 changes: 8 additions & 2 deletions src/TrackerCouncil.Smz3.Data/Services/OptionsWindowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using TrackerCouncil.Smz3.Chat.Integration;
using TrackerCouncil.Smz3.Data.Configuration;
using TrackerCouncil.Smz3.Data.Options;
using TrackerCouncil.Smz3.Data.ViewModels;
using ConfigProvider = TrackerCouncil.Smz3.Data.Configuration.ConfigProvider;
Expand All @@ -25,7 +26,8 @@ public class OptionsWindowService(
ILogger<OptionsWindowService> logger,
IGitHubConfigDownloaderService gitHubConfigDownloaderService,
IGitHubFileSynchronizerService gitHubFileSynchronizerService,
TrackerSpriteService trackerSpriteService)
TrackerSpriteService trackerSpriteService,
Configs configs)
{
private Dictionary<string, string> _availableInputDevices = new() { { "Default", "Default" } };
private OptionsWindowViewModel _model = new();
Expand Down Expand Up @@ -196,7 +198,11 @@ private async Task UpdateConfigsAsync()
configSource = new ConfigSource() { Owner = "TheTrackerCouncil", Repo = "SMZ3CasConfigs" };
options.GeneralOptions.ConfigSources.Add(configSource);
}
await gitHubConfigDownloaderService.DownloadFromSourceAsync(configSource);

if (await gitHubConfigDownloaderService.DownloadFromSourceAsync(configSource))
{
configs.LoadConfigs();
}
}

private async Task UpdateSpritesAsync()
Expand Down
23 changes: 19 additions & 4 deletions src/TrackerCouncil.Smz3.UI/Services/MainWindowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.Extensions.Logging;
using TrackerCouncil.Smz3.Chat.Integration;
using TrackerCouncil.Smz3.Data;
using TrackerCouncil.Smz3.Data.Configuration;
using TrackerCouncil.Smz3.Data.Options;
using TrackerCouncil.Smz3.Data.Services;
using TrackerCouncil.Smz3.UI.ViewModels;
Expand All @@ -28,7 +29,8 @@ public class MainWindowService(
IGitHubConfigDownloaderService gitHubConfigDownloaderService,
IGitHubFileSynchronizerService gitHubFileSynchronizerService,
SpriteService spriteService,
TrackerSpriteService trackerSpriteService) : ControlService
TrackerSpriteService trackerSpriteService,
Configs configs) : ControlService
{
private MainWindowViewModel _model = new();
private MainWindow _window = null!;
Expand Down Expand Up @@ -89,11 +91,15 @@ public async Task<bool> ValidateTwitchToken()

public async Task DownloadConfigsAsync()
{
gitHubConfigDownloaderService.InstallDefaultConfigFolder();
var configsUpdated = gitHubConfigDownloaderService.InstallDefaultConfigFolder();

if (string.IsNullOrEmpty(_options.GeneralOptions.Z3RomPath) ||
!_options.GeneralOptions.DownloadConfigsOnStartup)
{
if (configsUpdated)
{
configs.LoadConfigs();
}
return;
}

Expand All @@ -103,8 +109,17 @@ public async Task DownloadConfigsAsync()
configSource = new ConfigSource() { Owner = "TheTrackerCouncil", Repo = "SMZ3CasConfigs" };
_options.GeneralOptions.ConfigSources.Add(configSource);
}
await gitHubConfigDownloaderService.DownloadFromSourceAsync(configSource);
_options.Save();

if (await gitHubConfigDownloaderService.DownloadFromSourceAsync(configSource))
{
configsUpdated = true;
}

if (configsUpdated)
{
_options.Save();
configs.LoadConfigs();
}
}

public async Task DownloadSpritesAsync()
Expand Down
Loading