update: 更新到godot4.4.1,并大量重构代码

This commit is contained in:
ZZY
2025-06-09 18:17:06 +08:00
parent b27abb55a2
commit 3fa39fc71e
39 changed files with 801 additions and 790 deletions

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
class ModManager {
private readonly Dictionary<string, Delegate> _api = [];
private readonly Dictionary<string, Delegate> _hooks = [];
public delegate bool OnCallback(params object[] args);
private readonly Dictionary<string, List<OnCallback>> _callbackList = [];
public ReadOnlyDictionary<string, Delegate> GetAPIs() => new(_api);
public ReadOnlyDictionary<string, Delegate> GetHooks() => new(_hooks);
public ModManager RegistryFunc<TDelegate>(string name, TDelegate handler, bool isHook = false)
where TDelegate : Delegate {
MethodInfo _ = handler.Method;
Dictionary<string, Delegate> dict = isHook ? _hooks : _api;
dict.Add(name, handler);
return this;
}
public bool AddHook(string name, OnCallback handler) {
if (_hooks.ContainsKey(name)) {
if (!_callbackList.TryGetValue(name, out var list)) {
list = [];
_callbackList[name] = list;
}
list.Add(handler);
return true;
}
return false;
}
public bool InvokeFunc<TDelegate>(string name, params object[] args)
where TDelegate : Delegate {
List<object> res = [];
if (_callbackList.TryGetValue(name, out var callback)) {
foreach (var func in callback) {
func?.Invoke(args);
}
}
return true;
}
}