feat(sdk): migrate to EventBus 2.0
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.
This commit is contained in:
@@ -8,6 +8,16 @@ namespace ShrinkCommand.Integration
|
||||
{
|
||||
public static class ShrinkCommandEventBusBridge
|
||||
{
|
||||
[ShrinkEventSubscriber(OwnerId = "shrink.command", DefaultBus = "game")]
|
||||
private sealed class CommandRequestSubscriber
|
||||
{
|
||||
[ShrinkSubscribe(Priority = ShrinkEventPriority.Lowest)]
|
||||
private UniTask OnExecuteRequest(ShrinkCommandExecuteRequestEvent eventArgs)
|
||||
{
|
||||
return HandleExecuteRequestAsync(eventArgs);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ServiceRegistration
|
||||
{
|
||||
public string ServiceName = ShrinkCommandConstants.DefaultServiceName;
|
||||
@@ -20,7 +30,7 @@ namespace ShrinkCommand.Integration
|
||||
private static readonly object SyncRoot = new();
|
||||
private static readonly Dictionary<string, ServiceRegistration> RegisteredByName = new(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly Dictionary<ShrinkCommandService, ServiceRegistration> RegisteredByService = new();
|
||||
private static bool _initialized;
|
||||
private static IDisposable? _requestHandlerBinding;
|
||||
|
||||
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void ResetStaticState()
|
||||
@@ -37,7 +47,8 @@ namespace ShrinkCommand.Integration
|
||||
|
||||
RegisteredByService.Clear();
|
||||
RegisteredByName.Clear();
|
||||
_initialized = false;
|
||||
_requestHandlerBinding?.Dispose();
|
||||
_requestHandlerBinding = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,17 +124,16 @@ namespace ShrinkCommand.Integration
|
||||
Source = source
|
||||
};
|
||||
|
||||
await EventBus.TriggerEventAsync(requestEvent);
|
||||
await EventBus.PostAsync(requestEvent);
|
||||
return requestEvent.ExecutionResult ?? ShrinkCommandExecutionResult.Failure("没有命令桥处理该请求。");
|
||||
}
|
||||
|
||||
private static void EnsureInitialized()
|
||||
{
|
||||
if (_initialized)
|
||||
if (_requestHandlerBinding != null)
|
||||
return;
|
||||
|
||||
_initialized = true;
|
||||
EventBus.RegisterEvent<ShrinkCommandExecuteRequestEvent>(HandleExecuteRequestAsync, EventPriority.LOWEST);
|
||||
_requestHandlerBinding = EventBus.Attach(new CommandRequestSubscriber());
|
||||
}
|
||||
|
||||
private static async UniTask HandleExecuteRequestAsync(ShrinkCommandExecuteRequestEvent eventArgs)
|
||||
@@ -159,7 +169,7 @@ namespace ShrinkCommand.Integration
|
||||
|
||||
private static void PublishExecuting(ServiceRegistration registration, ShrinkCommandExecutingInfo info)
|
||||
{
|
||||
EventBus.TriggerEvent(new ShrinkCommandExecutingEvent
|
||||
EventBus.Post(new ShrinkCommandExecutingEvent
|
||||
{
|
||||
ServiceName = registration.ServiceName,
|
||||
RawInput = info.RawInput,
|
||||
@@ -174,7 +184,7 @@ namespace ShrinkCommand.Integration
|
||||
{
|
||||
var commandPath = info.Command?.Path ?? string.Empty;
|
||||
var arguments = new Dictionary<string, string>(info.Arguments, StringComparer.OrdinalIgnoreCase);
|
||||
EventBus.TriggerEvent(new ShrinkCommandExecutedEvent
|
||||
EventBus.Post(new ShrinkCommandExecutedEvent
|
||||
{
|
||||
ServiceName = registration.ServiceName,
|
||||
RawInput = info.RawInput,
|
||||
@@ -189,7 +199,7 @@ namespace ShrinkCommand.Integration
|
||||
if (info.Result.IsSuccess)
|
||||
return;
|
||||
|
||||
EventBus.TriggerEvent(new ShrinkCommandFailedEvent
|
||||
EventBus.Post(new ShrinkCommandFailedEvent
|
||||
{
|
||||
ServiceName = registration.ServiceName,
|
||||
RawInput = info.RawInput,
|
||||
|
||||
+8
-5
@@ -4,17 +4,20 @@ using ShrinkEventBus;
|
||||
|
||||
namespace ShrinkCommand.Integration
|
||||
{
|
||||
[Cancelable]
|
||||
public sealed class ShrinkCommandExecuteRequestEvent : EventBase
|
||||
public sealed class ShrinkCommandExecuteRequestEvent : IShrinkCancelableEvent
|
||||
{
|
||||
private bool _isCanceled;
|
||||
|
||||
public string ServiceName { get; set; } = ShrinkCommandConstants.DefaultServiceName;
|
||||
public string RawInput { get; set; } = string.Empty;
|
||||
public IShrinkCommandSource? Source { get; set; }
|
||||
public bool IsHandled { get; set; }
|
||||
public ShrinkCommandExecutionResult? ExecutionResult { get; set; }
|
||||
public bool IsCanceled => _isCanceled;
|
||||
public void SetCanceled(bool value) => _isCanceled = value;
|
||||
}
|
||||
|
||||
public sealed class ShrinkCommandExecutingEvent : EventBase
|
||||
public sealed class ShrinkCommandExecutingEvent : IShrinkEvent
|
||||
{
|
||||
public string ServiceName { get; set; } = ShrinkCommandConstants.DefaultServiceName;
|
||||
public string RawInput { get; set; } = string.Empty;
|
||||
@@ -24,7 +27,7 @@ namespace ShrinkCommand.Integration
|
||||
public Dictionary<string, string> Arguments { get; set; } = new();
|
||||
}
|
||||
|
||||
public sealed class ShrinkCommandExecutedEvent : EventBase
|
||||
public sealed class ShrinkCommandExecutedEvent : IShrinkEvent
|
||||
{
|
||||
public string ServiceName { get; set; } = ShrinkCommandConstants.DefaultServiceName;
|
||||
public string RawInput { get; set; } = string.Empty;
|
||||
@@ -36,7 +39,7 @@ namespace ShrinkCommand.Integration
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public sealed class ShrinkCommandFailedEvent : EventBase
|
||||
public sealed class ShrinkCommandFailedEvent : IShrinkEvent
|
||||
{
|
||||
public string ServiceName { get; set; } = ShrinkCommandConstants.DefaultServiceName;
|
||||
public string RawInput { get; set; } = string.Empty;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"dependencies": {
|
||||
"com.cneicy.shrink-command": "0.2.0",
|
||||
"com.cneicy.shrink-context-core": "0.1.0",
|
||||
"com.cneicy.shrink-eventbus": "1.3.0"
|
||||
"com.cneicy.shrink-eventbus": "2.0.0"
|
||||
},
|
||||
"keywords": ["command", "eventbus", "integration", "bridge"],
|
||||
"author": {
|
||||
|
||||
Reference in New Issue
Block a user