mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Display conditions - Added basic models
Display conditions - Added externally registerable condition operators Display conditions - Added GreaterThan condition for testing
This commit is contained in:
1 parent
448d94915c
commit
f9d26a8ba3
12 files changed
+248
-10
No files matched your search
@@ -1,11 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models.Profile.Conditions;
|
||||
using Artemis.Core.Models.Profile.Conditions.Operators;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.Core.Plugins.Exceptions;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
@@ -17,15 +21,19 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
private readonly List<DataModel> _dataModelExpansions;
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly List<LayerConditionOperator> _registeredConditionOperators;
|
||||
|
||||
internal DataModelService(IPluginService pluginService)
|
||||
{
|
||||
_pluginService = pluginService;
|
||||
_dataModelExpansions = new List<DataModel>();
|
||||
_registeredConditionOperators = new List<LayerConditionOperator>();
|
||||
|
||||
_pluginService.PluginEnabled += PluginServiceOnPluginEnabled;
|
||||
_pluginService.PluginDisabled += PluginServiceOnPluginDisabled;
|
||||
|
||||
RegisterBuiltInConditionOperators();
|
||||
|
||||
foreach (var module in _pluginService.GetPluginsOfType<Module>().Where(m => m.InternalExpandsMainDataModel))
|
||||
AddModuleDataModel(module);
|
||||
foreach (var dataModelExpansion in _pluginService.GetPluginsOfType<BaseDataModelExpansion>())
|
||||
@@ -73,6 +81,52 @@ namespace Artemis.Core.Services
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void RegisterConditionOperator(PluginInfo pluginInfo, LayerConditionOperator layerConditionOperator)
|
||||
{
|
||||
if (pluginInfo == null)
|
||||
throw new ArgumentNullException(nameof(pluginInfo));
|
||||
if (layerConditionOperator == null)
|
||||
throw new ArgumentNullException(nameof(layerConditionOperator));
|
||||
|
||||
lock (_registeredConditionOperators)
|
||||
{
|
||||
if (_registeredConditionOperators.Contains(layerConditionOperator))
|
||||
return;
|
||||
|
||||
layerConditionOperator.Register(pluginInfo, this);
|
||||
_registeredConditionOperators.Add(layerConditionOperator);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveConditionOperator(LayerConditionOperator layerConditionOperator)
|
||||
{
|
||||
if (layerConditionOperator == null)
|
||||
throw new ArgumentNullException(nameof(layerConditionOperator));
|
||||
|
||||
lock (_registeredConditionOperators)
|
||||
{
|
||||
if (!_registeredConditionOperators.Contains(layerConditionOperator))
|
||||
return;
|
||||
|
||||
layerConditionOperator.Unsubscribe();
|
||||
_registeredConditionOperators.Remove(layerConditionOperator);
|
||||
}
|
||||
}
|
||||
|
||||
public List<LayerConditionOperator> GetCompatibleConditionOperators(Type type)
|
||||
{
|
||||
lock (_registeredConditionOperators)
|
||||
{
|
||||
return _registeredConditionOperators.Where(c => c.CompatibleTypes.Contains(type)).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterBuiltInConditionOperators()
|
||||
{
|
||||
RegisterConditionOperator(Constants.CorePluginInfo, new GreaterThanConditionOperator());
|
||||
}
|
||||
|
||||
private void PluginServiceOnPluginEnabled(object sender, PluginEventArgs e)
|
||||
{
|
||||
if (e.PluginInfo.Instance is Module module && module.InternalExpandsMainDataModel)
|
||||
@@ -85,7 +139,7 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
if (dataModelExpansion.InternalDataModel.DataModelDescription == null)
|
||||
throw new ArtemisPluginException(dataModelExpansion.PluginInfo, "Data model expansion overrides GetDataModelDescription but returned null");
|
||||
|
||||
|
||||
AddExpansion(dataModelExpansion.InternalDataModel);
|
||||
}
|
||||
|
||||
@@ -93,7 +147,7 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
if (module.InternalDataModel.DataModelDescription == null)
|
||||
throw new ArtemisPluginException(module.PluginInfo, "Module overrides GetDataModelDescription but returned null");
|
||||
|
||||
|
||||
AddExpansion(module.InternalDataModel);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Artemis.Core.Models;
|
||||
using Artemis.Core.Annotations;
|
||||
using Artemis.Core.Models.Profile.Conditions;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
|
||||
namespace Artemis.Core.Services.Interfaces
|
||||
{
|
||||
@@ -22,9 +24,22 @@ namespace Artemis.Core.Services.Interfaces
|
||||
void RemoveExpansion(DataModel baseDataModelExpansion);
|
||||
|
||||
/// <summary>
|
||||
/// If found, returns the data model of the provided plugin
|
||||
/// If found, returns the data model of the provided plugin
|
||||
/// </summary>
|
||||
/// <param name="plugin">Should be a module with a data model or a data model expansion</param>
|
||||
DataModel GetPluginDataModel(Plugin plugin);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a new condition operator for use in layer conditions
|
||||
/// </summary>
|
||||
/// <param name="pluginInfo">The PluginInfo of the plugin this condition operator belongs to</param>
|
||||
/// <param name="layerConditionOperator">The condition operator to register</param>
|
||||
void RegisterConditionOperator([NotNull] PluginInfo pluginInfo, [NotNull] LayerConditionOperator layerConditionOperator);
|
||||
|
||||
/// <summary>
|
||||
/// Removes a condition operator so it is no longer available for use in layer conditions
|
||||
/// </summary>
|
||||
/// <param name="layerConditionOperator">The layer condition operator to remove</param>
|
||||
void RemoveConditionOperator([NotNull] LayerConditionOperator layerConditionOperator);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user