Skip to content

Commit 1a192c2

Browse files
Update to reload configs after downloading
1 parent 0d0d42a commit 1a192c2

File tree

5 files changed

+75
-42
lines changed

5 files changed

+75
-42
lines changed

src/TrackerCouncil.Smz3.Data/Configuration/Configs.cs

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,55 @@ namespace TrackerCouncil.Smz3.Data.Configuration;
1313
/// </summary>
1414
public class Configs
1515
{
16+
private ConfigProvider _configProvider;
17+
private RandomizerOptions _randomizerOptions;
18+
private ILogger<Configs> _logger;
19+
1620
/// <summary>
1721
/// Constructor
1822
/// </summary>
1923
/// <param name="optionsFactory">The tracker options for determining the selected tracker profiles</param>
2024
/// <param name="provider">The config provider for loading configs</param>
2125
/// <param name="logger"></param>
22-
public Configs(OptionsFactory optionsFactory, Smz3.Data.Configuration.ConfigProvider provider, ILogger<Configs> logger)
26+
public Configs(OptionsFactory optionsFactory, ConfigProvider provider, ILogger<Configs> logger)
27+
{
28+
_configProvider = provider;
29+
_randomizerOptions = optionsFactory.Create();
30+
_logger = logger;
31+
LoadConfigs();
32+
}
33+
34+
public void LoadConfigs()
2335
{
24-
var options = optionsFactory.Create();
25-
var profiles = options.GeneralOptions.SelectedProfiles.NonNull().Where(x => x != "Default").ToArray();
26-
var moods = provider.GetAvailableMoods(profiles);
36+
var profiles = _randomizerOptions.GeneralOptions.SelectedProfiles.NonNull().Where(x => x != "Default").ToArray();
37+
var moods = _configProvider.GetAvailableMoods(profiles);
2738
CurrentMood = moods.Random(Random.Shared);
28-
logger.LogInformation("Tracker is feeling {Mood} today", CurrentMood);
29-
30-
Bosses = provider.GetBossConfig(profiles, CurrentMood);
31-
Dungeons = provider.GetDungeonConfig(profiles, CurrentMood);
32-
Items = provider.GetItemConfig(profiles, CurrentMood);
33-
Locations = provider.GetLocationConfig(profiles, CurrentMood);
34-
Regions = provider.GetRegionConfig(profiles, CurrentMood);
35-
Requests = provider.GetRequestConfig(profiles, CurrentMood);
36-
Responses = provider.GetResponseConfig(profiles, CurrentMood);
37-
Rooms = provider.GetRoomConfig(profiles, CurrentMood);
38-
Rewards = provider.GetRewardConfig(profiles, CurrentMood);
39-
UILayouts = provider.GetUIConfig(profiles, CurrentMood);
40-
GameLines = provider.GetGameConfig(profiles, CurrentMood);
41-
MsuConfig = provider.GetMsuConfig(profiles, CurrentMood);
42-
HintTileConfig = provider.GetHintTileConfig(profiles, CurrentMood);
39+
_logger.LogInformation("Tracker is feeling {Mood} today", CurrentMood);
40+
41+
Bosses = _configProvider.GetBossConfig(profiles, CurrentMood);
42+
Dungeons = _configProvider.GetDungeonConfig(profiles, CurrentMood);
43+
Items = _configProvider.GetItemConfig(profiles, CurrentMood);
44+
Locations = _configProvider.GetLocationConfig(profiles, CurrentMood);
45+
Regions = _configProvider.GetRegionConfig(profiles, CurrentMood);
46+
Requests = _configProvider.GetRequestConfig(profiles, CurrentMood);
47+
Responses = _configProvider.GetResponseConfig(profiles, CurrentMood);
48+
Rooms = _configProvider.GetRoomConfig(profiles, CurrentMood);
49+
Rewards = _configProvider.GetRewardConfig(profiles, CurrentMood);
50+
UILayouts = _configProvider.GetUIConfig(profiles, CurrentMood);
51+
GameLines = _configProvider.GetGameConfig(profiles, CurrentMood);
52+
MsuConfig = _configProvider.GetMsuConfig(profiles, CurrentMood);
53+
HintTileConfig = _configProvider.GetHintTileConfig(profiles, CurrentMood);
4354
}
4455

4556
/// <summary>
4657
/// Gets the current mood.
4758
/// </summary>
48-
public string? CurrentMood { get; }
59+
public string? CurrentMood { get; private set; }
4960

5061
/// <summary>
5162
/// Gets a collection of trackable items.
5263
/// </summary>
53-
public ItemConfig Items { get; }
64+
public ItemConfig Items { get; private set; } = null!;
5465

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

90101
/// <summary>
91102
/// Gets a collection of basic requests and responses.
92103
/// </summary>
93-
public RequestConfig Requests { get; }
104+
public RequestConfig Requests { get; private set; } = null!;
94105

95106
/// <summary>
96107
/// Gets a collection of extra information about regions.
97108
/// </summary>
98-
public RegionConfig Regions { get; }
109+
public RegionConfig Regions { get; private set; } = null!;
99110

100111
/// <summary>
101112
/// Gets a collection of extra information about dungeons.
102113
/// </summary>
103-
public DungeonConfig Dungeons { get; }
114+
public DungeonConfig Dungeons { get; private set; } = null!;
104115

105116
/// <summary>
106117
/// Gets a collection of bosses.
107118
/// </summary>
108-
public BossConfig Bosses { get; }
119+
public BossConfig Bosses { get; private set; } = null!;
109120

110121
/// <summary>
111122
/// Gets a collection of extra information about rooms.
112123
/// </summary>
113-
public RoomConfig Rooms { get; }
124+
public RoomConfig Rooms { get; private set; } = null!;
114125

115126
/// <summary>
116127
/// Gets a collection of extra information about locations.
117128
/// </summary>
118-
public LocationConfig Locations { get; }
129+
public LocationConfig Locations { get; private set; } = null!;
119130

120131
/// <summary>
121132
/// Gets a collection of extra information about rewards
122133
/// </summary>
123-
public RewardConfig Rewards { get; }
134+
public RewardConfig Rewards { get; private set; } = null!;
124135

125136
/// <summary>
126137
/// Gets a collection of available UI layouts
127138
/// </summary>
128-
public UIConfig UILayouts { get; }
139+
public UIConfig UILayouts { get; private set; } = null!;
129140

130141
/// <summary>
131142
/// Gets the in game lines
132143
/// </summary>
133-
public GameLinesConfig GameLines { get; }
144+
public GameLinesConfig GameLines { get; private set; } = null!;
134145

135146
/// <summary>
136147
/// Gets the msu config
137148
/// </summary>
138-
public MsuConfig MsuConfig { get; }
149+
public MsuConfig MsuConfig { get; private set; } = null!;
139150

140151
/// <summary>
141152
/// Gets the hint tile config
142153
/// </summary>
143-
public HintTileConfig HintTileConfig { get; }
154+
public HintTileConfig HintTileConfig { get; private set; } = null!;
144155
}

src/TrackerCouncil.Smz3.Data/Services/GitHubConfigDownloaderService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,18 @@ public async Task<bool> DownloadFromSourceAsync (ConfigSource configSource)
9999
return true;
100100
}
101101

102-
public void InstallDefaultConfigFolder()
102+
public bool InstallDefaultConfigFolder()
103103
{
104104
var source = Path.Combine(AppContext.BaseDirectory, "Configs");
105105
if (!Directory.Exists(source))
106106
{
107-
return;
107+
return false;
108108
}
109109

110110
CopyFolder(source, _targetDirectory);
111111
Directory.Delete(source, true);
112112
_logger.LogInformation("Copied default config folder");
113+
return true;
113114
}
114115

115116
private async Task<string?> DownloadFileAsync(GitHubReleaseAsset asset)

src/TrackerCouncil.Smz3.Data/Services/IGitHubConfigDownloaderService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ public interface IGitHubConfigDownloaderService
77
{
88
public Task<bool> DownloadFromSourceAsync(ConfigSource configSource);
99

10-
public void InstallDefaultConfigFolder();
10+
public bool InstallDefaultConfigFolder();
1111
}

src/TrackerCouncil.Smz3.Data/Services/OptionsWindowService.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading.Tasks;
77
using Microsoft.Extensions.Logging;
88
using TrackerCouncil.Smz3.Chat.Integration;
9+
using TrackerCouncil.Smz3.Data.Configuration;
910
using TrackerCouncil.Smz3.Data.Options;
1011
using TrackerCouncil.Smz3.Data.ViewModels;
1112
using ConfigProvider = TrackerCouncil.Smz3.Data.Configuration.ConfigProvider;
@@ -25,7 +26,8 @@ public class OptionsWindowService(
2526
ILogger<OptionsWindowService> logger,
2627
IGitHubConfigDownloaderService gitHubConfigDownloaderService,
2728
IGitHubFileSynchronizerService gitHubFileSynchronizerService,
28-
TrackerSpriteService trackerSpriteService)
29+
TrackerSpriteService trackerSpriteService,
30+
Configs configs)
2931
{
3032
private Dictionary<string, string> _availableInputDevices = new() { { "Default", "Default" } };
3133
private OptionsWindowViewModel _model = new();
@@ -196,7 +198,11 @@ private async Task UpdateConfigsAsync()
196198
configSource = new ConfigSource() { Owner = "TheTrackerCouncil", Repo = "SMZ3CasConfigs" };
197199
options.GeneralOptions.ConfigSources.Add(configSource);
198200
}
199-
await gitHubConfigDownloaderService.DownloadFromSourceAsync(configSource);
201+
202+
if (await gitHubConfigDownloaderService.DownloadFromSourceAsync(configSource))
203+
{
204+
configs.LoadConfigs();
205+
}
200206
}
201207

202208
private async Task UpdateSpritesAsync()

src/TrackerCouncil.Smz3.UI/Services/MainWindowService.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Microsoft.Extensions.Logging;
1414
using TrackerCouncil.Smz3.Chat.Integration;
1515
using TrackerCouncil.Smz3.Data;
16+
using TrackerCouncil.Smz3.Data.Configuration;
1617
using TrackerCouncil.Smz3.Data.Options;
1718
using TrackerCouncil.Smz3.Data.Services;
1819
using TrackerCouncil.Smz3.UI.ViewModels;
@@ -28,7 +29,8 @@ public class MainWindowService(
2829
IGitHubConfigDownloaderService gitHubConfigDownloaderService,
2930
IGitHubFileSynchronizerService gitHubFileSynchronizerService,
3031
SpriteService spriteService,
31-
TrackerSpriteService trackerSpriteService) : ControlService
32+
TrackerSpriteService trackerSpriteService,
33+
Configs configs) : ControlService
3234
{
3335
private MainWindowViewModel _model = new();
3436
private MainWindow _window = null!;
@@ -89,11 +91,15 @@ public async Task<bool> ValidateTwitchToken()
8991

9092
public async Task DownloadConfigsAsync()
9193
{
92-
gitHubConfigDownloaderService.InstallDefaultConfigFolder();
94+
var configsUpdated = gitHubConfigDownloaderService.InstallDefaultConfigFolder();
9395

9496
if (string.IsNullOrEmpty(_options.GeneralOptions.Z3RomPath) ||
9597
!_options.GeneralOptions.DownloadConfigsOnStartup)
9698
{
99+
if (configsUpdated)
100+
{
101+
configs.LoadConfigs();
102+
}
97103
return;
98104
}
99105

@@ -103,8 +109,17 @@ public async Task DownloadConfigsAsync()
103109
configSource = new ConfigSource() { Owner = "TheTrackerCouncil", Repo = "SMZ3CasConfigs" };
104110
_options.GeneralOptions.ConfigSources.Add(configSource);
105111
}
106-
await gitHubConfigDownloaderService.DownloadFromSourceAsync(configSource);
107-
_options.Save();
112+
113+
if (await gitHubConfigDownloaderService.DownloadFromSourceAsync(configSource))
114+
{
115+
configsUpdated = true;
116+
}
117+
118+
if (configsUpdated)
119+
{
120+
_options.Save();
121+
configs.LoadConfigs();
122+
}
108123
}
109124

110125
public async Task DownloadSpritesAsync()

0 commit comments

Comments
 (0)