mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Implemented layer LED assignment
Added a centralised ProfileEditorSurface for communication between VMs Prefixed Surface, Device and Led with Artemis to differentiate them better
This commit is contained in:
1 parent
8a596f1426
commit
f32edcf502
50 files changed
+556
-662
No files matched your search
@@ -161,9 +161,9 @@
|
||||
<Compile Include="Extensions\RgbRectangleExtensions.cs" />
|
||||
<Compile Include="Extensions\TypeExtensions.cs" />
|
||||
<Compile Include="Models\DataModelDescription.cs" />
|
||||
<Compile Include="Models\Surface\DeviceLed.cs" />
|
||||
<Compile Include="Models\Surface\Surface.cs" />
|
||||
<Compile Include="Models\Surface\Device.cs" />
|
||||
<Compile Include="Models\Surface\ArtemisLed.cs" />
|
||||
<Compile Include="Models\Surface\ArtemisSurface.cs" />
|
||||
<Compile Include="Models\Surface\ArtemisDevice.cs" />
|
||||
<Compile Include="Ninject\LoggerProvider.cs" />
|
||||
<Compile Include="Ninject\PluginSettingsProvider.cs" />
|
||||
<Compile Include="Ninject\SettingsServiceProvider.cs" />
|
||||
@@ -216,9 +216,7 @@
|
||||
<Name>Artemis.Storage</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="ProfileElements\Interfaces\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\Fody.6.0.5\build\Fody.targets" Condition="Exists('..\packages\Fody.6.0.5\build\Fody.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
|
||||
@@ -5,11 +5,11 @@ namespace Artemis.Core.Events
|
||||
{
|
||||
public class SurfaceConfigurationEventArgs : EventArgs
|
||||
{
|
||||
public SurfaceConfigurationEventArgs(Surface surface)
|
||||
public SurfaceConfigurationEventArgs(ArtemisSurface surface)
|
||||
{
|
||||
Surface = surface;
|
||||
}
|
||||
|
||||
public Surface Surface { get; }
|
||||
public ArtemisSurface Surface { get; }
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ namespace Artemis.Core.Models.Profile.Abstract
|
||||
/// <summary>
|
||||
/// Renders the element
|
||||
/// </summary>
|
||||
public abstract void Render(double deltaTime, Surface.Surface surface, Graphics graphics);
|
||||
public abstract void Render(double deltaTime, Surface.ArtemisSurface surface, Graphics graphics);
|
||||
|
||||
/// <summary>
|
||||
/// Applies the profile element's properties to the underlying storage entity
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Artemis.Core.Models.Profile
|
||||
profileElement.Update(deltaTime);
|
||||
}
|
||||
|
||||
public override void Render(double deltaTime, Surface.Surface surface, Graphics graphics)
|
||||
public override void Render(double deltaTime, Surface.ArtemisSurface surface, Graphics graphics)
|
||||
{
|
||||
// Folders don't render but their children do
|
||||
foreach (var profileElement in Children)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
@@ -15,6 +16,8 @@ namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
public sealed class Layer : ProfileElement
|
||||
{
|
||||
private List<ArtemisLed> _leds;
|
||||
|
||||
public Layer(Profile profile, ProfileElement parent, string name)
|
||||
{
|
||||
LayerEntity = new LayerEntity();
|
||||
@@ -23,7 +26,7 @@ namespace Artemis.Core.Models.Profile
|
||||
Profile = profile;
|
||||
Parent = parent;
|
||||
Name = name;
|
||||
Leds = new List<DeviceLed>();
|
||||
_leds = new List<ArtemisLed>();
|
||||
}
|
||||
|
||||
internal Layer(Profile profile, ProfileElement parent, LayerEntity layerEntity, IPluginService pluginService)
|
||||
@@ -37,12 +40,12 @@ namespace Artemis.Core.Models.Profile
|
||||
Order = layerEntity.Order;
|
||||
|
||||
LayerType = pluginService.GetLayerTypeByGuid(layerEntity.LayerTypeGuid);
|
||||
Leds = new List<DeviceLed>();
|
||||
_leds = new List<ArtemisLed>();
|
||||
}
|
||||
|
||||
internal LayerEntity LayerEntity { get; set; }
|
||||
|
||||
public List<DeviceLed> Leds { get; private set; }
|
||||
public ReadOnlyCollection<ArtemisLed> Leds => _leds.AsReadOnly();
|
||||
public LayerType LayerType { get; private set; }
|
||||
public ILayerTypeConfiguration LayerTypeConfiguration { get; set; }
|
||||
|
||||
@@ -60,7 +63,7 @@ namespace Artemis.Core.Models.Profile
|
||||
}
|
||||
}
|
||||
|
||||
public override void Render(double deltaTime, Surface.Surface surface, Graphics graphics)
|
||||
public override void Render(double deltaTime, ArtemisSurface surface, Graphics graphics)
|
||||
{
|
||||
if (LayerType == null)
|
||||
return;
|
||||
@@ -81,19 +84,62 @@ namespace Artemis.Core.Models.Profile
|
||||
LayerEntity.Name = Name;
|
||||
|
||||
LayerEntity.ProfileId = Profile.EntityId;
|
||||
// TODO: LEDs, conditions, elements
|
||||
}
|
||||
|
||||
public void ApplySurface(Surface.Surface surface)
|
||||
{
|
||||
var leds = new List<DeviceLed>();
|
||||
foreach (var surfaceDevice in surface.Devices)
|
||||
LayerEntity.Leds.Clear();
|
||||
foreach (var artemisLed in Leds)
|
||||
{
|
||||
var deviceHash = surfaceDevice.RgbDevice.GetDeviceHashCode();
|
||||
leds.AddRange(surfaceDevice.Leds.Where(dl => LayerEntity.Leds.Any(l => l.DeviceHash == deviceHash && l.LedName == dl.RgbLed.ToString())));
|
||||
var ledEntity = new LedEntity
|
||||
{
|
||||
DeviceHash = artemisLed.Device.RgbDevice.GetDeviceHashCode(),
|
||||
LedName = artemisLed.RgbLed.Id.ToString()
|
||||
};
|
||||
LayerEntity.Leds.Add(ledEntity);
|
||||
}
|
||||
|
||||
Leds = leds;
|
||||
LayerEntity.Condition.Clear();
|
||||
|
||||
LayerEntity.Elements.Clear();
|
||||
}
|
||||
|
||||
public void ApplySurface(ArtemisSurface surface)
|
||||
{
|
||||
var leds = new List<ArtemisLed>();
|
||||
|
||||
// Get the surface LEDs for this layer
|
||||
var availableLeds = surface.Devices.SelectMany(d => d.Leds).ToList();
|
||||
foreach (var ledEntity in LayerEntity.Leds)
|
||||
{
|
||||
var match = availableLeds.FirstOrDefault(a => a.Device.RgbDevice.GetDeviceHashCode() == ledEntity.DeviceHash &&
|
||||
a.RgbLed.Id.ToString() == ledEntity.LedName);
|
||||
if (match != null)
|
||||
leds.Add(match);
|
||||
}
|
||||
|
||||
_leds = leds;
|
||||
CalculateRenderProperties();
|
||||
}
|
||||
|
||||
public void AddLed(ArtemisLed led)
|
||||
{
|
||||
_leds.Add(led);
|
||||
CalculateRenderProperties();
|
||||
}
|
||||
|
||||
public void AddLeds(IEnumerable<ArtemisLed> leds)
|
||||
{
|
||||
_leds.AddRange(leds);
|
||||
CalculateRenderProperties();
|
||||
}
|
||||
|
||||
public void RemoveLed(ArtemisLed led)
|
||||
{
|
||||
_leds.Remove(led);
|
||||
CalculateRenderProperties();
|
||||
}
|
||||
|
||||
public void ClearLeds()
|
||||
{
|
||||
_leds.Clear();
|
||||
CalculateRenderProperties();
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Artemis.Core.Models.Profile
|
||||
}
|
||||
}
|
||||
|
||||
public override void Render(double deltaTime, Surface.Surface surface, Graphics graphics)
|
||||
public override void Render(double deltaTime, Surface.ArtemisSurface surface, Graphics graphics)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
@@ -113,7 +113,7 @@ namespace Artemis.Core.Models.Profile
|
||||
return $"{nameof(Order)}: {Order}, {nameof(Name)}: {Name}, {nameof(PluginInfo)}: {PluginInfo}";
|
||||
}
|
||||
|
||||
public void ApplySurface(Surface.Surface surface)
|
||||
public void ApplySurface(Surface.ArtemisSurface surface)
|
||||
{
|
||||
foreach (var layer in GetAllLayers())
|
||||
layer.ApplySurface(surface);
|
||||
|
||||
+7
-7
@@ -11,15 +11,15 @@ using Rectangle = System.Drawing.Rectangle;
|
||||
|
||||
namespace Artemis.Core.Models.Surface
|
||||
{
|
||||
public class Device : PropertyChangedBase
|
||||
public class ArtemisDevice : PropertyChangedBase
|
||||
{
|
||||
internal Device(IRGBDevice rgbDevice, Plugin plugin, Surface surface)
|
||||
internal ArtemisDevice(IRGBDevice rgbDevice, Plugin plugin, ArtemisSurface surface)
|
||||
{
|
||||
RgbDevice = rgbDevice;
|
||||
Plugin = plugin;
|
||||
Surface = surface;
|
||||
DeviceEntity = new DeviceEntity();
|
||||
Leds = rgbDevice.Select(l => new DeviceLed(l, this)).ToList().AsReadOnly();
|
||||
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
||||
|
||||
Rotation = 0;
|
||||
Scale = 1;
|
||||
@@ -29,13 +29,13 @@ namespace Artemis.Core.Models.Surface
|
||||
CalculateRenderProperties();
|
||||
}
|
||||
|
||||
internal Device(IRGBDevice rgbDevice, Plugin plugin, Surface surface, DeviceEntity deviceEntity)
|
||||
internal ArtemisDevice(IRGBDevice rgbDevice, Plugin plugin, ArtemisSurface surface, DeviceEntity deviceEntity)
|
||||
{
|
||||
RgbDevice = rgbDevice;
|
||||
Plugin = plugin;
|
||||
Surface = surface;
|
||||
DeviceEntity = deviceEntity;
|
||||
Leds = rgbDevice.Select(l => new DeviceLed(l, this)).ToList().AsReadOnly();
|
||||
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
||||
}
|
||||
|
||||
public Rectangle RenderRectangle { get; private set; }
|
||||
@@ -43,9 +43,9 @@ namespace Artemis.Core.Models.Surface
|
||||
|
||||
public IRGBDevice RgbDevice { get; }
|
||||
public Plugin Plugin { get; }
|
||||
public Surface Surface { get; }
|
||||
public ArtemisSurface Surface { get; }
|
||||
public DeviceEntity DeviceEntity { get; }
|
||||
public ReadOnlyCollection<DeviceLed> Leds { get; set; }
|
||||
public ReadOnlyCollection<ArtemisLed> Leds { get; set; }
|
||||
|
||||
public double X
|
||||
{
|
||||
+3
-3
@@ -5,9 +5,9 @@ using Rectangle = System.Drawing.Rectangle;
|
||||
|
||||
namespace Artemis.Core.Models.Surface
|
||||
{
|
||||
public class DeviceLed : PropertyChangedBase
|
||||
public class ArtemisLed : PropertyChangedBase
|
||||
{
|
||||
public DeviceLed(Led led, Device device)
|
||||
public ArtemisLed(Led led, ArtemisDevice device)
|
||||
{
|
||||
RgbLed = led;
|
||||
Device = device;
|
||||
@@ -15,7 +15,7 @@ namespace Artemis.Core.Models.Surface
|
||||
}
|
||||
|
||||
public Led RgbLed { get; }
|
||||
public Device Device { get; }
|
||||
public ArtemisDevice Device { get; }
|
||||
|
||||
public Rectangle RenderRectangle { get; private set; }
|
||||
public Rectangle AbsoluteRenderRectangle { get; private set; }
|
||||
+6
-6
@@ -7,9 +7,9 @@ using Stylet;
|
||||
|
||||
namespace Artemis.Core.Models.Surface
|
||||
{
|
||||
public class Surface : PropertyChangedBase
|
||||
public class ArtemisSurface : PropertyChangedBase
|
||||
{
|
||||
internal Surface(RGBSurface rgbSurface, string name, double scale)
|
||||
internal ArtemisSurface(RGBSurface rgbSurface, string name, double scale)
|
||||
{
|
||||
SurfaceEntity = new SurfaceEntity {DeviceEntities = new List<DeviceEntity>()};
|
||||
EntityId = Guid.NewGuid();
|
||||
@@ -20,12 +20,12 @@ namespace Artemis.Core.Models.Surface
|
||||
IsActive = false;
|
||||
|
||||
// Devices are not populated here but as they are detected
|
||||
Devices = new List<Device>();
|
||||
Devices = new List<ArtemisDevice>();
|
||||
|
||||
ApplyToEntity();
|
||||
}
|
||||
|
||||
internal Surface(RGBSurface rgbSurface, SurfaceEntity surfaceEntity, double scale)
|
||||
internal ArtemisSurface(RGBSurface rgbSurface, SurfaceEntity surfaceEntity, double scale)
|
||||
{
|
||||
SurfaceEntity = surfaceEntity;
|
||||
EntityId = surfaceEntity.Id;
|
||||
@@ -36,14 +36,14 @@ namespace Artemis.Core.Models.Surface
|
||||
IsActive = surfaceEntity.IsActive;
|
||||
|
||||
// Devices are not populated here but as they are detected
|
||||
Devices = new List<Device>();
|
||||
Devices = new List<ArtemisDevice>();
|
||||
}
|
||||
|
||||
public RGBSurface RgbSurface { get; }
|
||||
public double Scale { get; private set; }
|
||||
public string Name { get; set; }
|
||||
public bool IsActive { get; internal set; }
|
||||
public List<Device> Devices { get; internal set; }
|
||||
public List<ArtemisDevice> Devices { get; internal set; }
|
||||
|
||||
internal SurfaceEntity SurfaceEntity { get; set; }
|
||||
internal Guid EntityId { get; set; }
|
||||
@@ -24,6 +24,6 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
/// <summary>
|
||||
/// Renders the layer type
|
||||
/// </summary>
|
||||
public abstract void Render(Layer device, Surface surface, Graphics graphics);
|
||||
public abstract void Render(Layer device, ArtemisSurface surface, Graphics graphics);
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,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, Surface surface, Graphics graphics);
|
||||
public abstract void Render(double deltaTime, ArtemisSurface surface, Graphics graphics);
|
||||
|
||||
/// <summary>
|
||||
/// Called when the module's view model is being show, return view models here to create tabs for them
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Render(double deltaTime, Surface surface, Graphics graphics)
|
||||
public override void Render(double deltaTime, ArtemisSurface surface, Graphics graphics)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.ProfileElements.Interfaces;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.ProfileElements
|
||||
{
|
||||
public class Folder : IProfileElement
|
||||
{
|
||||
public Folder(Profile profile)
|
||||
{
|
||||
Profile = profile;
|
||||
Children = new List<IProfileElement>();
|
||||
}
|
||||
|
||||
public Profile Profile { get; }
|
||||
public List<IProfileElement> Children { get; set; }
|
||||
public int Order { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public void Update(double deltaTime)
|
||||
{
|
||||
// Folders don't update but their children do
|
||||
foreach (var profileElement in Children)
|
||||
profileElement.Update(deltaTime);
|
||||
}
|
||||
|
||||
public void Render(double deltaTime, RGBSurface surface, Graphics graphics)
|
||||
{
|
||||
// Folders don't render but their children do
|
||||
foreach (var profileElement in Children)
|
||||
profileElement.Render(deltaTime, surface, graphics);
|
||||
}
|
||||
|
||||
public static Folder FromFolderEntity(Profile profile, FolderEntity folderEntity, IPluginService pluginService)
|
||||
{
|
||||
var folder = new Folder(profile)
|
||||
{
|
||||
Name = folderEntity.Name,
|
||||
Order = folderEntity.Order
|
||||
};
|
||||
|
||||
// Load child folders
|
||||
foreach (var childFolder in folderEntity.Folders)
|
||||
folder.Children.Add(FromFolderEntity(profile, childFolder, pluginService));
|
||||
// Load child layers
|
||||
foreach (var childLayer in folderEntity.Layers)
|
||||
folder.Children.Add(Layer.FromLayerEntity(profile, childLayer, pluginService));
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{nameof(Profile)}: {Profile}, {nameof(Order)}: {Order}, {nameof(Name)}: {Name}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.ProfileElements.Interfaces
|
||||
{
|
||||
public interface IProfileElement
|
||||
{
|
||||
/// <summary>
|
||||
/// The element's children
|
||||
/// </summary>
|
||||
List<IProfileElement> Children { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The order in which this element appears in the update loop and editor
|
||||
/// </summary>
|
||||
int Order { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name which appears in the editor
|
||||
/// </summary>
|
||||
string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Updates the element
|
||||
/// </summary>
|
||||
/// <param name="deltaTime"></param>
|
||||
void Update(double deltaTime);
|
||||
|
||||
/// <summary>
|
||||
/// Renders the element
|
||||
/// </summary>
|
||||
void Render(double deltaTime, RGBSurface surface, Graphics graphics);
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.ProfileElements.Interfaces;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.ProfileElements
|
||||
{
|
||||
public class Layer : IProfileElement
|
||||
{
|
||||
public Layer(Profile profile)
|
||||
{
|
||||
Profile = profile;
|
||||
Children = new List<IProfileElement>();
|
||||
}
|
||||
|
||||
public Profile Profile { get; }
|
||||
public LayerType LayerType { get; private set; }
|
||||
public ILayerTypeConfiguration LayerTypeConfiguration { get; set; }
|
||||
public List<IProfileElement> Children { get; set; }
|
||||
public int Order { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public void Update(double deltaTime)
|
||||
{
|
||||
if (LayerType == null)
|
||||
return;
|
||||
|
||||
lock (LayerType)
|
||||
{
|
||||
LayerType.Update(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Render(double deltaTime, RGBSurface surface, Graphics graphics)
|
||||
{
|
||||
if (LayerType == null)
|
||||
return;
|
||||
|
||||
lock (LayerType)
|
||||
{
|
||||
LayerType.Render(this, surface, graphics);
|
||||
}
|
||||
}
|
||||
|
||||
public static Layer FromLayerEntity(Profile profile, LayerEntity layerEntity, IPluginService pluginService)
|
||||
{
|
||||
var layer = new Layer(profile)
|
||||
{
|
||||
Name = layerEntity.Name,
|
||||
Order = layerEntity.Order,
|
||||
LayerType = pluginService.GetLayerTypeByGuid(Guid.Parse(layerEntity.Guid))
|
||||
};
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
public void UpdateLayerType(LayerType layerType)
|
||||
{
|
||||
if (LayerType != null)
|
||||
{
|
||||
lock (LayerType)
|
||||
{
|
||||
LayerType.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
LayerType = layerType;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{nameof(Profile)}: {Profile}, {nameof(Order)}: {Order}, {nameof(Name)}: {Name}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.ProfileElements.Interfaces;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.ProfileElements
|
||||
{
|
||||
public class Profile : IProfileElement
|
||||
{
|
||||
private Profile(PluginInfo pluginInfo)
|
||||
{
|
||||
PluginInfo = pluginInfo;
|
||||
}
|
||||
|
||||
public PluginInfo PluginInfo { get; }
|
||||
public bool IsActivated { get; private set; }
|
||||
public int Order { get; set; }
|
||||
public string Name { get; set; }
|
||||
public List<IProfileElement> Children { get; set; }
|
||||
|
||||
public void Update(double deltaTime)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (!IsActivated)
|
||||
throw new ArtemisCoreException($"Cannot update inactive profile: {this}");
|
||||
|
||||
foreach (var profileElement in Children)
|
||||
profileElement.Update(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void Render(double deltaTime, RGBSurface surface, Graphics graphics)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (!IsActivated)
|
||||
throw new ArtemisCoreException($"Cannot render inactive profile: {this}");
|
||||
|
||||
foreach (var profileElement in Children)
|
||||
profileElement.Render(deltaTime, surface, graphics);
|
||||
}
|
||||
}
|
||||
|
||||
public static Profile FromProfileEntity(PluginInfo pluginInfo, ProfileEntity profileEntity, IPluginService pluginService)
|
||||
{
|
||||
var profile = new Profile(pluginInfo) {Name = profileEntity.Name};
|
||||
lock (profile)
|
||||
{
|
||||
// Populate the profile starting at the root, the rest is populated recursively
|
||||
profile.Children.Add(Folder.FromFolderEntity(profile, profileEntity.RootFolder, pluginService));
|
||||
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (IsActivated) return;
|
||||
|
||||
OnActivated();
|
||||
IsActivated = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (!IsActivated) return;
|
||||
|
||||
IsActivated = false;
|
||||
OnDeactivated();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{nameof(Order)}: {Order}, {nameof(Name)}: {Name}, {nameof(PluginInfo)}: {PluginInfo}";
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the profile is being activated.
|
||||
/// </summary>
|
||||
public event EventHandler Activated;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the profile is being deactivated.
|
||||
/// </summary>
|
||||
public event EventHandler Deactivated;
|
||||
|
||||
private void OnActivated()
|
||||
{
|
||||
Activated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void OnDeactivated()
|
||||
{
|
||||
Deactivated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,12 @@ namespace Artemis.Core.Services
|
||||
_coreService = coreService;
|
||||
}
|
||||
|
||||
public void IdentifyDevice(Device device)
|
||||
public void IdentifyDevice(ArtemisDevice device)
|
||||
{
|
||||
BlinkDevice(device, 0);
|
||||
}
|
||||
|
||||
private void BlinkDevice(Device device, int blinkCount)
|
||||
private void BlinkDevice(ArtemisDevice device, int blinkCount)
|
||||
{
|
||||
// Draw a white overlay over the device
|
||||
void DrawOverlay(object sender, FrameRenderingEventArgs args)
|
||||
@@ -59,6 +59,6 @@ namespace Artemis.Core.Services
|
||||
/// Identifies the device by making it blink white 5 times
|
||||
/// </summary>
|
||||
/// <param name="device"></param>
|
||||
void IdentifyDevice(Device device);
|
||||
void IdentifyDevice(ArtemisDevice device);
|
||||
}
|
||||
}
|
||||
@@ -11,38 +11,38 @@ namespace Artemis.Core.Services.Storage.Interfaces
|
||||
/// <summary>
|
||||
/// Gets the currently active surface entity, to change config use <see cref="SetActiveSurfaceConfiguration" />
|
||||
/// </summary>
|
||||
Surface ActiveSurface { get; }
|
||||
ArtemisSurface ActiveSurface { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only list of all surface configurations
|
||||
/// </summary>
|
||||
ReadOnlyCollection<Surface> SurfaceConfigurations { get; }
|
||||
ReadOnlyCollection<ArtemisSurface> SurfaceConfigurations { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new surface entity with the supplied name
|
||||
/// </summary>
|
||||
/// <param name="name">The name for the new surface entity</param>
|
||||
/// <returns></returns>
|
||||
Surface CreateSurfaceConfiguration(string name);
|
||||
ArtemisSurface CreateSurfaceConfiguration(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the provided entity as active and applies it to the surface
|
||||
/// </summary>
|
||||
/// <param name="surface">The entity to activate and apply</param>
|
||||
void SetActiveSurfaceConfiguration(Surface surface);
|
||||
void SetActiveSurfaceConfiguration(ArtemisSurface surface);
|
||||
|
||||
/// <summary>
|
||||
/// Saves the provided surface entity to permanent storage and if config is active, applies it to the surface
|
||||
/// </summary>
|
||||
/// <param name="surface">The entity to save (and apply if active)</param>
|
||||
/// <param name="includeDevices">Whether to also save devices. If false, devices changes won't be applied either</param>
|
||||
void UpdateSurfaceConfiguration(Surface surface, bool includeDevices);
|
||||
void UpdateSurfaceConfiguration(ArtemisSurface surface, bool includeDevices);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the supplied surface entity, surface entity may not be the active surface entity
|
||||
/// </summary>
|
||||
/// <param name="surface">The surface entity to delete, may not be the active surface entity</param>
|
||||
void DeleteSurfaceConfiguration(Surface surface);
|
||||
void DeleteSurfaceConfiguration(ArtemisSurface surface);
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the active device entity has been changed
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Artemis.Core.Services.Storage
|
||||
ApplySurfaceToProfiles(e.Surface);
|
||||
}
|
||||
|
||||
private void ApplySurfaceToProfiles(Surface surface)
|
||||
private void ApplySurfaceToProfiles(ArtemisSurface surface)
|
||||
{
|
||||
var profileModules = _pluginService.GetPluginsOfType<ProfileModule>();
|
||||
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Artemis.Core.Services.Storage
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly PluginSetting<double> _renderScaleSetting;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly List<Surface> _surfaceConfigurations;
|
||||
private readonly List<ArtemisSurface> _surfaceConfigurations;
|
||||
private readonly ISurfaceRepository _surfaceRepository;
|
||||
|
||||
internal SurfaceService(ILogger logger, ISurfaceRepository surfaceRepository, IRgbService rgbService, IPluginService pluginService, ISettingsService settingsService)
|
||||
@@ -30,7 +30,7 @@ namespace Artemis.Core.Services.Storage
|
||||
_surfaceRepository = surfaceRepository;
|
||||
_rgbService = rgbService;
|
||||
_pluginService = pluginService;
|
||||
_surfaceConfigurations = new List<Surface>();
|
||||
_surfaceConfigurations = new List<ArtemisSurface>();
|
||||
_renderScaleSetting = settingsService.GetSetting("Core.RenderScale", 1.0);
|
||||
|
||||
LoadFromRepository();
|
||||
@@ -39,19 +39,19 @@ namespace Artemis.Core.Services.Storage
|
||||
_renderScaleSetting.SettingChanged += RenderScaleSettingOnSettingChanged;
|
||||
}
|
||||
|
||||
public Surface ActiveSurface { get; private set; }
|
||||
public ReadOnlyCollection<Surface> SurfaceConfigurations => _surfaceConfigurations.AsReadOnly();
|
||||
public ArtemisSurface ActiveSurface { get; private set; }
|
||||
public ReadOnlyCollection<ArtemisSurface> SurfaceConfigurations => _surfaceConfigurations.AsReadOnly();
|
||||
|
||||
public Surface CreateSurfaceConfiguration(string name)
|
||||
public ArtemisSurface CreateSurfaceConfiguration(string name)
|
||||
{
|
||||
// Create a blank config
|
||||
var configuration = new Surface(_rgbService.Surface, name, _renderScaleSetting.Value);
|
||||
var configuration = new ArtemisSurface(_rgbService.Surface, name, _renderScaleSetting.Value);
|
||||
|
||||
// Add all current devices
|
||||
foreach (var rgbDevice in _rgbService.LoadedDevices)
|
||||
{
|
||||
var plugin = _pluginService.GetDevicePlugin(rgbDevice);
|
||||
configuration.Devices.Add(new Device(rgbDevice, plugin, configuration));
|
||||
configuration.Devices.Add(new ArtemisDevice(rgbDevice, plugin, configuration));
|
||||
}
|
||||
|
||||
lock (_surfaceConfigurations)
|
||||
@@ -64,7 +64,7 @@ namespace Artemis.Core.Services.Storage
|
||||
}
|
||||
}
|
||||
|
||||
public void SetActiveSurfaceConfiguration(Surface surface)
|
||||
public void SetActiveSurfaceConfiguration(ArtemisSurface surface)
|
||||
{
|
||||
if (ActiveSurface == surface)
|
||||
return;
|
||||
@@ -97,7 +97,7 @@ namespace Artemis.Core.Services.Storage
|
||||
OnActiveSurfaceConfigurationChanged(new SurfaceConfigurationEventArgs(ActiveSurface));
|
||||
}
|
||||
|
||||
public void UpdateSurfaceConfiguration(Surface surface, bool includeDevices)
|
||||
public void UpdateSurfaceConfiguration(ArtemisSurface surface, bool includeDevices)
|
||||
{
|
||||
surface.ApplyToEntity();
|
||||
if (includeDevices)
|
||||
@@ -115,7 +115,7 @@ namespace Artemis.Core.Services.Storage
|
||||
OnSurfaceConfigurationUpdated(new SurfaceConfigurationEventArgs(surface));
|
||||
}
|
||||
|
||||
public void DeleteSurfaceConfiguration(Surface surface)
|
||||
public void DeleteSurfaceConfiguration(ArtemisSurface surface)
|
||||
{
|
||||
if (surface == ActiveSurface)
|
||||
throw new ArtemisCoreException($"Cannot delete surface entity '{surface.Name}' because it is active.");
|
||||
@@ -136,14 +136,14 @@ namespace Artemis.Core.Services.Storage
|
||||
foreach (var surfaceEntity in configs)
|
||||
{
|
||||
// Create the surface entity
|
||||
var surfaceConfiguration = new Surface(_rgbService.Surface, surfaceEntity, _renderScaleSetting.Value);
|
||||
var surfaceConfiguration = new ArtemisSurface(_rgbService.Surface, surfaceEntity, _renderScaleSetting.Value);
|
||||
foreach (var position in surfaceEntity.DeviceEntities)
|
||||
{
|
||||
var device = _rgbService.Surface.Devices.FirstOrDefault(d => d.GetDeviceHashCode() == position.DeviceHashCode);
|
||||
if (device != null)
|
||||
{
|
||||
var plugin = _pluginService.GetDevicePlugin(device);
|
||||
surfaceConfiguration.Devices.Add(new Device(device, plugin, surfaceConfiguration, position));
|
||||
surfaceConfiguration.Devices.Add(new ArtemisDevice(device, plugin, surfaceConfiguration, position));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace Artemis.Core.Services.Storage
|
||||
|
||||
#region Utilities
|
||||
|
||||
private void AddDeviceIfMissing(IRGBDevice rgbDevice, Surface surface)
|
||||
private void AddDeviceIfMissing(IRGBDevice rgbDevice, ArtemisSurface surface)
|
||||
{
|
||||
var deviceHashCode = rgbDevice.GetDeviceHashCode();
|
||||
var device = surface.Devices.FirstOrDefault(d => d.DeviceEntity.DeviceHashCode == deviceHashCode);
|
||||
@@ -185,7 +185,7 @@ namespace Artemis.Core.Services.Storage
|
||||
if (existingDeviceConfig != null)
|
||||
{
|
||||
var plugin = _pluginService.GetDevicePlugin(rgbDevice);
|
||||
device = new Device(rgbDevice, plugin, surface, existingDeviceConfig);
|
||||
device = new ArtemisDevice(rgbDevice, plugin, surface, existingDeviceConfig);
|
||||
}
|
||||
// Fall back on creating a new device
|
||||
else
|
||||
@@ -196,7 +196,7 @@ namespace Artemis.Core.Services.Storage
|
||||
deviceHashCode
|
||||
);
|
||||
var plugin = _pluginService.GetDevicePlugin(rgbDevice);
|
||||
device = new Device(rgbDevice, plugin, surface);
|
||||
device = new ArtemisDevice(rgbDevice, plugin, surface);
|
||||
}
|
||||
|
||||
surface.Devices.Add(device);
|
||||
|
||||
Reference in new issue
Block a user