From b7a4333e2d39a2362c6d933996bcccd87748d718 Mon Sep 17 00:00:00 2001 From: That-One-Nerd Date: Mon, 17 Apr 2023 20:27:40 -0400 Subject: [PATCH] Added the ability to load custom assemblies to the shell. --- SrcMod/Shell/Shell.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/SrcMod/Shell/Shell.cs b/SrcMod/Shell/Shell.cs index 3a90b88..8516305 100644 --- a/SrcMod/Shell/Shell.cs +++ b/SrcMod/Shell/Shell.cs @@ -95,6 +95,26 @@ public class Shell ReloadDirectoryInfo(); } + public bool LoadModule(Type moduleType) + { + if (LoadedModules.Any(x => x.Type.FullName == moduleType.FullName)) return false; + + ModuleInfo? module = ModuleInfo.FromType(moduleType); + if (module is null) return false; + + LoadedModules.Add(module); + LoadedCommands.AddRange(module.Commands); + + return true; + } + public bool LoadModule() => LoadModule(typeof(T)); + public int LoadModules(Assembly moduleAssembly) + { + int loaded = 0; + foreach (Type moduleType in moduleAssembly.GetTypes()) if (LoadModule(moduleType)) loaded++; + return loaded; + } + public void AddHistory(HistoryItem item) => History.Add(item); public void UndoItem() {