ServerPack: card-actions hook for a server's own buttons
Adds partial void ServerCardActions(), drawn at the top of the server card under RynthCore's verdict (render thread). ServerPackUi takes an optional cardActions delegate; the plugin passes DrawCardActions (a delegate cannot bind an unimplemented partial, CS0762). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e52923ba5c
commit
52b0b00860
3 changed files with 53 additions and 3 deletions
|
|
@ -24,6 +24,7 @@ internal static class ServerPackHooksTests
|
|||
r.Add("hooks: settings migration runs once, and a broken file means defaults", SettingsMigration);
|
||||
r.Add("hooks: profile values are published, validated and read back", ProfileValues);
|
||||
r.Add("hooks: the own-reply window opens, stretches and closes", ReplyWindow);
|
||||
r.Add("hooks: the card draws server actions under the verdict, once", CardActions);
|
||||
}
|
||||
|
||||
internal static string TempDir()
|
||||
|
|
@ -199,4 +200,40 @@ internal static class ServerPackHooksTests
|
|||
req.Clear();
|
||||
Check.False(req.Awaiting(1001), "cleared");
|
||||
}
|
||||
}
|
||||
|
||||
// Source scan: the card hands the server's own buttons a spot right under RynthCore's verdict.
|
||||
private static string ServerPackDir()
|
||||
{
|
||||
string? dir = AppContext.BaseDirectory;
|
||||
while (dir != null && !Directory.Exists(Path.Combine(dir, "Plugins", "Shared", "ServerPack")))
|
||||
dir = Path.GetDirectoryName(dir);
|
||||
if (dir == null) throw new DirectoryNotFoundException("Plugins\\Shared\\ServerPack not found above " + AppContext.BaseDirectory);
|
||||
return Path.Combine(dir, "Plugins", "Shared", "ServerPack");
|
||||
}
|
||||
|
||||
private static int CountOf(string text, string needle)
|
||||
{
|
||||
int n = 0, at = 0;
|
||||
while ((at = text.IndexOf(needle, at, StringComparison.Ordinal)) >= 0) { n++; at += needle.Length; }
|
||||
return n;
|
||||
}
|
||||
|
||||
private static void CardActions()
|
||||
{
|
||||
string ui = File.ReadAllText(Path.Combine(ServerPackDir(), "ServerPackUi.cs"));
|
||||
string plugin = File.ReadAllText(Path.Combine(ServerPackDir(), "ServerPackPlugin.cs"));
|
||||
|
||||
int body = ui.IndexOf("public void RenderBody()", StringComparison.Ordinal);
|
||||
Check.True(body >= 0, "RenderBody exists");
|
||||
int verdict = ui.IndexOf("RenderVerdict(info);", body, StringComparison.Ordinal);
|
||||
int facts = ui.IndexOf("RenderFacts(info);", body, StringComparison.Ordinal);
|
||||
Check.True(verdict > body && facts > verdict, "RenderBody draws the verdict, then the facts");
|
||||
Check.Eq(CountOf(ui, "_cardActions()"), 1, "the card actions are invoked exactly once");
|
||||
int call = ui.IndexOf("_cardActions()", StringComparison.Ordinal);
|
||||
Check.True(call > verdict && call < facts, "the actions are drawn after the verdict and before the facts");
|
||||
|
||||
Check.True(plugin.Contains("DrawCardActions", StringComparison.Ordinal) && plugin.Contains("partial void ServerCardActions();", StringComparison.Ordinal),
|
||||
"the plugin declares the ServerCardActions hook and DrawCardActions");
|
||||
Check.True(plugin.Contains("_pages, DrawCardActions)", StringComparison.Ordinal), "the plugin passes DrawCardActions to ServerPackUi");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue