mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user