Profiles - Reworked profile system

Sidebar - Redesigned sidebar with customizable categories
Profiles - Added the ability to configure custom profile icons
Profiles - Added the ability to activate multiple profiles for modules at once
Profiles - Added the ability to create profiles for no modules
Profiles - Added the ability to suspend a profile or an entire category
Profiles - Added profile activation conditions
Profiles - Added file-based importing/exporting
Profile editor - Condensed UI, removed tabs 
Profile editor - Disable condition operators until a left-side is picked
This commit is contained in:
Robert Beekman authored and GitHub committed 2021-06-03 22:34:43 +02:00
1 parent 4152c290d2
commit ceeaa4bf6d
164 files changed
+5019 -4220

No files matched your search

@@ -0,0 +1,210 @@
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Modules;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core
{
public class ProfileConfiguration : CorePropertyChanged, IStorageModel
{
private ProfileCategory _category;
private bool _isMissingModule;
private bool _isSuspended;
private Module? _module;
private string _name;
private int _order;
private Profile? _profile;
internal ProfileConfiguration(ProfileCategory category, string name, string icon)
{
_name = name;
_category = category;
Entity = new ProfileConfigurationEntity();
Icon = new ProfileConfigurationIcon(Entity) {MaterialIcon = icon};
}
internal ProfileConfiguration(ProfileCategory category, ProfileConfigurationEntity entity)
{
// Will be loaded from the entity
_name = null!;
_category = category;
Entity = entity;
Icon = new ProfileConfigurationIcon(Entity);
Load();
}
/// <summary>
/// Gets or sets the name of this profile configuration
/// </summary>
public string Name
{
get => _name;
set => SetAndNotify(ref _name, value);
}
/// <summary>
/// The order in which this profile appears in the update loop and sidebar
/// </summary>
public int Order
{
get => _order;
set => SetAndNotify(ref _order, value);
}
/// <summary>
/// Gets or sets a boolean indicating whether this profile is suspended, disabling it regardless of the
/// <see cref="ActivationCondition" />
/// </summary>
public bool IsSuspended
{
get => _isSuspended;
set => SetAndNotify(ref _isSuspended, value);
}
/// <summary>
/// Gets a boolean indicating whether this profile configuration is missing any modules
/// </summary>
public bool IsMissingModule
{
get => _isMissingModule;
private set => SetAndNotify(ref _isMissingModule, value);
}
/// <summary>
/// Gets or sets the category of this profile configuration
/// </summary>
public ProfileCategory Category
{
get => _category;
internal set => SetAndNotify(ref _category, value);
}
/// <summary>
/// Gets the icon configuration
/// </summary>
public ProfileConfigurationIcon Icon { get; }
/// <summary>
/// Gets the profile of this profile configuration
/// </summary>
public Profile? Profile
{
get => _profile;
internal set => SetAndNotify(ref _profile, value);
}
/// <summary>
/// Gets or sets the behaviour of when this profile is activated
/// </summary>
public ActivationBehaviour ActivationBehaviour { get; set; }
/// <summary>
/// Gets the data model condition that must evaluate to <see langword="true" /> for this profile to be activated
/// alongside any activation requirements of the <see cref="Module" />, if set
/// </summary>
public DataModelConditionGroup? ActivationCondition { get; set; }
/// <summary>
/// Gets or sets the module this profile uses
/// </summary>
public Module? Module
{
get => _module;
set
{
_module = value;
IsMissingModule = false;
}
}
/// <summary>
/// Gets a boolean indicating whether the activation conditions where met during the last <see cref="Update" /> call
/// </summary>
public bool ActivationConditionMet { get; private set; }
/// <summary>
/// Gets or sets a boolean indicating whether this profile configuration is being edited
/// </summary>
public bool IsBeingEdited { get; set; }
/// <summary>
/// Gets the entity used by this profile config
/// </summary>
public ProfileConfigurationEntity Entity { get; }
/// <summary>
/// Updates this configurations activation condition status
/// </summary>
public void Update()
{
ActivationConditionMet = ActivationCondition == null || ActivationCondition.Evaluate();
}
public bool ShouldBeActive(bool includeActivationCondition)
{
if (Category.IsSuspended || IsSuspended || IsMissingModule)
return false;
if (includeActivationCondition)
return ActivationConditionMet && (Module == null || Module.IsActivated);
return Module == null || Module.IsActivated;
}
/// <inheritdoc />
public override string ToString()
{
return $"[ProfileConfiguration] {nameof(Name)}: {Name}";
}
internal void LoadModules(List<Module> enabledModules)
{
Module = enabledModules.FirstOrDefault(m => m.Id == Entity.ModuleId);
IsMissingModule = Module == null && Entity.ModuleId != null;
}
#region Implementation of IStorageModel
/// <inheritdoc />
public void Load()
{
Name = Entity.Name;
IsSuspended = Entity.IsSuspended;
ActivationBehaviour = (ActivationBehaviour) Entity.ActivationBehaviour;
Icon.Load();
ActivationCondition = Entity.ActivationCondition != null
? new DataModelConditionGroup(null, Entity.ActivationCondition)
: null;
}
/// <inheritdoc />
public void Save()
{
Entity.Name = Name;
Entity.IsSuspended = IsSuspended;
Entity.ActivationBehaviour = (int) ActivationBehaviour;
Entity.ProfileCategoryId = Category.Entity.Id;
Icon.Save();
if (ActivationCondition != null)
{
ActivationCondition.Save();
Entity.ActivationCondition = ActivationCondition.Entity;
}
else
{
Entity.ActivationCondition = null;
}
if (!IsMissingModule)
Entity.ModuleId = Module?.Id;
}
#endregion
}
}
@@ -0,0 +1,30 @@
using System.IO;
using Artemis.Core.JsonConverters;
using Artemis.Storage.Entities.Profile;
using Newtonsoft.Json;
namespace Artemis.Core
{
/// <summary>
/// A model that can be used to serialize a profile configuration, it's profile and it's icon
/// </summary>
public class ProfileConfigurationExportModel
{
/// <summary>
/// Gets or sets the storage entity of the profile configuration
/// </summary>
public ProfileConfigurationEntity? ProfileConfigurationEntity { get; set; }
/// <summary>
/// Gets or sets the storage entity of the profile
/// </summary>
[JsonProperty(Required = Required.Always)]
public ProfileEntity ProfileEntity { get; set; } = null!;
/// <summary>
/// Gets or sets a stream containing the profile image
/// </summary>
[JsonConverter(typeof(StreamConverter))]
public Stream? ProfileImage { get; set; }
}
}
@@ -0,0 +1,89 @@
using System.ComponentModel;
using System.IO;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core
{
/// <summary>
/// Represents the icon of a <see cref="ProfileConfiguration" />
/// </summary>
public class ProfileConfigurationIcon : CorePropertyChanged, IStorageModel
{
private readonly ProfileConfigurationEntity _entity;
private Stream? _fileIcon;
private ProfileConfigurationIconType _iconType;
private string? _materialIcon;
internal ProfileConfigurationIcon(ProfileConfigurationEntity entity)
{
_entity = entity;
}
/// <summary>
/// Gets or sets the type of icon this profile configuration uses
/// </summary>
public ProfileConfigurationIconType IconType
{
get => _iconType;
set => SetAndNotify(ref _iconType, value);
}
/// <summary>
/// Gets or sets the icon if it is a Material icon
/// </summary>
public string? MaterialIcon
{
get => _materialIcon;
set => SetAndNotify(ref _materialIcon, value);
}
/// <summary>
/// Gets or sets a stream containing the icon if it is bitmap or SVG
/// </summary>
/// <returns></returns>
public Stream? FileIcon
{
get => _fileIcon;
set => SetAndNotify(ref _fileIcon, value);
}
#region Implementation of IStorageModel
/// <inheritdoc />
public void Load()
{
IconType = (ProfileConfigurationIconType) _entity.IconType;
MaterialIcon = _entity.MaterialIcon;
}
/// <inheritdoc />
public void Save()
{
_entity.IconType = (int) IconType;
_entity.MaterialIcon = MaterialIcon;
}
#endregion
}
/// <summary>
/// Represents a type of profile icon
/// </summary>
public enum ProfileConfigurationIconType
{
/// <summary>
/// An icon picked from the Material Design Icons collection
/// </summary>
[Description("Material Design Icon")] MaterialIcon,
/// <summary>
/// A bitmap image icon
/// </summary>
[Description("Bitmap Image")] BitmapImage,
/// <summary>
/// An SVG image icon
/// </summary>
[Description("SVG Image")] SvgImage
}
}