using Microsoft.Extensions.Logging; namespace Tiger.Game.Settings; public class SettingsManager : ISettingsManager { private IReadOnlyDictionary _settings; private readonly ISettingsDao _settingsDao; private readonly ILogger _logger; public SettingsManager(ISettingsDao settingsDao, ILogger logger) { _settingsDao = settingsDao; _logger = logger; _settings = new Dictionary(); } public async Task ReloadSettingsAsync() { _settings = await _settingsDao.GetSettingsAsync(); _logger.LogInformation("Loaded {Count} settings", _settings.Count); } public T GetSetting(string key) { if (!_settings.TryGetValue(key, out var value)) throw new KeyNotFoundException($"No setting found with key '{key}'"); if (value is T castedValue) return castedValue; throw new InvalidCastException($"Setting '{key}' is not of type '{typeof(T)}'"); } }