ServerPack: card actions, web open, usage lines #1
3 changed files with 53 additions and 3 deletions
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>
commit
52b0b00860
|
|
@ -33,6 +33,8 @@
|
|||
// plugins that apply a server rule without knowing the server.
|
||||
// ServerCommandVerbs(list) its own "/rserver <verb>" words, handled in ServerChatCommand.
|
||||
// RunOnTick(action) work for the next tick (a page's button, on the render thread).
|
||||
// ServerCardActions() the server's own buttons at the top of its card, under RynthCore's verdict
|
||||
// (render thread: ImGui calls only; queue work with RunOnTick).
|
||||
// Send(command) a chat command as if typed (pump thread, logged in only);
|
||||
// LogTagged(text) the engine log, "[RynthConquest] ..."; ChatLine(text) the chat window.
|
||||
// Resources\quests.<id>.csv (no code) the server's own quest list: embedded by ServerPlugin.props and
|
||||
|
|
@ -102,7 +104,7 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
var verbs = new List<string>();
|
||||
ServerCommandVerbs(verbs);
|
||||
foreach (string v in verbs) if (!string.IsNullOrWhiteSpace(v)) _serverVerbs.Add(v.Trim());
|
||||
_ui = new ServerPackUi(_model, RynthPluginInfo.Name + " " + Marshal.PtrToStringAnsi(VersionPointer), () => _world, _pages);
|
||||
_ui = new ServerPackUi(_model, RynthPluginInfo.Name + " " + Marshal.PtrToStringAnsi(VersionPointer), () => _world, _pages, DrawCardActions);
|
||||
}
|
||||
|
||||
internal ServerPackInfo Info => _model.Info;
|
||||
|
|
@ -147,6 +149,10 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
/// <summary>Every frame while logged in (render thread, AC's main thread; the engine's ImGui context current).</summary>
|
||||
partial void ServerRender();
|
||||
/// <summary>
|
||||
/// Drawn at the top of the server card, under RynthCore's verdict; render thread; queue work with RunOnTick.
|
||||
/// </summary>
|
||||
partial void ServerCardActions();
|
||||
/// <summary>
|
||||
/// An incoming chat line (pump thread, logged in only): set <paramref name="eat"/> to keep it out of
|
||||
/// the chat window (it comes in true when an earlier plugin already ate it).
|
||||
/// </summary>
|
||||
|
|
@ -165,6 +171,9 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
/// <summary>The live numbers of the profile ("values"). Any thread.</summary>
|
||||
internal ServerProfileValues ProfileValues => _profileValues;
|
||||
|
||||
// A delegate cannot bind an unimplemented partial method (CS0762), so the card gets this wrapper.
|
||||
private void DrawCardActions() => ServerCardActions();
|
||||
|
||||
/// <summary>The pages this plugin draws.</summary>
|
||||
internal IReadOnlyList<ServerPage> Pages => _pages;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ internal sealed class ServerPackUi
|
|||
private readonly Func<string?> _world;
|
||||
private readonly string _windowTitle;
|
||||
private readonly IReadOnlyList<ServerPage> _pages;
|
||||
private readonly Action? _cardActions;
|
||||
private string _status = string.Empty;
|
||||
|
||||
/// <summary>The standalone window is open ("/rserver").</summary>
|
||||
|
|
@ -34,12 +35,14 @@ internal sealed class ServerPackUi
|
|||
/// <param name="pluginLabel">"RynthColdeve 0.1.0", for the title and the card.</param>
|
||||
/// <param name="world">The world name the client reports now (null when unknown).</param>
|
||||
/// <param name="pages">The server's own pages: tabs of the window after the card.</param>
|
||||
public ServerPackUi(ServerPackModel model, string pluginLabel, Func<string?> world, IReadOnlyList<ServerPage>? pages = null)
|
||||
/// <param name="cardActions">The server's own buttons, drawn under the verdict (render thread); null when it has none.</param>
|
||||
public ServerPackUi(ServerPackModel model, string pluginLabel, Func<string?> world, IReadOnlyList<ServerPage>? pages = null, Action? cardActions = null)
|
||||
{
|
||||
_model = model;
|
||||
_pluginLabel = pluginLabel;
|
||||
_world = world;
|
||||
_pages = pages ?? Array.Empty<ServerPage>();
|
||||
_cardActions = cardActions;
|
||||
_windowTitle = model.Info.Name + " server (" + pluginLabel + ")##server_" + model.Info.Id;
|
||||
}
|
||||
|
||||
|
|
@ -82,6 +85,7 @@ internal sealed class ServerPackUi
|
|||
{
|
||||
ServerPackInfo info = _model.Info;
|
||||
RenderVerdict(info);
|
||||
if (_cardActions != null) { ImGui.Separator(); _cardActions(); }
|
||||
ImGui.Separator();
|
||||
RenderFacts(info);
|
||||
if (info.Commands.Length > 0)
|
||||
|
|
|
|||
|
|
@ -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