diff --git a/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/DreamWeaveWeb.cs b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/DreamWeaveWeb.cs index 199bb1f..b7b746a 100644 --- a/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/DreamWeaveWeb.cs +++ b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/DreamWeaveWeb.cs @@ -2,6 +2,8 @@ // (the site's registry: dreamweave-market Source/ACE.Market/Site/SiteTools.cs and HostRouting.cs); // nothing here is ever read from chat. Pure, so RynthServerPack.Tests compiles it directly. using System; +using System.Collections.Generic; +using RynthCore.Plugin.ServerPack; namespace RynthCore.Plugin.RynthDreamWeave; @@ -24,6 +26,30 @@ internal static class DreamWeaveWeb new("abilities", "Ability Planner", "/tools/abilities", "Plan a class ability build."), }; + /// The first engine API that draws a plugin window's bar-icon dropdown from the manifest's barMenu. + internal const uint BarMenuEngineApi = 94; + + /// Whether an engine of this API version draws the bar menu (so the card's buttons are redundant). + internal static bool EngineDrawsBarMenu(uint engineVersion) => engineVersion >= BarMenuEngineApi; + + /// The Phosphor glyph (private-use character) for a destination's menu item; "" when it has none. + internal static string Icon(string id) => id switch + { + "market" => ((char)0xE470).ToString(), // Storefront + "suit" => ((char)0xE40A).ToString(), // Shield + "abilities" => ((char)0xE6A2).ToString(), // Sparkle + _ => string.Empty, + }; + + /// One bar-menu item per destination: id, label as tooltip, glyph, and the /rserver verb. + internal static List BarMenu() + { + var items = new List(Destinations.Length); + foreach (WebDestination d in Destinations) + items.Add(new ServerBarMenuItem(d.Id, d.Label, Icon(d.Id), "/rserver " + d.Id)); + return items; + } + public static WebDestination? ById(string? id) { if (string.IsNullOrEmpty(id)) return null; diff --git a/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeaveWebTools.cs b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeaveWebTools.cs index 71aec1f..e27ec05 100644 --- a/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeaveWebTools.cs +++ b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeaveWebTools.cs @@ -59,10 +59,25 @@ public sealed partial class ServerPackPlugin } } + partial void ServerBarMenu(List items) + { + try + { + items.AddRange(DreamWeaveWeb.BarMenu()); + } + catch (Exception) + { + // The constructor has no Host to log to yet; the destinations are constants. + } + } + partial void ServerCardActions() { try { + // An engine that draws the bar icon's dropdown carries the links; the card keeps its buttons + // (and the status line) only for older engines, so no one loses them. + if (DreamWeaveWeb.EngineDrawsBarMenu(Host.Version)) return; WebButtons.Draw(_web, Active, _webClick ??= d => RunOnTick(() => StartLaunch(d))); } catch (Exception ex) diff --git a/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs b/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs index 05d8914..794d7f7 100644 --- a/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs +++ b/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml.Linq; +using RynthCore.Engine.UI.Sections; using RynthCore.Plugin.RynthDreamWeave; using RynthCore.Plugin.ServerPack; using RynthCore.RynthAiTests.Harness; @@ -33,6 +34,61 @@ internal static class DreamWeaveWebTests r.Add("dreamweave web: a malformed launch-code line never reaches chat", MalformedSuccess); r.Add("dreamweave web: the source scan's helpers read code, not comments or strings", ScanHelpers); r.Add("dreamweave web: the plugin's shared hooks hand off to the web tools first", HooksHandOff); + r.Add("dreamweave web: the bar icon's menu lists the destinations, in the engine's own terms", BarMenuItems); + r.Add("dreamweave web: the engine draws the bar menu from API 94", EngineDrawsMenu); + r.Add("dreamweave web: the card hides its buttons only when the engine's version says it draws the menu", CardHidesButtonsOnNewEngines); + } + + private static void BarMenuItems() + { + List items = DreamWeaveWeb.BarMenu(); + string[][] want = + { + new[] { "market", "Market", ((char)0xE470).ToString(), "/rserver market" }, + new[] { "suit", "Suit Builder", ((char)0xE40A).ToString(), "/rserver suit" }, + new[] { "abilities", "Ability Planner", ((char)0xE6A2).ToString(), "/rserver abilities" }, + }; + Check.Eq(items.Count, want.Length, "one item per destination"); + for (int i = 0; i < want.Length && i < items.Count; i++) + { + Check.Eq(items[i].Id, want[i][0], "id " + i); + Check.Eq(items[i].Tooltip, want[i][1], "tooltip " + i); + Check.Eq(items[i].Icon, want[i][2], "icon " + i); + Check.Eq(items[i].Command, want[i][3], "command " + i); + Check.Eq(SectionManifestParser.Command(items[i].Command), items[i].Command, "the engine keeps the command " + i); + Check.Eq(SectionManifestParser.Icon(items[i].Icon), items[i].Icon, "the engine keeps the icon " + i); + Check.True(DreamWeaveWeb.ById(items[i].Id) != null, "the command's verb is a destination: " + items[i].Id); + } + Check.True(items.Count <= SectionManifestParser.MaxBarMenuItems, "within the engine's cap"); + + // And through the manifest, as the engine reads it. + var info = new ServerPackInfo("dreamweave", "DreamWeave", new[] { "play.acdreamweave.com" }, Array.Empty()); + SectionManifest m = SectionManifestParser.Parse("RynthDreamWeave", ServerPackModel.BuildSectionsJson(info, "RynthDreamWeave", null, barMenu: items), out string error); + Check.Eq(error, string.Empty, "parses clean: " + error); + Check.Eq(m.Windows.Single().Menu.Length, 3, "the engine reads three items"); + } + + private static void EngineDrawsMenu() + { + Check.Eq(DreamWeaveWeb.BarMenuEngineApi, 94u, "the engine API that draws the bar menu"); + Check.False(DreamWeaveWeb.EngineDrawsBarMenu(93), "93: the card keeps its buttons"); + Check.True(DreamWeaveWeb.EngineDrawsBarMenu(94), "94: the engine draws the menu"); + Check.True(DreamWeaveWeb.EngineDrawsBarMenu(95), "95: the engine draws the menu"); + Check.False(DreamWeaveWeb.EngineDrawsBarMenu(0), "0: unknown version keeps the buttons"); + } + + private static void CardHidesButtonsOnNewEngines() + { + string hostPath = Path.Combine(ServerProjectsTests.PluginsDir(), "RynthCore.Plugin.RynthDreamWeave", "DreamWeaveWebTools.cs"); + Check.True(File.Exists(hostPath), "DreamWeaveWebTools.cs exists"); + if (!File.Exists(hostPath)) return; + string host = StripComments(File.ReadAllText(hostPath)); + List card = StatementsAfter(host, "partial void ServerCardActions()"); + Check.Eq(card.Count, 1, "ServerCardActions implemented once"); + Check.True(card.Count == 1 && card[0].Contains("EngineDrawsBarMenu(Host.Version)", StringComparison.Ordinal), + "ServerCardActions asks the running engine's version (Host.Version)"); + Check.False(host.Contains("CurrentApiVersion", StringComparison.Ordinal), "the plugin never reads the compile-time CurrentApiVersion"); + Check.True(host.Contains("DreamWeaveWeb.BarMenu()", StringComparison.Ordinal), "ServerBarMenu supplies DreamWeaveWeb.BarMenu()"); } // -- Host wiring (source scan: the plugin is NativeAOT, so its host code can't run here) --