mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Redid some of the surface editor and started working on layout saving
This commit is contained in:
1 parent
f3650445d9
commit
a34786fb5d
48 files changed
+1012
-107
No files matched your search
@@ -0,0 +1,60 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Models.Profile.Interfaces;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Models.Profile.Interfaces;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models.Profile.Interfaces;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Storage.Entities;
|
||||
|
||||
namespace Artemis.Core.Models.Surface
|
||||
{
|
||||
public class SurfaceConfiguration
|
||||
{
|
||||
public SurfaceConfiguration(string name)
|
||||
{
|
||||
Name = name;
|
||||
DeviceConfigurations = new List<SurfaceDeviceConfiguration>();
|
||||
}
|
||||
|
||||
internal SurfaceConfiguration(SurfaceEntity surfaceEntity)
|
||||
{
|
||||
Guid = surfaceEntity.Guid;
|
||||
Name = surfaceEntity.Name;
|
||||
IsActive = surfaceEntity.IsActive;
|
||||
DeviceConfigurations = new List<SurfaceDeviceConfiguration>();
|
||||
|
||||
if (surfaceEntity.SurfacePositions == null)
|
||||
return;
|
||||
foreach (var position in surfaceEntity.SurfacePositions)
|
||||
DeviceConfigurations.Add(new SurfaceDeviceConfiguration(position, this));
|
||||
}
|
||||
|
||||
internal string Guid { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public List<SurfaceDeviceConfiguration> DeviceConfigurations { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using Artemis.Storage.Entities;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Models.Surface
|
||||
{
|
||||
public class SurfaceDeviceConfiguration
|
||||
{
|
||||
internal SurfaceDeviceConfiguration(int deviceId, IRGBDeviceInfo deviceInfo, SurfaceConfiguration surface)
|
||||
{
|
||||
DeviceId = deviceId;
|
||||
DeviceName = deviceInfo.DeviceName;
|
||||
DeviceModel = deviceInfo.Model;
|
||||
DeviceManufacturer = deviceInfo.Manufacturer;
|
||||
|
||||
Surface = surface;
|
||||
}
|
||||
|
||||
internal SurfaceDeviceConfiguration(SurfacePositionEntity position, SurfaceConfiguration surfaceConfiguration)
|
||||
{
|
||||
Guid = position.Guid;
|
||||
|
||||
DeviceId = position.DeviceId;
|
||||
DeviceName = position.DeviceName;
|
||||
DeviceModel = position.DeviceModel;
|
||||
DeviceManufacturer = position.DeviceManufacturer;
|
||||
|
||||
X = position.X;
|
||||
Y = position.Y;
|
||||
Rotation = position.Rotation;
|
||||
|
||||
Surface = surfaceConfiguration;
|
||||
}
|
||||
|
||||
internal string Guid { get; set; }
|
||||
|
||||
public int DeviceId { get; set; }
|
||||
public string DeviceName { get; set; }
|
||||
public string DeviceModel { get; set; }
|
||||
public string DeviceManufacturer { get; set; }
|
||||
|
||||
public double X { get; set; }
|
||||
public double Y { get; set; }
|
||||
public double Rotation { get; set; }
|
||||
|
||||
public SurfaceConfiguration Surface { get; internal set; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user