First consumer of acdream's plugin automation surface, and the first slice of the VTank-class plugin milestone (docs/research/2026-07-29-vtank-plugin-automation-requirements.md). MossTank shows a panel with a Buff button; clicking it casts every self-buff the character is missing, skips what is already in force at an equal or higher tier, and refreshes what is nearly expired. The host/plugin line is the load-bearing decision here. The host publishes spell DATA -- family, tier, difficulty, mana, duration -- plus a cast primitive with a preflight gate. The plugin owns the POLICY. That is the architectural conclusion the requirements research reached: VTank's engine lived in plugin-land, built on Decal's primitives, and baking "best buff for skill X" into the host would start pulling the engine inward one convenience at a time. Why the plan is driven off the spellbook rather than off trained skills, which is the obvious reading of "buff every trained and specialised skill": the client cannot honestly make that mapping. The link between a spell and the stat it modifies arrives from the SERVER in the enchantment message and is absent from the client's own spell table. What the client does know is which spells the character has learned -- and a character only learns buffs for the skills they use, so the spellbook reaches the same set without inventing a mapping the client has no grounds for. Surface added, all BCL-only so Plugin.Abstractions keeps its zero project references: * ICharacterInfo, ISpellCatalog, IMagicCommands, grouped behind one IAutomationSurface so IPluginHost grows by one member rather than three. * IEvents.Tick. Automation is sequences, not single calls -- a buff pass casts several spells and must wait between them. Without a host tick a plugin would need its own timer thread re-entering the host off its update thread. * NoOpAutomationSurface for hosts with no live session, so a plugin keeps one code path and checks IsAvailable. Markup gained <button> and <label>; it previously supported only <meter>, with a comment promising the rest. Buttons bind onclick to an Action property and FAIL THE PANEL LOAD if it does not resolve -- a silently dead button is worse than a panel that refuses to load, because the user clicks and there is nothing to diagnose. Labels bind through a Func so a status line tracks its binding instead of freezing at build time. Enchantment reads use EnchantmentsInEffectSnapshot rather than the raw active set: retail leaves a weaker same-family enchantment in the registry while a stronger one is in force, and a plugin asking "am I buffed?" means in force. BuffPlan is a pure function of (known buffs, active enchantments) precisely so it can be tested without a session; 9 tests cover tier supersede, the family-0 no-stack bucket that must not be de-duplicated, expiry refresh, and plan stability across the rebuilds the tick loop performs. Solution builds clean; 14,421 tests pass on the standard hermetic lane filter, 0 failures. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
151 lines
5.7 KiB
C#
151 lines
5.7 KiB
C#
using AcDream.App.UI;
|
|
|
|
namespace AcDream.App.Tests.UI;
|
|
|
|
public class MarkupDocumentTests
|
|
{
|
|
private sealed class FakeBinding
|
|
{
|
|
public float HealthPercent => 0.5f;
|
|
public uint? HealthCurrent => 109;
|
|
public uint? HealthMax => 218;
|
|
public float? ManaPercent => null;
|
|
public uint? ManaCurrent => null;
|
|
public uint? ManaMax => null;
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_CreatesPanelWithMeterFillLabelAndGeometry()
|
|
{
|
|
const string xml =
|
|
"<panel id=\"acdream.vitals\" x=\"10\" y=\"30\" w=\"220\" h=\"96\" title=\"Vitals\">" +
|
|
" <meter id=\"health\" x=\"8\" y=\"24\" w=\"200\" h=\"14\" fill=\"{HealthPercent}\" cur=\"{HealthCurrent}\" max=\"{HealthMax}\" color=\"#FFFF0000\"/>" +
|
|
"</panel>";
|
|
|
|
var panel = MarkupDocument.Build(xml, new FakeBinding(), _ => ((uint)1, 32, 32));
|
|
|
|
Assert.IsType<UiNineSlicePanel>(panel);
|
|
Assert.Equal(10f, panel.Left);
|
|
Assert.Equal(220f, panel.Width);
|
|
Assert.Equal(2, panel.Children.Count); // title UiLabel + 1 meter
|
|
var meter = Assert.IsType<UiMeter>(panel.Children[1]);
|
|
Assert.Equal(8f, meter.Left);
|
|
Assert.Equal(200f, meter.Width);
|
|
Assert.Equal(0.5f, meter.Fill());
|
|
Assert.Equal("109/218", meter.Label());
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_NullBindingValuesYieldNullFillAndLabel()
|
|
{
|
|
const string xml =
|
|
"<panel id=\"v\" x=\"0\" y=\"0\" w=\"10\" h=\"10\" title=\"V\">" +
|
|
" <meter id=\"mana\" x=\"0\" y=\"0\" w=\"10\" h=\"2\" fill=\"{ManaPercent}\" cur=\"{ManaCurrent}\" max=\"{ManaMax}\" color=\"#FF0000FF\"/>" +
|
|
"</panel>";
|
|
var panel = MarkupDocument.Build(xml, new FakeBinding(), _ => ((uint)1, 32, 32));
|
|
var meter = Assert.IsType<UiMeter>(panel.Children[1]);
|
|
Assert.Null(meter.Fill());
|
|
Assert.Null(meter.Label());
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_ResizeAttrX_SetsHorizontalOnly()
|
|
{
|
|
const string xml = "<panel id=\"v\" x=\"0\" y=\"0\" w=\"100\" h=\"50\" title=\"V\" resize=\"x\"></panel>";
|
|
var panel = MarkupDocument.Build(xml, new object(), _ => ((uint)1, 32, 32));
|
|
Assert.True(panel.ResizeX);
|
|
Assert.False(panel.ResizeY);
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_ParsesNineSliceBarSpriteIds()
|
|
{
|
|
const string xml = "<panel id=\"v\" x=\"0\" y=\"0\" w=\"100\" h=\"50\" title=\"V\">" +
|
|
"<meter id=\"h\" x=\"0\" y=\"0\" w=\"100\" h=\"14\" fill=\"{HealthPercent}\" " +
|
|
"backleft=\"0x06001141\" backtile=\"0x06001140\" backright=\"0x0600113F\" " +
|
|
"frontleft=\"0x06001131\" fronttile=\"0x06001132\" frontright=\"0x06001133\"/>" +
|
|
"</panel>";
|
|
var panel = MarkupDocument.Build(xml, new FakeBinding(), _ => ((uint)7, 32, 32));
|
|
var meter = Assert.IsType<UiMeter>(panel.Children[1]);
|
|
Assert.Equal(0x06001141u, meter.BackLeft);
|
|
Assert.Equal(0x06001140u, meter.BackTile);
|
|
Assert.Equal(0x0600113Fu, meter.BackRight);
|
|
Assert.Equal(0x06001131u, meter.FrontLeft);
|
|
Assert.Equal(0x06001132u, meter.FrontTile);
|
|
Assert.Equal(0x06001133u, meter.FrontRight);
|
|
Assert.NotNull(meter.SpriteResolve);
|
|
}
|
|
|
|
private sealed class ButtonBinding
|
|
{
|
|
public int Clicks { get; private set; }
|
|
public string Status { get; set; } = "idle";
|
|
public Action Go => () => Clicks++;
|
|
public Action? Missing => null;
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_ButtonInvokesTheBoundActionOnClick()
|
|
{
|
|
const string xml =
|
|
"<panel x=\"0\" y=\"0\" w=\"100\" h=\"60\">" +
|
|
" <button x=\"4\" y=\"8\" w=\"60\" h=\"20\" text=\"Buff\" onclick=\"{Go}\"/>" +
|
|
"</panel>";
|
|
|
|
var binding = new ButtonBinding();
|
|
var panel = MarkupDocument.Build(xml, binding, _ => ((uint)1, 32, 32));
|
|
|
|
var button = Assert.IsType<UiSimpleButton>(panel.Children[0]);
|
|
Assert.Equal("Buff", button.Text);
|
|
Assert.Equal(60f, button.Width);
|
|
|
|
button.OnEvent(new UiEvent { Type = UiEventType.Click });
|
|
button.OnEvent(new UiEvent { Type = UiEventType.Click });
|
|
Assert.Equal(2, binding.Clicks);
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_ButtonWithUnresolvableHandlerFailsLoudly()
|
|
{
|
|
// A silently dead button is worse than a panel that refuses to load:
|
|
// the user clicks and nothing happens, with nothing to diagnose.
|
|
const string xml =
|
|
"<panel x=\"0\" y=\"0\" w=\"100\" h=\"60\">" +
|
|
" <button x=\"0\" y=\"0\" w=\"10\" h=\"10\" text=\"X\" onclick=\"{NoSuchProperty}\"/>" +
|
|
"</panel>";
|
|
|
|
Assert.Throws<FormatException>(
|
|
() => MarkupDocument.Build(xml, new ButtonBinding(), _ => ((uint)1, 32, 32)));
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_BoundLabelTracksTheBindingRatherThanFreezing()
|
|
{
|
|
const string xml =
|
|
"<panel x=\"0\" y=\"0\" w=\"100\" h=\"60\">" +
|
|
" <label x=\"2\" y=\"4\" text=\"{Status}\"/>" +
|
|
"</panel>";
|
|
|
|
var binding = new ButtonBinding();
|
|
var panel = MarkupDocument.Build(xml, binding, _ => ((uint)1, 32, 32));
|
|
|
|
var label = Assert.IsType<UiLabel>(panel.Children[0]);
|
|
Assert.Equal("idle", label.TextSource!());
|
|
|
|
binding.Status = "casting";
|
|
Assert.Equal("casting", label.TextSource!());
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_LiteralLabelTextIsUsedVerbatim()
|
|
{
|
|
const string xml =
|
|
"<panel x=\"0\" y=\"0\" w=\"100\" h=\"60\">" +
|
|
" <label x=\"0\" y=\"0\" text=\"MossTank\"/>" +
|
|
"</panel>";
|
|
|
|
var panel = MarkupDocument.Build(xml, new ButtonBinding(), _ => ((uint)1, 32, 32));
|
|
var label = Assert.IsType<UiLabel>(panel.Children[0]);
|
|
Assert.Equal("MossTank", label.TextSource!());
|
|
}
|
|
}
|