Plugins - Fixed GetFeature<T> always returning null

Plugins - Added AlwaysEnabled property to [PluginFeature] attribute
This commit is contained in:
Robert committed 2021-03-26 19:39:48 +01:00
1 parent 0a7c724de0
commit 5545bdb783
7 files changed
+72 -19

No files matched your search

+6 -1
View File
@@ -107,7 +107,7 @@ namespace Artemis.Core
/// <returns>If found, the instance of the feature</returns>
public T? GetFeature<T>() where T : PluginFeature
{
return _features.FirstOrDefault(i => i.Instance is T) as T;
return _features.FirstOrDefault(i => i.Instance is T)?.Instance as T;
}
/// <inheritdoc />
@@ -164,6 +164,11 @@ namespace Artemis.Core
}
}
internal bool HasEnabledFeatures()
{
return Entity.Features.Any(f => f.IsEnabled) || Features.Any(f => f.AlwaysEnabled);
}
#region IDisposable
/// <summary>
@@ -23,5 +23,10 @@ namespace Artemis.Core
/// available icons
/// </summary>
public string? Icon { get; set; }
/// <summary>
/// Marks the feature to always be enabled as long as the plugin is enabled
/// </summary>
public bool AlwaysEnabled { get; set; }
}
}
}
@@ -28,7 +28,8 @@ namespace Artemis.Core
Name = attribute?.Name ?? featureType.Name.Humanize(LetterCasing.Title);
Description = attribute?.Description;
Icon = attribute?.Icon;
AlwaysEnabled = attribute?.AlwaysEnabled ?? false;
if (Icon != null) return;
if (typeof(BaseDataModelExpansion).IsAssignableFrom(featureType))
Icon = "TableAdd";
@@ -55,6 +56,7 @@ namespace Artemis.Core
Name = attribute?.Name ?? instance.GetType().Name.Humanize(LetterCasing.Title);
Description = attribute?.Description;
Icon = attribute?.Icon;
AlwaysEnabled = attribute?.AlwaysEnabled ?? false;
Instance = instance;
if (Icon != null) return;
@@ -111,6 +113,12 @@ namespace Artemis.Core
set => SetAndNotify(ref _icon, value);
}
/// <summary>
/// Marks the feature to always be enabled as long as the plugin is enabled and cannot be disabled
/// </summary>
[JsonProperty]
public bool AlwaysEnabled { get; }
/// <summary>
/// Gets the feature this info is associated with
/// </summary>