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:
@@ -1,76 +1,36 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
|
||||
namespace ShrinkEventBus
|
||||
{
|
||||
public sealed class ShrinkEventBusBuilder
|
||||
{
|
||||
internal IShrinkEventExceptionHandler? ExceptionHandler { get; private set; }
|
||||
internal ShrinkEventExceptionHandlingMode ExceptionHandlingMode { get; private set; } =
|
||||
ShrinkEventExceptionHandlingMode.LogAndContinue;
|
||||
internal Action<Type>? EventClassChecker { get; private set; }
|
||||
internal bool StartShutdownEnabled { get; private set; }
|
||||
internal bool CheckTypesOnDispatchEnabled { get; private set; }
|
||||
internal bool AllowPerPhaseDispatchEnabled { get; private set; }
|
||||
internal ShrinkBusKey Key { get; private set; } = ShrinkBusKey.Game;
|
||||
internal ShrinkBusOptions Options { get; private set; } = ShrinkBusOptions.Inline();
|
||||
internal Action<IShrinkEvent, Type, ShrinkBusKey>? PostObserver { get; private set; }
|
||||
|
||||
public ShrinkEventBusBuilder SetExceptionHandler(IShrinkEventExceptionHandler handler)
|
||||
public ShrinkEventBusBuilder WithKey(ShrinkBusKey key)
|
||||
{
|
||||
ExceptionHandler = handler ?? throw new ArgumentNullException(nameof(handler));
|
||||
Key = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ShrinkEventBusBuilder SetExceptionHandlingMode(ShrinkEventExceptionHandlingMode mode)
|
||||
public ShrinkEventBusBuilder WithOptions(ShrinkBusOptions options)
|
||||
{
|
||||
ExceptionHandlingMode = mode;
|
||||
Options = (options ?? throw new ArgumentNullException(nameof(options))).CloneValidated();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ShrinkEventBusBuilder StartShutdown()
|
||||
public IShrinkEventBus Build() => Options.Scheduler == ShrinkBusSchedulerKind.Inline
|
||||
? new ShrinkInlineEventBusInstance(this)
|
||||
: new ShrinkEventBusInstance(this);
|
||||
|
||||
internal ShrinkEventBusBuilder WithPostObserver(
|
||||
Action<IShrinkEvent, Type, ShrinkBusKey> observer)
|
||||
{
|
||||
StartShutdownEnabled = true;
|
||||
PostObserver = observer ?? throw new ArgumentNullException(nameof(observer));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ShrinkEventBusBuilder CheckTypesOnDispatch()
|
||||
{
|
||||
CheckTypesOnDispatchEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ShrinkEventBusBuilder AllowPerPhaseDispatch()
|
||||
{
|
||||
AllowPerPhaseDispatchEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ShrinkEventBusBuilder ClassChecker(Action<Type> checker)
|
||||
{
|
||||
if (checker == null)
|
||||
throw new ArgumentNullException(nameof(checker));
|
||||
|
||||
EventClassChecker = EventClassChecker == null
|
||||
? checker
|
||||
: EventClassChecker + checker;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ShrinkEventBusBuilder MarkerInterface<TMarker>() where TMarker : class
|
||||
{
|
||||
var markerType = typeof(TMarker);
|
||||
if (!markerType.IsInterface)
|
||||
throw new InvalidOperationException($"Marker type {markerType.FullName} must be an interface.");
|
||||
|
||||
return ClassChecker(eventType =>
|
||||
{
|
||||
if (!markerType.IsAssignableFrom(eventType))
|
||||
throw new ArgumentException(
|
||||
$"This bus only accepts events assignable to {markerType.FullName}, but got {eventType.FullName}.");
|
||||
});
|
||||
}
|
||||
|
||||
public IShrinkEventBus Build()
|
||||
{
|
||||
return new ShrinkEventBusInstance(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user