Further expanded plugins

Added navigation between modules
This commit is contained in:
SpoinkyNL committed 2018-02-25 19:48:22 +01:00
1 parent 4781524139
commit aada338dcc
21 files changed
+1193 -163

No files matched your search

+22 -1
View File
@@ -1,7 +1,10 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Core.Exceptions;
using Artemis.Core.Services.Interfaces;
using Artemis.Plugins.Interfaces;
using RGB.NET.Core;
namespace Artemis.Core.Services
{
@@ -14,6 +17,7 @@ namespace Artemis.Core.Services
{
_pluginService = pluginService;
_rgbService = rgbService;
_rgbService.Surface.Updating += SurfaceOnUpdating;
Task.Run(Initialize);
}
@@ -34,10 +38,27 @@ namespace Artemis.Core.Services
// Initialize the services
await _pluginService.LoadPlugins();
await _rgbService.LoadDevices();
OnInitialized();
}
private void SurfaceOnUpdating(UpdatingEventArgs args)
{
try
{
// Update all active modules
foreach (var module in _pluginService.Plugins.OfType<IModule>())
module.Update(args.DeltaTime);
// Render all active modules
foreach (var module in _pluginService.Plugins.OfType<IModule>())
module.Render(args.DeltaTime);
}
catch (Exception e)
{
throw new ArtemisCoreException("Exception during update", e);
}
}
#region Events
public event EventHandler Initialized;
@@ -9,17 +9,32 @@ namespace Artemis.Core.Services.Interfaces
{
public interface IPluginService : IArtemisService, IDisposable
{
/// <summary>
/// Indicates wether or not plugins are currently being loaded
/// </summary>
bool LoadingPlugins { get; }
/// <summary>
/// All loaded plugins
/// </summary>
ReadOnlyCollection<PluginInfo> Plugins { get; }
/// <summary>
/// Loads all installed plugins. If plugins already loaded this will reload them all
/// </summary>
/// <returns></returns>
Task LoadPlugins();
/// <summary>
/// Reloads the plugin accompanying the provided plugin info
/// </summary>
/// <param name="pluginInfo">The plugin info containing the plugin to reload</param>
Task ReloadPlugin(PluginInfo pluginInfo);
Task<IPluginViewModel> GetPluginViewModel(PluginInfo pluginInfo);
/// <summary>
/// Gets the view model of the module accompanying the provided plugin info
/// </summary>
/// <param name="pluginInfo">The plugin info containing the module for which to load the view model</param>
Task<IModuleViewModel> GetModuleViewModel(PluginInfo pluginInfo);
/// <summary>
/// Occurs when a single plugin has loaded
+9 -24
View File
@@ -33,10 +33,6 @@ namespace Artemis.Core.Services
public ReadOnlyCollection<PluginInfo> Plugins => _plugins.AsReadOnly();
/// <inheritdoc />
/// <summary>
/// Loads all installed plugins. If plugins already loaded this will reload them all
/// </summary>
/// <returns></returns>
public async Task LoadPlugins()
{
if (LoadingPlugins)
@@ -56,18 +52,22 @@ namespace Artemis.Core.Services
public async Task ReloadPlugin(PluginInfo pluginInfo)
{
throw new NotImplementedException();
}
public async Task<IPluginViewModel> GetPluginViewModel(PluginInfo pluginInfo)
public async Task<IModuleViewModel> GetModuleViewModel(PluginInfo pluginInfo)
{
// Don't attempt to locave VMs for something other than a module
if (pluginInfo.Plugin is IModule)
throw new ArtemisPluginException(pluginInfo, "Cannot locate a view model for this plugin as it's not a module.");
// Compile the ViewModel and get the type
var compile = await Task.Run(() => CSScript.LoadFile(pluginInfo.Folder + pluginInfo.ViewModel));
var vmType = compile.ExportedTypes.FirstOrDefault(t => typeof(IPluginViewModel).IsAssignableFrom(t));
var vmType = compile.ExportedTypes.FirstOrDefault(t => typeof(IModuleViewModel).IsAssignableFrom(t));
if (vmType == null)
throw new ArtemisPluginException(pluginInfo, "Cannot locate a view model for this plugin.");
throw new ArtemisPluginException(pluginInfo, "Cannot locate a view model for this module.");
// Instantiate the ViewModel with Ninject
var vm = (IPluginViewModel) _kernel.Get(vmType);
var vm = (IModuleViewModel) _kernel.Get(vmType);
vm.PluginInfo = pluginInfo;
return vm;
}
@@ -94,25 +94,10 @@ namespace Artemis.Core.Services
}
#region Events
/// <summary>
/// Occurs when a single plugin has loaded
/// </summary>
public event EventHandler<PluginEventArgs> PluginLoaded;
/// <summary>
/// Occurs when a single plugin has reloaded
/// </summary>
public event EventHandler<PluginEventArgs> PluginReloaded;
/// <summary>
/// Occurs when loading all plugins has started
/// </summary>
public event EventHandler StartedLoadingPlugins;
/// <summary>
/// Occurs when loading all plugins has finished
/// </summary>
public event EventHandler FinishedLoadedPlugins;
private void OnPluginLoaded(PluginEventArgs e)