cruelman/CruelMan/Modules/ModuleManager.cs

64 lines
2.1 KiB
C#
Raw Normal View History

2024-01-20 13:52:41 +01:00
using System.Collections.Generic;
using UnityEngine;
namespace CruelMan.Modules {
public class ModuleManager : MonoBehaviour {
public static ModuleManager instance;
public List<Module> modules = new List<Module>();
public void Awake() {
instance = this;
AddModules();
2024-01-22 19:25:38 +01:00
new Terminal.ConsoleCommand($"cmbind", "binds a module to a key", delegate (Terminal.ConsoleEventArgs args) {
if (args.Args.Length < 2) {
args.Context.AddString("Usage: cmbind <module> <key>");
return;
}
string module = args.Args[1];
string key = args.Args[2];
foreach (Module m in modules) {
if (m.Command == module.ToLower()) {
m.bind = (KeyCode)System.Enum.Parse(typeof(KeyCode), key);
args.Context.AddString($"Bound {module} to {key}");
return;
}
}
args.Context.AddString($"Module {module} not found");
});
2024-01-20 13:52:41 +01:00
}
public void Update() {
foreach (Module module in modules) {
module.Update();
}
}
private void AddModules() {
AddModule<NoDeath>();
AddModule<Menu>();
AddModule<AddStamina>();
AddModule<InfCarry>();
AddModule<GuardianPowers>();
AddModule<NotInAttack>();
AddModule<Speed>();
AddModule<JumpHeight>();
AddModule<InstantDmg>();
2024-01-22 19:25:38 +01:00
AddModule<SwimSpeed>();
2024-01-20 13:52:41 +01:00
}
private void AddModule<T>() where T : Module, new() {
T module = new T();
module.Register();
}
public T GetModule<T>() where T : Module, new() {
foreach (Module module in modules) {
if (module is T) {
return (T)module;
}
}
throw new System.Exception("Module not found");
}
}
}