Replace the legacy EventBase runtime with generated multi-bus bindings and explicit scheduling. Migrate app, data, network, demo, and mod consumers; add generated network-event registration and owner-scoped mod content overrides.
57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace ShrinkModFramework
|
|
{
|
|
public sealed class ShrinkModRegistryManager
|
|
{
|
|
private readonly Dictionary<string, object> _registries = new();
|
|
|
|
public IReadOnlyShrinkModRegistry<T> GetOrCreateRegistry<T>(string name) =>
|
|
GetOrCreateMutableRegistry<T>(name);
|
|
|
|
internal ShrinkModRegistry<T> GetOrCreateMutableRegistry<T>(string name)
|
|
{
|
|
var compositeKey = BuildCompositeKey(typeof(T), name);
|
|
if (_registries.TryGetValue(compositeKey, out var existing))
|
|
return (ShrinkModRegistry<T>)existing;
|
|
|
|
var registry = new ShrinkModRegistry<T>(name);
|
|
_registries.Add(compositeKey, registry);
|
|
return registry;
|
|
}
|
|
|
|
public bool TryGetRegistry<T>(string name, out IReadOnlyShrinkModRegistry<T> registry)
|
|
{
|
|
var compositeKey = BuildCompositeKey(typeof(T), name);
|
|
if (_registries.TryGetValue(compositeKey, out var existing))
|
|
{
|
|
registry = (ShrinkModRegistry<T>)existing;
|
|
return true;
|
|
}
|
|
|
|
registry = null;
|
|
return false;
|
|
}
|
|
|
|
internal void Clear() => _registries.Clear();
|
|
|
|
internal void RemoveOwnedEntries(string ownerModId)
|
|
{
|
|
foreach (var registry in _registries.Values)
|
|
{
|
|
if (registry is IShrinkOwnedRegistry ownedRegistry)
|
|
ownedRegistry.RemoveOwnedEntries(ownerModId);
|
|
}
|
|
}
|
|
|
|
private static string BuildCompositeKey(Type type, string name)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(name))
|
|
throw new ArgumentException("注册表名称不能为空。", nameof(name));
|
|
|
|
return $"{type.AssemblyQualifiedName}::{name.Trim()}";
|
|
}
|
|
}
|
|
}
|