Implemented layer elements

Added a brush layer element
Corsair - Added ST100 RGB layout
This commit is contained in:
SpoinkyNL committed 2019-12-01 18:55:49 +01:00
1 parent 482cbe79ed
commit 9148323ad5
81 files changed
+1610 -365

No files matched your search

-1
View File
@@ -5,7 +5,6 @@ using Artemis.Core.Events;
using Artemis.Core.Exceptions;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage;
using Artemis.Core.Services.Storage.Interfaces;
using RGB.NET.Core;
using Serilog;
+3 -7
View File
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading.Tasks;
using Artemis.Core.Events;
using Artemis.Core.Models.Surface;
@@ -56,9 +52,9 @@ namespace Artemis.Core.Services
public interface IDeviceService : IArtemisService
{
/// <summary>
/// Identifies the device by making it blink white 5 times
/// Identifies the device by making it blink white 5 times
/// </summary>
/// <param name="device"></param>
void IdentifyDevice(ArtemisDevice device);
}
}
}
@@ -0,0 +1,18 @@
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.LayerElement;
namespace Artemis.Core.Services.Interfaces
{
public interface ILayerService : IArtemisService
{
/// <summary>
/// Instantiates and adds the <see cref="LayerElement" /> described by the provided
/// <see cref="LayerElementDescriptor" /> to the provided <see cref="Layer" />.
/// </summary>
/// <param name="layer">The layer to add the new layer element to</param>
/// <param name="layerElementDescriptor">The descriptor of the new layer element</param>
/// <param name="settings">JSON settings to be deserialized and injected into the layer element</param>
/// <returns></returns>
LayerElement InstantiateLayerElement(Layer layer, LayerElementDescriptor layerElementDescriptor, string settings = null);
}
}
@@ -55,13 +55,6 @@ namespace Artemis.Core.Services.Interfaces
/// <returns>A list containing all the plugin info</returns>
List<PluginInfo> GetAllPluginInfo();
/// <summary>
/// Finds an instance of the layer type matching the given GUID
/// </summary>
/// <param name="layerTypeGuid">The GUID of the layer type to find</param>
/// <returns>An instance of the layer type</returns>
LayerType GetLayerTypeByGuid(Guid layerTypeGuid);
/// <summary>
/// Finds all enabled <see cref="Plugin" /> instances of type <see cref="T" />
/// </summary>
+50
View File
@@ -0,0 +1,50 @@
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.LayerElement;
using Artemis.Core.Services.Interfaces;
using Newtonsoft.Json;
using Ninject;
using Ninject.Parameters;
namespace Artemis.Core.Services
{
public class LayerService : ILayerService
{
private readonly IKernel _kernel;
public LayerService(IKernel kernel)
{
_kernel = kernel;
}
public LayerElement InstantiateLayerElement(Layer layer, LayerElementDescriptor layerElementDescriptor, string settings)
{
// Deserialize the settings, if provided
object deserializedSettings = null;
if (settings != null)
{
var settingsType = layerElementDescriptor.LayerElementType.GetProperty(nameof(LayerElement.Settings))?.PropertyType;
if (settingsType == null)
{
throw new ArtemisPluginException(
layerElementDescriptor.LayerElementProvider.PluginInfo,
$"Layer element of type {layerElementDescriptor.LayerElementType} has no Settings property."
);
}
deserializedSettings = JsonConvert.DeserializeObject(settings, settingsType);
}
var arguments = new IParameter[]
{
new ConstructorArgument("layer", layer),
new ConstructorArgument("settings", deserializedSettings),
new ConstructorArgument("descriptor", layerElementDescriptor)
};
var layerElement = (LayerElement) _kernel.Get(layerElementDescriptor.LayerElementType, arguments);
layer.AddLayerElement(layerElement);
return layerElement;
}
}
}
+1 -14
View File
@@ -285,19 +285,6 @@ namespace Artemis.Core.Services
return new List<PluginInfo>(_plugins);
}
/// <inheritdoc />
public LayerType GetLayerTypeByGuid(Guid layerTypeGuid)
{
var pluginInfo = _plugins.FirstOrDefault(p => p.Guid == layerTypeGuid);
if (pluginInfo == null)
return null;
if (!(pluginInfo.Instance is LayerType layerType))
throw new ArtemisPluginException(pluginInfo, "Plugin is expected to implement exactly one LayerType");
return layerType;
}
/// <inheritdoc />
public List<T> GetPluginsOfType<T>() where T : Plugin
{
@@ -309,7 +296,7 @@ namespace Artemis.Core.Services
public Plugin GetDevicePlugin(IRGBDevice rgbDevice)
{
return GetPluginsOfType<Device>().First(d => d.DeviceProvider.Devices.Contains(rgbDevice));
return GetPluginsOfType<DeviceProvider>().First(d => d.RgbDeviceProvider.Devices.Contains(rgbDevice));
}
public void Dispose()
@@ -12,5 +12,12 @@ namespace Artemis.Core.Services.Storage.Interfaces
Profile GetActiveProfile(ProfileModule module);
void UpdateProfile(Profile profile, bool includeChildren);
void DeleteProfile(Profile profile);
/// <summary>
/// Activates the profile for the given <see cref="ProfileModule" /> with the currently active surface
/// </summary>
/// <param name="module">The module to activate the profile for</param>
/// <param name="profile">The profile to activate</param>
void ActivateProfile(ProfileModule module, Profile profile);
}
}
@@ -16,8 +16,8 @@ namespace Artemis.Core.Services.Storage
public class ProfileService : IProfileService
{
private readonly IPluginService _pluginService;
private readonly ISurfaceService _surfaceService;
private readonly IProfileRepository _profileRepository;
private readonly ISurfaceService _surfaceService;
internal ProfileService(IPluginService pluginService, ISurfaceService surfaceService, IProfileRepository profileRepository)
{
@@ -29,6 +29,73 @@ namespace Artemis.Core.Services.Storage
_surfaceService.SurfaceConfigurationUpdated += SurfaceServiceOnSurfaceConfigurationUpdated;
}
public List<Profile> GetProfiles(ProfileModule module)
{
var profileEntities = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
var profiles = new List<Profile>();
foreach (var profileEntity in profileEntities)
{
// If the profile entity matches the module's currently active profile, use that instead
if (module.ActiveProfile != null && module.ActiveProfile.EntityId == profileEntity.Id)
profiles.Add(module.ActiveProfile);
else
profiles.Add(new Profile(module.PluginInfo, profileEntity));
}
return profiles;
}
public Profile GetActiveProfile(ProfileModule module)
{
if (module.ActiveProfile != null)
return module.ActiveProfile;
var moduleProfiles = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
var profileEntity = moduleProfiles.FirstOrDefault(p => p.IsActive) ?? moduleProfiles.FirstOrDefault();
if (profileEntity == null)
return null;
return new Profile(module.PluginInfo, profileEntity);
}
public Profile CreateProfile(ProfileModule module, string name)
{
var profile = new Profile(module.PluginInfo, name);
_profileRepository.Add(profile.ProfileEntity);
if (_surfaceService.ActiveSurface != null)
profile.ApplySurface(_surfaceService.ActiveSurface);
return profile;
}
public void ActivateProfile(ProfileModule module, Profile profile)
{
module.ChangeActiveProfile(profile, _surfaceService.ActiveSurface);
}
public void DeleteProfile(Profile profile)
{
_profileRepository.Remove(profile.ProfileEntity);
}
public void UpdateProfile(Profile profile, bool includeChildren)
{
profile.ApplyToEntity();
if (includeChildren)
{
foreach (var folder in profile.GetAllFolders())
folder.ApplyToEntity();
foreach (var layer in profile.GetAllLayers())
layer.ApplyToEntity();
if (_surfaceService.ActiveSurface != null)
profile.ApplySurface(_surfaceService.ActiveSurface);
}
_profileRepository.Save(profile.ProfileEntity);
}
private void SurfaceServiceOnActiveSurfaceConfigurationChanged(object sender, SurfaceConfigurationEventArgs e)
{
ApplySurfaceToProfiles(e.Surface);
@@ -47,66 +114,5 @@ namespace Artemis.Core.Services.Storage
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
profileModule.ActiveProfile.ApplySurface(surface);
}
public List<Profile> GetProfiles(ProfileModule module)
{
var profileEntities = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
var profiles = new List<Profile>();
foreach (var profileEntity in profileEntities)
{
// If the profile entity matches the module's currently active profile, use that instead
if (module.ActiveProfile != null && module.ActiveProfile.EntityId == profileEntity.Id)
profiles.Add(module.ActiveProfile);
else
profiles.Add(new Profile(module.PluginInfo, profileEntity, _pluginService));
}
return profiles;
}
public Profile GetActiveProfile(ProfileModule module)
{
if (module.ActiveProfile != null)
return module.ActiveProfile;
var moduleProfiles = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
var profileEntity = moduleProfiles.FirstOrDefault(p => p.IsActive) ?? moduleProfiles.FirstOrDefault();
if (profileEntity == null)
return null;
return new Profile(module.PluginInfo, profileEntity, _pluginService);
}
public Profile CreateProfile(ProfileModule module, string name)
{
var profile = new Profile(module.PluginInfo, name);
_profileRepository.Add(profile.ProfileEntity);
if (_surfaceService.ActiveSurface != null)
profile.ApplySurface(_surfaceService.ActiveSurface);
return profile;
}
public void DeleteProfile(Profile profile)
{
_profileRepository.Remove(profile.ProfileEntity);
}
public void UpdateProfile(Profile profile, bool includeChildren)
{
profile.ApplyToEntity();
if (includeChildren)
{
foreach (var folder in profile.GetAllFolders())
folder.ApplyToEntity();
foreach (var layer in profile.GetAllLayers())
layer.ApplyToEntity();
if (_surfaceService.ActiveSurface != null)
profile.ApplySurface(_surfaceService.ActiveSurface);
}
_profileRepository.Save(profile.ProfileEntity);
}
}
}