Rename IPlugin to IComponent

This commit is contained in:
Alessandro Proto 2023-02-16 18:43:10 +01:00
parent dba8f8c600
commit 9dd01041d0
21 changed files with 30 additions and 37 deletions

View file

@ -18,7 +18,7 @@ using Microsoft.Extensions.DependencyInjection;
namespace Capy64.API;
public interface IPlugin
public interface IComponent
{
void ConfigureServices(IServiceCollection services) { }
void LuaInit(Lua L) { }

View file

@ -41,8 +41,8 @@ public class Capy64 : Game, IGame
"Capy64");
public static Capy64 Instance { get; private set; }
public Capy64 Game => this;
public IList<IPlugin> NativePlugins { get; private set; }
public IList<IPlugin> Plugins { get; private set; }
public IList<IComponent> NativePlugins { get; private set; }
public IList<IComponent> Plugins { get; private set; }
public int Width { get; set; } = 400;
public int Height { get; set; } = 300;
public float Scale { get; set; } = 2f;
@ -159,18 +159,18 @@ public class Capy64 : Game, IGame
base.Initialize();
}
private List<IPlugin> GetNativePlugins()
private List<IComponent> GetNativePlugins()
{
var iType = typeof(IPlugin);
var iType = typeof(IComponent);
var types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => iType.IsAssignableFrom(p) && !p.IsInterface);
var plugins = new List<IPlugin>();
var plugins = new List<IComponent>();
foreach (var type in types)
{
var instance = (IPlugin)ActivatorUtilities.CreateInstance(_serviceProvider, type)!;
var instance = (IComponent)ActivatorUtilities.CreateInstance(_serviceProvider, type)!;
plugins.Add(instance);
}
return plugins;

View file

@ -27,8 +27,8 @@ namespace Capy64;
public interface IGame
{
Capy64 Game { get; }
IList<IPlugin> NativePlugins { get; }
IList<IPlugin> Plugins { get; }
IList<IComponent> NativePlugins { get; }
IList<IComponent> Plugins { get; }
GameWindow Window { get; }
Drawing Drawing { get; }
Audio Audio { get; }

View file

@ -27,7 +27,7 @@ using System.Threading.Tasks;
namespace Capy64.Integrations;
public class DiscordIntegration : IPlugin
public class DiscordIntegration : IComponent
{
public DiscordRpcClient Client { get; private set; }
private readonly IConfiguration _configuration;

View file

@ -33,21 +33,21 @@ internal class PluginLoader
return loadContext.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(path)));
}
public static List<IPlugin> LoadAllPlugins(string pluginsPath, IServiceProvider provider)
public static List<IComponent> LoadAllPlugins(string pluginsPath, IServiceProvider provider)
{
if (!Directory.Exists(pluginsPath))
Directory.CreateDirectory(pluginsPath);
var plugins = new List<IPlugin>();
var plugins = new List<IComponent>();
foreach (var fileName in Directory.GetFiles(pluginsPath).Where(q => q.EndsWith(".dll")))
{
var assembly = LoadPlugin(fileName);
foreach (Type type in assembly.GetTypes())
{
if (typeof(IPlugin).IsAssignableFrom(type))
if (typeof(IComponent).IsAssignableFrom(type))
{
IPlugin result = ActivatorUtilities.CreateInstance(provider, type) as IPlugin;
IComponent result = ActivatorUtilities.CreateInstance(provider, type) as IComponent;
plugins.Add(result);
}
}

View file

@ -22,7 +22,7 @@ using static Capy64.Core.Audio;
namespace Capy64.Runtime.Libraries;
public class Audio : IPlugin
public class Audio : IComponent
{
private const int queueLimit = 8;

View file

@ -23,7 +23,7 @@ using System.Threading.Tasks;
namespace Capy64.Runtime.Libraries;
public class Event : IPlugin
public class Event : IComponent
{
private static IGame _game;
public Event(IGame game)

View file

@ -25,7 +25,7 @@ using Capy64.Runtime.Objects;
namespace Capy64.Runtime.Libraries;
public class FileSystem : IPlugin
public class FileSystem : IComponent
{
public static string DataPath = Path.Combine(Capy64.AppDataPath, "data");

View file

@ -24,7 +24,7 @@ using System.IO;
namespace Capy64.Runtime.Libraries;
public class GPU : IPlugin
public class GPU : IComponent
{
private static IGame _game;

View file

@ -28,7 +28,7 @@ using System.Threading;
namespace Capy64.Runtime.Libraries;
#nullable enable
public class HTTP : IPlugin
public class HTTP : IComponent
{
private static IGame _game;
private static HttpClient _httpClient;

View file

@ -25,7 +25,7 @@ using System.Threading.Tasks;
namespace Capy64.Runtime.Libraries;
public class Machine : IPlugin
public class Machine : IComponent
{
private static IGame _game;
public Machine(IGame game)
@ -103,13 +103,6 @@ public class Machine : IPlugin
if (!L.IsNoneOrNil(1))
{
var newTitle = L.CheckString(1);
if (string.IsNullOrEmpty(newTitle))
{
newTitle = "Capy64 " + Capy64.Version;
}
newTitle = newTitle[..Math.Min(newTitle.Length, 256)];
Capy64.Instance.Window.Title = newTitle;
}

View file

@ -19,7 +19,7 @@ using System;
namespace Capy64.Runtime.Libraries;
public class OS : IPlugin
public class OS : IComponent
{
private static IGame _game;
public OS(IGame game)

View file

@ -26,7 +26,7 @@ using static System.Formats.Asn1.AsnWriter;
namespace Capy64.Runtime.Libraries;
internal class Term : IPlugin
internal class Term : IComponent
{
private struct Char
{

View file

@ -21,7 +21,7 @@ using System.Collections.Generic;
namespace Capy64.Runtime.Libraries;
class Timer : IPlugin
class Timer : IComponent
{
private LuaRegister[] TimerLib = new LuaRegister[]
{

View file

@ -75,7 +75,7 @@ public class LuaState : IDisposable
private void InitPlugins()
{
var allPlugins = new List<IPlugin>(Capy64.Instance.NativePlugins);
var allPlugins = new List<IComponent>(Capy64.Instance.NativePlugins);
allPlugins.AddRange(Capy64.Instance.Plugins);
foreach (var plugin in allPlugins)
{

View file

@ -26,7 +26,7 @@ using System.Threading.Tasks;
namespace Capy64.Runtime;
public class ObjectManager : IPlugin
public class ObjectManager : IComponent
{
private static ConcurrentDictionary<nint, object> _objects = new();

View file

@ -24,7 +24,7 @@ using System.Threading.Tasks;
namespace Capy64.Runtime.Objects;
public class FileHandle : IPlugin
public class FileHandle : IComponent
{
public const string ObjectType = "file";

View file

@ -20,7 +20,7 @@ using System.IO;
namespace Capy64.Runtime.Objects;
public class GPUBuffer : IPlugin
public class GPUBuffer : IComponent
{
public const string ObjectType = "GPUBuffer";

View file

@ -23,7 +23,7 @@ using System.Threading;
namespace Capy64.Runtime.Objects;
public class WebSocketClient : IPlugin
public class WebSocketClient : IComponent
{
public const string ObjectType = "WebSocketClient";

View file

@ -30,7 +30,7 @@ using System.Threading.Tasks;
namespace Capy64.Runtime;
internal class RuntimeManager : IPlugin
internal class RuntimeManager : IComponent
{
private LuaState luaState;
private EventEmitter emitter;

View file

@ -4,7 +4,7 @@ using KeraLua;
namespace ExamplePlugin;
public class MyPlugin : IPlugin
public class MyPlugin : IComponent
{
private static IGame _game;
public MyPlugin(IGame game)