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:
+4
-2
@@ -11,8 +11,10 @@ namespace ExampleGreedMod
|
||||
{
|
||||
public override void OnRegisterContent(ShrinkModContext context)
|
||||
{
|
||||
context.GetRegistry<IReplacedPersonMod>(ReplacedPersonModBridge.RegistryName)
|
||||
.Register(context.ModInfo.ModId, context.ModInfo.ModId, new ExampleGreedRules());
|
||||
context.RegisterContent(
|
||||
ReplacedPersonModBridge.RegistryName,
|
||||
"rules",
|
||||
new ExampleGreedRules());
|
||||
}
|
||||
|
||||
public override void OnReady(ShrinkModContext context)
|
||||
|
||||
@@ -477,6 +477,6 @@ namespace ReplacedPerson.Runtime
|
||||
private static ReplacedCommandResult Reject(string code, string detail) => new() { ErrorCode = code, Message = detail };
|
||||
|
||||
private static void Publish(string status, string detail) =>
|
||||
EventBus.TriggerEvent(new ReplacedNetworkStatusEvent { Status = status, Detail = detail });
|
||||
EventBus.Post(new ReplacedNetworkStatusEvent { Status = status, Detail = detail });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using ShrinkEventBus;
|
||||
|
||||
namespace ReplacedPerson.Runtime
|
||||
{
|
||||
public sealed class ReplacedMatchPhaseEvent : EventBase
|
||||
public sealed class ReplacedMatchPhaseEvent : IShrinkEvent
|
||||
{
|
||||
public int Round { get; set; }
|
||||
public ReplacedMatchPhase MatchPhase { get; set; }
|
||||
@@ -13,39 +13,39 @@ namespace ReplacedPerson.Runtime
|
||||
public string StateHash { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public sealed class ReplacedCardsCommittedEvent : EventBase
|
||||
public sealed class ReplacedCardsCommittedEvent : IShrinkEvent
|
||||
{
|
||||
public int PlayerIndex { get; set; }
|
||||
public string[] NormalCardIds { get; set; } = System.Array.Empty<string>();
|
||||
public string[] EndCardIds { get; set; } = System.Array.Empty<string>();
|
||||
}
|
||||
|
||||
public sealed class ReplacedDiceEvent : EventBase
|
||||
public sealed class ReplacedDiceEvent : IShrinkEvent
|
||||
{
|
||||
public int Slot { get; set; }
|
||||
public int PlayerOneRoll { get; set; }
|
||||
public int PlayerTwoRoll { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ReplacedDamageEvent : EventBase
|
||||
public sealed class ReplacedDamageEvent : IShrinkEvent
|
||||
{
|
||||
public int TargetPlayer { get; set; }
|
||||
public int Amount { get; set; }
|
||||
public int RemainingHealth { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ReplacedRewardEvent : EventBase
|
||||
public sealed class ReplacedRewardEvent : IShrinkEvent
|
||||
{
|
||||
public string RewardId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public sealed class ReplacedSaveEvent : EventBase
|
||||
public sealed class ReplacedSaveEvent : IShrinkEvent
|
||||
{
|
||||
public string Operation { get; set; } = string.Empty;
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ReplacedNetworkStatusEvent : EventBase
|
||||
public sealed class ReplacedNetworkStatusEvent : IShrinkEvent
|
||||
{
|
||||
public string Status { get; set; } = string.Empty;
|
||||
public string Detail { get; set; } = string.Empty;
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace ReplacedPerson.Runtime
|
||||
var result = Match.Apply(command);
|
||||
if (result.Accepted && !result.Duplicate)
|
||||
{
|
||||
EventBus.TriggerEvent(new ReplacedCardsCommittedEvent
|
||||
EventBus.Post(new ReplacedCardsCommittedEvent
|
||||
{
|
||||
PlayerIndex = 0,
|
||||
NormalCardIds = submission.NormalCardIds.ToArray(),
|
||||
@@ -87,7 +87,7 @@ namespace ReplacedPerson.Runtime
|
||||
{
|
||||
if (!Content.Current.Cards.ContainsKey(cardId)) throw new ArgumentException("Unknown card: " + cardId);
|
||||
_saveData.CollectedCards.Add(cardId);
|
||||
EventBus.TriggerEvent(new ReplacedRewardEvent { RewardId = cardId });
|
||||
EventBus.Post(new ReplacedRewardEvent { RewardId = cardId });
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
@@ -106,11 +106,11 @@ namespace ReplacedPerson.Runtime
|
||||
try
|
||||
{
|
||||
await ShrinkSave.SaveSlotAsync(slot, new SaveOptions { SlotName = "被替代之人" });
|
||||
EventBus.TriggerEvent(new ReplacedSaveEvent { Operation = "save", Success = true });
|
||||
EventBus.Post(new ReplacedSaveEvent { Operation = "save", Success = true });
|
||||
}
|
||||
catch
|
||||
{
|
||||
EventBus.TriggerEvent(new ReplacedSaveEvent { Operation = "save", Success = false });
|
||||
EventBus.Post(new ReplacedSaveEvent { Operation = "save", Success = false });
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -120,12 +120,12 @@ namespace ReplacedPerson.Runtime
|
||||
try
|
||||
{
|
||||
await ShrinkSave.LoadSlotAsync(slot);
|
||||
EventBus.TriggerEvent(new ReplacedSaveEvent { Operation = "load", Success = true });
|
||||
EventBus.Post(new ReplacedSaveEvent { Operation = "load", Success = true });
|
||||
Changed?.Invoke();
|
||||
}
|
||||
catch
|
||||
{
|
||||
EventBus.TriggerEvent(new ReplacedSaveEvent { Operation = "load", Success = false });
|
||||
EventBus.Post(new ReplacedSaveEvent { Operation = "load", Success = false });
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -171,7 +171,7 @@ namespace ReplacedPerson.Runtime
|
||||
var before = Match.State.Clone();
|
||||
var result = Match.Apply(command);
|
||||
if (!result.Accepted) throw new InvalidOperationException("AI produced illegal command: " + result.ErrorCode);
|
||||
EventBus.TriggerEvent(new ReplacedCardsCommittedEvent
|
||||
EventBus.Post(new ReplacedCardsCommittedEvent
|
||||
{
|
||||
PlayerIndex = 1,
|
||||
NormalCardIds = submission.NormalCardIds.ToArray(),
|
||||
@@ -194,7 +194,7 @@ namespace ReplacedPerson.Runtime
|
||||
{
|
||||
if (Match == null) return;
|
||||
var state = after ?? Match.State;
|
||||
EventBus.TriggerEvent(new ReplacedMatchPhaseEvent
|
||||
EventBus.Post(new ReplacedMatchPhaseEvent
|
||||
{
|
||||
Round = state.Round,
|
||||
MatchPhase = state.Phase,
|
||||
@@ -204,7 +204,7 @@ namespace ReplacedPerson.Runtime
|
||||
if (before == null || !SameResolution(before.LastResolution, state.LastResolution))
|
||||
foreach (var slot in state.LastResolution)
|
||||
{
|
||||
EventBus.TriggerEvent(new ReplacedDiceEvent
|
||||
EventBus.Post(new ReplacedDiceEvent
|
||||
{
|
||||
Slot = slot.SlotIndex,
|
||||
PlayerOneRoll = slot.PlayerOneRoll,
|
||||
@@ -216,7 +216,7 @@ namespace ReplacedPerson.Runtime
|
||||
{
|
||||
var damage = Math.Max(0, before.Players[i].Health - state.Players[i].Health);
|
||||
if (damage > 0)
|
||||
EventBus.TriggerEvent(new ReplacedDamageEvent { TargetPlayer = i, Amount = damage, RemainingHealth = state.Players[i].Health });
|
||||
EventBus.Post(new ReplacedDamageEvent { TargetPlayer = i, Amount = damage, RemainingHealth = state.Players[i].Health });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ namespace ReplacedPerson.Runtime
|
||||
var target = reward.StartsWith("ornament.", StringComparison.Ordinal) ? _saveData.Ornaments : _saveData.CollectedCards;
|
||||
if (target.Contains(reward)) continue;
|
||||
target.Add(reward);
|
||||
EventBus.TriggerEvent(new ReplacedRewardEvent { RewardId = reward });
|
||||
EventBus.Post(new ReplacedRewardEvent { RewardId = reward });
|
||||
}
|
||||
_saveData.ChapterProgress = Math.Max(_saveData.ChapterProgress, ActiveEnemyId == "greed.full" ? 2 : 1);
|
||||
_saveData.RecentReplay = Match.Replay.Select(value => value.Clone()).ToList();
|
||||
|
||||
Reference in New Issue
Block a user