mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Added a layer of abstraction between RGB.NET and Artemis
This means Artemis can add extra functionality It also avoid having to reference RGB.NET for basic rendering Implemented rendering scaling
This commit is contained in:
1 parent
498b6a6111
commit
8777e8975f
41 files changed
+725
-494
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using RGB.NET.Core;
|
||||
|
||||
@@ -24,6 +25,6 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
/// <summary>
|
||||
/// Renders the layer type
|
||||
/// </summary>
|
||||
public abstract void Render(Layer device, RGBSurface surface, Graphics graphics);
|
||||
public abstract void Render(Layer device, Surface surface, Graphics graphics);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using RGB.NET.Core;
|
||||
using Stylet;
|
||||
@@ -38,7 +39,7 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
/// <param name="deltaTime">Time since the last render</param>
|
||||
/// <param name="surface">The RGB Surface to render to</param>
|
||||
/// <param name="graphics"></param>
|
||||
public abstract void Render(double deltaTime, RGBSurface surface, Graphics graphics);
|
||||
public abstract void Render(double deltaTime, Surface surface, Graphics graphics);
|
||||
|
||||
/// <summary>
|
||||
/// Called when the module's main view is being shown
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using RGB.NET.Core;
|
||||
|
||||
@@ -25,7 +26,7 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Render(double deltaTime, RGBSurface surface, Graphics graphics)
|
||||
public override void Render(double deltaTime, Surface surface, Graphics graphics)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Storage.Entities;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using Newtonsoft.Json;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.Core.Plugins.Models
|
||||
{
|
||||
public class PluginSetting<T>
|
||||
public class PluginSetting<T> : PropertyChangedBase
|
||||
{
|
||||
// ReSharper disable once NotAccessedField.Local
|
||||
private readonly PluginInfo _pluginInfo;
|
||||
@@ -20,6 +23,15 @@ namespace Artemis.Core.Plugins.Models
|
||||
|
||||
Name = pluginSettingEntity.Name;
|
||||
Value = JsonConvert.DeserializeObject<T>(pluginSettingEntity.Value);
|
||||
|
||||
// PropertyChanged is for bindings, but we can use it here to create a easy to use SettingsChanged event
|
||||
PropertyChanged += OnPropertyChanged;
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Value))
|
||||
OnSettingChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -69,5 +81,12 @@ namespace Artemis.Core.Plugins.Models
|
||||
_pluginSettingEntity.Value = JsonConvert.SerializeObject(Value);
|
||||
await _pluginSettingRepository.SaveAsync();
|
||||
}
|
||||
|
||||
public event EventHandler<EventArgs> SettingChanged;
|
||||
|
||||
protected virtual void OnSettingChanged()
|
||||
{
|
||||
SettingChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,10 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Core.Plugins.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>This contains all the settings for your plugin. To access a setting use <see cref="GetSetting{T}" />.</para>
|
||||
/// <para>To use this class, inject it into the constructor of your plugin.</para>
|
||||
/// </summary>
|
||||
public class PluginSettings
|
||||
{
|
||||
private readonly PluginInfo _pluginInfo;
|
||||
@@ -19,17 +23,27 @@ namespace Artemis.Core.Plugins.Models
|
||||
_settingEntities = pluginSettingRepository.GetByPluginGuid(_pluginInfo.Guid).ToDictionary(se => se.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the setting with the provided name. If the setting does not exist yet, it is created.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the setting, can be any serializable type</typeparam>
|
||||
/// <param name="name">The name of the setting</param>
|
||||
/// <param name="defaultValue">The default value to use if the setting does not exist yet</param>
|
||||
/// <returns></returns>
|
||||
public PluginSetting<T> GetSetting<T>(string name, T defaultValue = default(T))
|
||||
{
|
||||
if (_settingEntities.ContainsKey(name))
|
||||
lock (_settingEntities)
|
||||
{
|
||||
if (_settingEntities.ContainsKey(name))
|
||||
return new PluginSetting<T>(_pluginInfo, _pluginSettingRepository, _settingEntities[name]);
|
||||
|
||||
var settingEntity = new PluginSettingEntity {Name = name, PluginGuid = _pluginInfo.Guid, Value = JsonConvert.SerializeObject(defaultValue)};
|
||||
_pluginSettingRepository.Add(settingEntity);
|
||||
_pluginSettingRepository.Save();
|
||||
|
||||
_settingEntities.Add(name, settingEntity);
|
||||
return new PluginSetting<T>(_pluginInfo, _pluginSettingRepository, _settingEntities[name]);
|
||||
|
||||
var settingEntity = new PluginSettingEntity {Name = name, PluginGuid = _pluginInfo.Guid, Value = JsonConvert.SerializeObject(defaultValue)};
|
||||
_pluginSettingRepository.Add(settingEntity);
|
||||
_pluginSettingRepository.Save();
|
||||
|
||||
_settingEntities.Add(name, settingEntity);
|
||||
return new PluginSetting<T>(_pluginInfo, _pluginSettingRepository, _settingEntities[name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user