Added some more plugin architecture (modules are now a type of plugin)

This commit is contained in:
SpoinkyNL committed 2018-01-07 14:54:09 +01:00
1 parent 84f21aa044
commit ede07722eb
22 files changed
+122 -122

No files matched your search

+5 -5
View File
@@ -5,24 +5,24 @@ namespace Artemis.Core.Services
{
public class CoreService : ICoreService
{
private readonly IModuleService _moduleService;
private readonly IPluginService _pluginService;
public CoreService(IModuleService moduleService)
public CoreService(IPluginService pluginService)
{
_moduleService = moduleService;
_pluginService = pluginService;
Task.Run(Initialize);
}
public void Dispose()
{
_moduleService.Dispose();
_pluginService.Dispose();
}
public bool IsInitialized { get; set; }
private async Task Initialize()
{
await _moduleService.LoadModules();
await _pluginService.LoadModules();
IsInitialized = true;
}
@@ -1,14 +1,14 @@
using System;
using System.Threading.Tasks;
using Artemis.Core.Events;
using Artemis.Core.Modules.Interfaces;
using Artemis.Plugins.Interfaces;
namespace Artemis.Core.Services.Interfaces
{
public interface IModuleService : IArtemisService, IDisposable
public interface IPluginService : IArtemisService, IDisposable
{
Task LoadModules();
Task ReloadModule(IModule module);
Task ReloadModule(IPlugin plugin);
event EventHandler<ModuleEventArgs> ModuleLoaded;
event EventHandler<ModuleEventArgs> ModuleReloaded;
@@ -6,27 +6,27 @@ using System.Threading.Tasks;
using Artemis.Core.Events;
using Artemis.Core.Exceptions;
using Artemis.Core.Models;
using Artemis.Core.Modules.Interfaces;
using Artemis.Core.Services.Interfaces;
using Artemis.Plugins.Interfaces;
using CSScriptLibrary;
using Newtonsoft.Json;
namespace Artemis.Core.Services
{
public class ModuleService : IModuleService
public class PluginService : IPluginService
{
private readonly List<IModule> _modules;
private readonly List<IPlugin> _modules;
public ModuleService()
public PluginService()
{
_modules = new List<IModule>();
_modules = new List<IPlugin>();
if (!Directory.Exists(Constants.DataFolder + "modules"))
Directory.CreateDirectory(Constants.DataFolder + "modules");
}
public bool LoadingModules { get; private set; }
public ReadOnlyCollection<IModule> Modules => _modules.AsReadOnly();
public ReadOnlyCollection<IPlugin> Modules => _modules.AsReadOnly();
/// <summary>
/// Loads all installed modules. If modules already loaded this will reload them all
@@ -50,7 +50,7 @@ namespace Artemis.Core.Services
OnFinishedLoadedModules();
}
public async Task ReloadModule(IModule module)
public async Task ReloadModule(IPlugin plugin)
{
}
@@ -58,7 +58,7 @@ namespace Artemis.Core.Services
{
}
private async Task<IModule> LoadModuleFromFolder(string folder)
private async Task<IPlugin> LoadModuleFromFolder(string folder)
{
if (!folder.EndsWith("\\"))
folder += "\\";
@@ -67,7 +67,7 @@ namespace Artemis.Core.Services
var moduleInfo = JsonConvert.DeserializeObject<ModuleInfo>(File.ReadAllText(folder + "module.json"));
// Load the main module which will contain a class implementing IModule
var module = await CSScript.Evaluator.LoadFileAsync<IModule>(folder + moduleInfo.MainFile);
var module = await CSScript.Evaluator.LoadFileAsync<IPlugin>(folder + moduleInfo.MainFile);
return module;
}