Skip to content

Commit 63c17fd

Browse files
committed
feat(bridge-rimtalk): migrate onto Core Bridge Kit & open skip-check channels, add CI test workflow
refactor: delegate bridge coordination and detection to Core shared components Replace the local BridgeModuleCoordinator logic and RimTalkDetector caching with Core's ExternalModBridgeCoordinator and SoftDependencyDetector, and migrate skip checks to IChannelSkipCheck with channel constants. Use DialogueTriggerKinds constants instead of string literals, and drop the unused RimTalkEvent invalidation trigger from the context pull bridge. Add a CI workflow that runs unit tests via the shared reusable workflow.
1 parent d61a37b commit 63c17fd

8 files changed

Lines changed: 77 additions & 101 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
paths:
7+
- 'Source/**'
8+
- 'Tests/**'
9+
- 'ArchTests/**'
10+
- '.github/workflows/test.yml'
11+
pull_request:
12+
branches: [main, master]
13+
paths:
14+
- 'Source/**'
15+
- 'Tests/**'
16+
- 'ArchTests/**'
17+
- '.github/workflows/test.yml'
18+
19+
jobs:
20+
test:
21+
uses: RimWorld-RimMind-Mod/Workflows/.github/workflows/test.yml@main
22+
secrets: inherit
Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,40 @@
11
using System;
22
using System.Collections.Generic;
33
using RimMind.Application.Common.Interfaces.Extension;
4+
using RimMind.Application.Features.Bridges;
45

56
namespace RimMind.Bridge.RimTalk.Bridge
67
{
78
internal sealed class BridgeModuleCoordinator
89
{
9-
private readonly IReadOnlyList<IBridgeModule> _modules;
10-
private readonly Func<bool> _isDependencyActive;
11-
private readonly Action<string> _log;
12-
private readonly Action<string> _warn;
10+
private readonly ExternalModBridgeCoordinator _inner;
1311

1412
public BridgeModuleCoordinator(
1513
IReadOnlyList<IBridgeModule> modules,
1614
Func<bool> isDependencyActive,
1715
Action<string> log,
1816
Action<string> warn)
1917
{
20-
_modules = modules ?? throw new ArgumentNullException(nameof(modules));
21-
_isDependencyActive = isDependencyActive
22-
?? throw new ArgumentNullException(nameof(isDependencyActive));
23-
_log = log ?? throw new ArgumentNullException(nameof(log));
24-
_warn = warn ?? throw new ArgumentNullException(nameof(warn));
18+
if (modules == null) throw new ArgumentNullException(nameof(modules));
19+
if (isDependencyActive == null) throw new ArgumentNullException(nameof(isDependencyActive));
20+
if (log == null) throw new ArgumentNullException(nameof(log));
21+
if (warn == null) throw new ArgumentNullException(nameof(warn));
22+
23+
_inner = new ExternalModBridgeCoordinator(
24+
isDependencyActive,
25+
modules,
26+
gates: null,
27+
logInfo: log,
28+
logWarn: warn,
29+
inactiveMessage: "RimTalk not active, bridge modules skipped.");
2530
}
2631

27-
public void RegisterAll()
28-
{
29-
if (!_isDependencyActive())
30-
{
31-
_log("RimTalk not active, bridge modules skipped.");
32-
return;
33-
}
32+
public bool AreAllRegistered => _inner.AreAllRegistered;
3433

35-
foreach (IBridgeModule module in _modules)
36-
{
37-
try
38-
{
39-
module.Register();
40-
_log($"{module.Id} registered={module.IsRegistered}.");
41-
}
42-
catch (Exception ex)
43-
{
44-
_warn($"{module.Id} registration failed: {ex.Message}");
45-
}
46-
}
47-
}
34+
public void RegisterAll() => _inner.RegisterAll();
4835

49-
public void UnregisterAll()
50-
{
51-
foreach (IBridgeModule module in _modules)
52-
{
53-
try
54-
{
55-
module.Unregister();
56-
}
57-
catch (Exception ex)
58-
{
59-
_warn($"{module.Id} cleanup failed: {ex.Message}");
60-
}
61-
}
62-
}
36+
public void UnregisterAll() => _inner.UnregisterAll();
37+
38+
public void Refresh() => _inner.Refresh();
6339
}
6440
}

‎Source/Bridge/ContextPullBridge.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private void RegisterRimTalkHistoryProvider()
8383
if (!RimMindPawnLookup.IsActiveSpawnedColonist(pawn)) return null;
8484
return BuildRimTalkHistoryContext(pawn!);
8585
}, null, ct: ct).ConfigureAwait(false);
86-
}, ModId, stalenessTicks: 3000, invalidationTriggers: new[] { "RimTalkEvent" }));
86+
}, ModId, stalenessTicks: 3000)); // RimTalk history changes are external (no bus event): staleness only
8787
}
8888

8989
private bool ResolveTypes()

‎Source/Bridge/DialogueGate.cs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using RimMind.Application.Common.Constants;
12
using RimMind.Bridge.RimTalk.Detection;
23
using RimMind.Bridge.RimTalk.Settings;
34
using Verse;
@@ -16,9 +17,9 @@ public static bool ShouldSkipDialogue(Pawn? pawn, string? triggerType)
1617

1718
return triggerType switch
1819
{
19-
"Chitchat" => settings.skipChitchat,
20-
"Auto" => settings.skipAutoDialogue,
21-
"PlayerInput" => settings.skipPlayerDialogue && !settings.forceRimMindPlayerDialogue,
20+
DialogueTriggerKinds.Chitchat => settings.skipChitchat,
21+
DialogueTriggerKinds.Auto => settings.skipAutoDialogue,
22+
DialogueTriggerKinds.PlayerInput => settings.skipPlayerDialogue && !settings.forceRimMindPlayerDialogue,
2223
_ => false
2324
};
2425
}

‎Source/Bridge/RimTalkBridgeCoordinator.cs‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
using System.Collections.Generic;
2-
using RimMind.Bridge.RimTalk.Detection;
32
using RimMind.Application.Common.Interfaces.Extension;
3+
using RimMind.Application.Features.Bridges;
4+
using RimMind.Bridge.RimTalk.Detection;
45
using Verse;
56

67
namespace RimMind.Bridge.RimTalk.Bridge
78
{
89
/// <summary>
9-
/// Coordinates registration of RimTalk bridge modules.
10+
/// Coordinates registration of RimTalk bridge modules using Core's <see cref="ExternalModBridgeCoordinator"/>.
1011
/// Modules are iterated uniformly; each module decides whether to actually register
1112
/// based on its own settings/detector checks inside <see cref="IBridgeModule.Register"/>.
12-
/// Unregister iterates all modules but each module's Unregister is a no-op if not registered,
13-
/// making Register/Unregister symmetric (previously Register was conditional, Unregister unconditional).
13+
/// Unregister iterates all modules symmetrically.
1414
/// </summary>
1515
public static class RimTalkBridgeCoordinator
1616
{
@@ -26,12 +26,14 @@ private static List<IBridgeModule> GetModules() =>
2626
new PersonaPushBridge()
2727
};
2828

29-
private static BridgeModuleCoordinator CreateCoordinator() =>
30-
new BridgeModuleCoordinator(
31-
GetModules(),
29+
private static ExternalModBridgeCoordinator CreateCoordinator() =>
30+
new ExternalModBridgeCoordinator(
3231
() => RimTalkDetector.IsRimTalkActive,
33-
message => Log.Message($"[RimMind-Bridge-RimTalk] {message}"),
34-
message => Log.Warning($"[RimMind-Bridge-RimTalk] {message}"));
32+
GetModules(),
33+
gates: null,
34+
logInfo: message => Log.Message($"[RimMind-Bridge-RimTalk] {message}"),
35+
logWarn: message => Log.Warning($"[RimMind-Bridge-RimTalk] {message}"),
36+
inactiveMessage: "RimTalk not active, bridge modules skipped.");
3537

3638
public static void Register()
3739
{
Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
using System;
21
using HarmonyLib;
2+
using RimMind.Application.Features.Bridges;
33
using Verse;
44

55
namespace RimMind.Bridge.RimTalk.Detection
66
{
77
public static class RimTalkDetector
88
{
99
public const string RimTalkPackageId = "cj.rimtalk";
10-
11-
private static bool? _cachedResult;
12-
private static int _cacheTick = -1;
10+
private const string RimTalkApiTypeName = "RimTalk.API.RimTalkPromptAPI";
1311
private const int CacheIntervalTicks = 6000;
1412

13+
internal static readonly SoftDependencyDetector Detector = new SoftDependencyDetector(
14+
RimTalkPackageId,
15+
new[] { RimTalkApiTypeName },
16+
ModsConfig.IsActive,
17+
AccessTools.TypeByName,
18+
() => SafeTicksGame,
19+
CacheIntervalTicks);
20+
1521
private static int SafeTicksGame
1622
{
1723
get
@@ -31,52 +37,19 @@ private static int SafeTicksGame
3137

3238
public static bool IsRimTalkActive
3339
{
34-
get
35-
{
36-
int now = SafeTicksGame;
37-
if (_cachedResult == null || (now > 0 && now - _cacheTick > CacheIntervalTicks))
38-
{
39-
_cachedResult = ModsConfig.IsActive(RimTalkPackageId);
40-
if (now > 0)
41-
{
42-
_cacheTick = now;
43-
}
44-
}
45-
return _cachedResult.Value;
46-
}
47-
internal set
48-
{
49-
_cachedResult = value;
50-
}
40+
get => Detector.IsModActive();
41+
internal set => Detector.SetForcedModActiveForTesting(value);
5142
}
5243

5344
public static void InvalidateCache()
5445
{
55-
_cachedResult = null;
56-
_cacheTick = -1;
57-
_apiAvailable = null;
58-
_apiChecked = false;
46+
Detector.ResetCache();
5947
}
6048

61-
private static bool? _apiAvailable;
62-
private static bool _apiChecked;
63-
6449
public static bool IsRimTalkApiAvailable
6550
{
66-
get
67-
{
68-
if (!_apiChecked)
69-
{
70-
_apiAvailable = IsRimTalkActive && AccessTools.TypeByName("RimTalk.API.RimTalkPromptAPI") != null;
71-
_apiChecked = true;
72-
}
73-
return _apiAvailable ?? false;
74-
}
75-
internal set
76-
{
77-
_apiAvailable = value;
78-
_apiChecked = true;
79-
}
51+
get => Detector.IsAvailable();
52+
internal set => Detector.SetForcedApiAvailableForTesting(value);
8053
}
8154
}
8255
}

‎Source/Extensions/RimTalkDialogueSkipCheck.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
namespace RimMind.Bridge.RimTalk
44
{
5-
internal sealed class RimTalkDialogueSkipCheck : ISkipCheck
5+
internal sealed class RimTalkDialogueSkipCheck : IChannelSkipCheck
66
{
77
public string Id => "rimtalk_bridge_dialogue";
88
public string OwnerModId => "RimMindBridgeRimTalk";
99
public SkipCheckKind Kind => SkipCheckKind.Dialogue;
10-
public bool ShouldSkip(in SkipCheckArgs args) => Bridge.DialogueGate.ShouldSkipDialogue(args.Pawn as Verse.Pawn, args.Trigger);
10+
public string Channel => SkipCheckChannels.Dialogue;
11+
public bool ShouldSkip(in SkipCheckArgs args) => Bridge.DialogueGate.ShouldSkipDialogue(args.Pawn as Verse.Pawn, args.Trigger ?? args.Tag);
1112
}
1213
}

‎Source/Extensions/RimTalkFloatMenuSkipCheck.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
namespace RimMind.Bridge.RimTalk
44
{
5-
internal sealed class RimTalkFloatMenuSkipCheck : ISkipCheck
5+
internal sealed class RimTalkFloatMenuSkipCheck : IChannelSkipCheck
66
{
77
public string Id => "rimtalk_bridge_floatmenu";
88
public string OwnerModId => "RimMindBridgeRimTalk";
99
public SkipCheckKind Kind => SkipCheckKind.FloatMenu;
10+
public string Channel => SkipCheckChannels.FloatMenu;
1011
public bool ShouldSkip(in SkipCheckArgs args) => Bridge.DialogueGate.ShouldSkipFloatMenuOption();
1112
}
1213
}

0 commit comments

Comments
 (0)