UI - Moved color scheme code away from tray VM

UI - Cleaned up settings page code
Core - Changed default framerate to 30
This commit is contained in:
Robert committed 2021-09-18 20:40:57 +02:00
1 parent da123e2fe2
commit ef4e5b4c3b
14 files changed
+504 -463

No files matched your search

@@ -11,18 +11,14 @@ namespace Artemis.Core
/// Represents a setting tied to a plugin of type <typeparamref name="T" />
/// </summary>
/// <typeparam name="T">The value type of the setting</typeparam>
public class PluginSetting<T> : CorePropertyChanged
public class PluginSetting<T> : CorePropertyChanged, IPluginSetting
{
// TODO: Why? Should have included that...
// ReSharper disable once NotAccessedField.Local
private readonly Plugin _plugin;
private readonly IPluginRepository _pluginRepository;
private readonly PluginSettingEntity _pluginSettingEntity;
private T _value;
internal PluginSetting(Plugin plugin, IPluginRepository pluginRepository, PluginSettingEntity pluginSettingEntity)
internal PluginSetting(IPluginRepository pluginRepository, PluginSettingEntity pluginSettingEntity)
{
_plugin = plugin;
_pluginRepository = pluginRepository;
_pluginSettingEntity = pluginSettingEntity;
@@ -37,9 +33,7 @@ namespace Artemis.Core
}
}
/// <summary>
/// The name of the setting, unique to this plugin
/// </summary>
/// <inheritdoc />
public string Name { get; }
/// <summary>
@@ -63,28 +57,19 @@ namespace Artemis.Core
}
}
/// <summary>
/// Determines whether the setting has been changed
/// </summary>
/// <inheritdoc />
public bool HasChanged => CoreJson.SerializeObject(Value) != _pluginSettingEntity.Value;
/// <summary>
/// Gets or sets whether changes must automatically be saved
/// <para>Note: When set to <c>true</c> <see cref="HasChanged" /> is always <c>false</c></para>
/// </summary>
/// <inheritdoc />
public bool AutoSave { get; set; }
/// <summary>
/// Resets the setting to the last saved value
/// </summary>
/// <inheritdoc />
public void RejectChanges()
{
Value = CoreJson.DeserializeObject<T>(_pluginSettingEntity.Value);
}
/// <summary>
/// Saves the setting
/// </summary>
/// <inheritdoc />
public void Save()
{
if (!HasChanged)
@@ -95,14 +80,10 @@ namespace Artemis.Core
OnSettingSaved();
}
/// <summary>
/// Occurs when the value of the setting has been changed
/// </summary>
/// <inheritdoc />
public event EventHandler? SettingChanged;
/// <summary>
/// Occurs when the value of the setting has been saved
/// </summary>
/// <inheritdoc />
public event EventHandler? SettingSaved;
/// <inheritdoc />
@@ -127,4 +108,46 @@ namespace Artemis.Core
SettingSaved?.Invoke(this, EventArgs.Empty);
}
}
/// <summary>
/// Represents a setting tied to a plugin
/// </summary>
public interface IPluginSetting
{
/// <summary>
/// The name of the setting, unique to this plugin
/// </summary>
string Name { get; }
/// <summary>
/// Determines whether the setting has been changed
/// </summary>
bool HasChanged { get; }
/// <summary>
/// Gets or sets whether changes must automatically be saved
/// <para>Note: When set to <c>true</c> <see cref="HasChanged" /> is always <c>false</c></para>
/// </summary>
bool AutoSave { get; set; }
/// <summary>
/// Resets the setting to the last saved value
/// </summary>
void RejectChanges();
/// <summary>
/// Saves the setting
/// </summary>
void Save();
/// <summary>
/// Occurs when the value of the setting has been changed
/// </summary>
event EventHandler? SettingChanged;
/// <summary>
/// Occurs when the value of the setting has been saved
/// </summary>
event EventHandler? SettingSaved;
}
}
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using Artemis.Storage.Entities.Plugins;
using Artemis.Storage.Repositories.Interfaces;
using Newtonsoft.Json;
namespace Artemis.Core
{
@@ -12,15 +11,15 @@ namespace Artemis.Core
public class PluginSettings
{
private readonly IPluginRepository _pluginRepository;
private readonly Dictionary<string, object> _settingEntities;
private readonly Dictionary<string, IPluginSetting> _settingEntities;
internal PluginSettings(Plugin plugin, IPluginRepository pluginRepository)
{
Plugin = plugin;
Plugin.Settings = this;
_pluginRepository = pluginRepository;
_settingEntities = new Dictionary<string, object>();
_settingEntities = new Dictionary<string, IPluginSetting>();
}
/// <summary>
@@ -49,14 +48,14 @@ namespace Artemis.Core
{
settingEntity = new PluginSettingEntity
{
Name = name,
PluginGuid = Plugin.Guid,
Name = name,
PluginGuid = Plugin.Guid,
Value = CoreJson.SerializeObject(defaultValue)
};
_pluginRepository.AddSetting(settingEntity);
}
PluginSetting<T> pluginSetting = new(Plugin, _pluginRepository, settingEntity);
PluginSetting<T> pluginSetting = new(_pluginRepository, settingEntity);
// This overrides null with the default value, I'm not sure if that's desirable because you
// might expect something to go null and you might not
@@ -68,6 +67,15 @@ namespace Artemis.Core
}
}
/// <summary>
/// Saves all currently loaded settings
/// </summary>
public void SaveAllSettings()
{
foreach (var (_, pluginSetting) in _settingEntities)
pluginSetting.Save();
}
internal void ClearSettings()
{
_settingEntities.Clear();
+1 -1
View File
@@ -35,7 +35,7 @@ namespace Artemis.Core.Services
_logger = logger;
_pluginManagementService = pluginManagementService;
_deviceRepository = deviceRepository;
_targetFrameRateSetting = settingsService.GetSetting("Core.TargetFrameRate", 25);
_targetFrameRateSetting = settingsService.GetSetting("Core.TargetFrameRate", 30);
_renderScaleSetting = settingsService.GetSetting("Core.RenderScale", 0.25);
Surface = new RGBSurface();
@@ -16,6 +16,12 @@ namespace Artemis.Core.Services
{
return _pluginSettings.GetSetting(name, defaultValue);
}
/// <inheritdoc />
public void SaveAllSettings()
{
_pluginSettings.SaveAllSettings();
}
}
/// <summary>
@@ -32,5 +38,10 @@ namespace Artemis.Core.Services
/// <param name="defaultValue">The default value to use if the setting does not exist yet</param>
/// <returns></returns>
PluginSetting<T> GetSetting<T>(string name, T? defaultValue = default);
/// <summary>
/// Saves all settings, obviously
/// </summary>
void SaveAllSettings();
}
}