RynthServers/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/DreamWeaveWeb.cs
Daniel Wallace a82d0f93c8 DreamWeave: Class Abilities first in the web links
The bar dropdown, the card buttons on older engines and the /rserver
usage line now list Class Abilities, then Market, then Suit Builder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:46:09 -08:00

75 lines
3.6 KiB
C#

// DreamWeave's website destinations: where each button goes. The host and the paths are constants
// (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;
/// <summary>One website page a DreamWeave button opens.</summary>
internal sealed record WebDestination(string Id, string Label, string Path, string Tooltip);
internal static class DreamWeaveWeb
{
public const string SiteBase = "https://www.acdreamweave.com";
/// <summary>The only host the panel or the browser may be sent to.</summary>
public static readonly string[] AllowedHosts = { "www.acdreamweave.com" };
public const string PanelTitle = "DreamWeave";
public static readonly WebDestination[] Destinations =
{
new("abilities", "Class Abilities", "/play/abilities", "Raise and lower this character's class abilities live."),
new("market", "Market", "/market", "The player market, logged in as this account."),
new("suit", "Suit Builder", "/tools/suit", "Plan a suit from this account's characters."),
};
/// <summary>The first engine API that draws a plugin window's bar-icon dropdown from the manifest's barMenu.</summary>
internal const uint BarMenuEngineApi = 95;
/// <summary>Whether an engine of this API version draws the bar menu (so the card's buttons are redundant).</summary>
internal static bool EngineDrawsBarMenu(uint engineVersion) => engineVersion >= BarMenuEngineApi;
/// <summary>The Phosphor glyph (private-use character) for a destination's menu item; "" when it has none.</summary>
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,
};
/// <summary>One bar-menu item per destination: id, label as tooltip, glyph, and the /rserver verb.</summary>
internal static List<ServerBarMenuItem> BarMenu()
{
var items = new List<ServerBarMenuItem>(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;
foreach (WebDestination d in Destinations)
if (string.Equals(d.Id, id, StringComparison.OrdinalIgnoreCase)) return d;
return null;
}
/// <summary>The "/rserver" usage line for the destinations' verbs (ServerUsageLines).</summary>
public static string UsageLine()
{
var ids = new string[Destinations.Length];
var labels = new string[Destinations.Length];
for (int i = 0; i < Destinations.Length; i++) { ids[i] = Destinations[i].Id; labels[i] = Destinations[i].Label; }
string choices = labels.Length < 2 ? string.Join("", labels)
: string.Join(", ", labels, 0, labels.Length - 1) + " or " + labels[labels.Length - 1];
return "/rserver " + string.Join(" | ", ids) + " - open the website's " + choices + ", logged in as this account.";
}
/// <summary>The sign-in URL for a destination. The caller has already checked the code with LaunchWire.</summary>
public static string LaunchUrl(string code, WebDestination d)
=> SiteBase + "/launch?code=" + code + "&to=" + Uri.EscapeDataString(d.Path);
}