Snapshot for release 2026.10.28.1 (internal decb3ab)

This commit is contained in:
Tom Bohar 2026-10-28 06:36:39 -04:00
commit b23cabc338
38 changed files with 2801 additions and 127 deletions

View file

@ -122,6 +122,7 @@ internal static class Program
ManaStoneChoiceTests.Register(runner);
CustomDebuffTests.Register(runner);
DebuffRenewTests.Register(runner);
VoidDebuffTests.Register(runner);
ProfileLoadTests.Register(runner);
ActivityInterfaceTests.Register(runner);
CastNoDamageTests.Register(runner);

View file

@ -42,7 +42,9 @@ internal static class MonsterEditorTests
{
Name = "Olthoi", Category = "Olthoi nest", MatchExpression = "getcharintprop[25]>=200",
Priority = 3, DamageType = "Acid", WeaponId = 0x50001234, Fester = true, Broadside = true,
GravityWell = true, Imperil = true, Yield = true, Vuln = true, UseArc = true, UseRing = true,
GravityWell = true, Imperil = true, Yield = true, Vuln = true,
Corrosion = true, Corruption = true, DestructiveCurse = true, WeakeningCurse = true, FesteringCurse = true,
UseArc = true, UseRing = true,
UseStreak = true, UseBolt = false, UseBlast = true, UseWall = true, ExVuln = "Fire", OffhandId = 2,
PetDamage = "Cold", CustomDebuffs = "Corrosion Vulnerability Other, Fire Vulnerability Other VII",
Kite = "PullAway",

View file

@ -0,0 +1,113 @@
using System.Collections.Generic;
using System.Reflection;
using System.Text.Json;
using RynthCore.Plugin.RynthAi;
using RynthCore.Plugin.RynthAi.LegacyUi;
using RynthCore.RynthAiHostTests.Fakes;
using RynthCore.RynthAiTests.Harness;
namespace RynthCore.RynthAiHostTests.Tests;
// 2026-10-27: the Void debuffs as Monsters-rule switches (VTank's Cs, Cp, DC, WC and FC columns):
// Corrosion, Corruption and Destructive Curse (Nether damage over time), Weakening Curse and
// Festering Curse. They were only castable as typed-in custom debuffs.
internal static class VoidDebuffTests
{
private const uint Player = 0x50000181;
private const uint STypeCreature = 31, STypeLife = 33, STypeVoid = 43;
public static void Register(Runner r)
{
r.Add("void debuffs: every one has levels I-VII and an Incantation in the spell data, with its duration", SpellData);
r.Add("void debuffs: a rule's switches go in the debuff list after the Creature ones", DebuffList);
r.Add("void debuffs: the level is capped by Void Magic alone", VoidCap);
r.Add("void debuffs: an engine that doesn't send them can't turn them off", Carried);
}
private static void SpellData()
{
var seconds = new Dictionary<string, int>
{
["Corrosion"] = 16, ["Corruption"] = 31, ["Destructive Curse"] = 31, ["Weakening Curse"] = 15, ["Festering Curse"] = 30,
};
Check.Eq(CombatManager.VoidDebuffBases.Length, 5, "five Void debuffs");
string[] numerals = { "I", "II", "III", "IV", "V", "VI", "VII" };
foreach (string b in CombatManager.VoidDebuffBases)
{
foreach (string n in numerals)
Check.True(SpellDatabase.GetIdByName($"{b} {n}") > 0, $"{b} {n} exists");
int top = SpellDatabase.GetIdByName($"Incantation of {b}");
Check.True(top > 0, $"Incantation of {b} exists");
Check.Eq(SpellDatabase.DurationSeconds(top), seconds[b], $"{b} lasts {seconds[b]} s");
}
}
private static void DebuffList()
{
MethodInfo build = typeof(CombatManager).GetMethod("BuildDebuffList", BindingFlags.NonPublic | BindingFlags.Static)!;
var rule = new MonsterRule { Name = "Mosswart", Imperil = true, Corrosion = true, DestructiveCurse = true, FesteringCurse = true, CustomDebuffs = "Corrosion Vulnerability Other" };
var list = (List<string>)build.Invoke(null, new object[] { rule, "Fire" })!;
Check.Eq(string.Join("|", list), "Imperil|Void:Corrosion|Void:Destructive Curse|Void:Festering Curse|Custom:Corrosion Vulnerability Other",
"Creature first, then Void, then the typed-in ones");
var none = (List<string>)build.Invoke(null, new object[] { new MonsterRule { Name = "Drudge" }, "Fire" })!;
Check.Eq(none.Count, 0, "a new rule (and an old file) has none on");
}
private static void VoidCap()
{
FakeHost.Reset();
foreach (string n in new[] { "Corrosion I", "Corrosion II", "Corrosion VII", "Weakening Curse VII" })
foreach (var row in SpellTable.Named(n)) FakeHost.Spellbook.Add((uint)row.Id);
FakeHost.Skills[(Player, STypeCreature)] = (400, 3); // tier 7 by the thresholds below
FakeHost.Skills[(Player, STypeLife)] = (400, 3);
FakeHost.Skills[(Player, STypeVoid)] = (60, 2); // tier 2
var s = new LegacyUiSettings
{
MinSkillLevelTier1 = 0, MinSkillLevelTier2 = 50, MinSkillLevelTier3 = 100, MinSkillLevelTier4 = 150,
MinSkillLevelTier5 = 200, MinSkillLevelTier6 = 300, MinSkillLevelTier7 = 350, MinSkillLevelTier8 = 10000,
};
var host = FakeHost.Create(Player);
var cache = FakeHost.MakeCache(host, Player, System.Array.Empty<uint>());
var c = new CombatManager(host, s, cache);
c.SetPlayerId(Player);
var skills = new CharacterSkills(host);
skills.SetPlayerId(Player);
var sm = new SpellManager(host, s);
sm.InitializeNatively();
sm.SetCharacterSkills(skills);
sm.RefreshKnownSpells();
c.SetSpellManager(sm);
MethodInfo find = typeof(CombatManager).GetMethod("FindBestVoidDebuffWithTier", BindingFlags.NonPublic | BindingFlags.Instance)!;
object[] args = { "Corrosion", 0 };
int id = (int)find.Invoke(c, args)!;
Check.Eq(SpellTableStub.GetById(id)?.Name, "Corrosion II", "Void at tier 2 casts II, though Creature and Life reach VII");
Check.Eq((int)args[1], 2, "tier 2");
object[] curse = { "Weakening Curse", 0 };
Check.Eq((int)find.Invoke(c, curse)!, 0, "only VII known, above the Void cap: nothing to cast");
object[] unknown = { "Corruption", 0 };
Check.Eq((int)find.Invoke(c, unknown)!, 0, "a debuff the character doesn't know: nothing");
}
private static void Carried()
{
var current = new List<MonsterRule>
{
new() { Name = "Default", Corrosion = true, WeakeningCurse = true },
new() { Name = "Drudge", Corruption = true, DestructiveCurse = true, FesteringCurse = true },
};
var incoming = new List<MonsterRule> { new() { Name = "Default" }, new() { Name = "drudge" }, new() { Name = "Mosswart" } };
LegacyDashboardRenderer.CarryVoidDebuffs(current, incoming);
Check.True(incoming[0].Corrosion && incoming[0].WeakeningCurse && !incoming[0].Corruption, "Default keeps its own");
Check.True(incoming[1].Corruption && incoming[1].DestructiveCurse && incoming[1].FesteringCurse, "matched by name, any case");
Check.False(incoming[2].Corrosion, "a new rule stays off");
// The bridge looks for the key "Corrosion": a rule saved with it has it, and a typed-in
// debuff named Corrosion is a value, not the key.
string json = JsonSerializer.Serialize(new List<MonsterRule> { new() { Name = "X", CustomDebuffs = "Corrosion" } }, RynthAiJsonContext.Default.MonsterRuleList);
Check.True(json.Contains("\"Corrosion\":"), "the plugin writes the key with a colon after it");
string old = "[{\"Name\":\"X\",\"CustomDebuffs\":\"Corrosion\"}]";
Check.False(old.Contains("\"Corrosion\":"), "a typed-in Corrosion doesn't look like the key");
}
}

View file

@ -0,0 +1,266 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using RynthCore.Plugin.RynthDefective;
using RynthCore.Plugin.RynthDefective.Items;
using RynthCore.Plugin.RynthDefective.Model;
using RynthCore.Plugin.RynthDefective.ShortcutBar;
using RynthCore.Plugin.RynthDefective.Ui;
using RynthCore.Plugin.RynthDefective.Use;
using RynthCore.Plugin.RynthDefective.Views;
namespace RynthDefective.Tests
{
// The Shortcuts bar's own logic (2026-10-27): which slot a bar slot is (usual / independent),
// a healing kit in one of AC's slots used on yourself, copying AC's 18 slots into an independent
// bar, the setting in the character's file, and the settings window.
internal static partial class Program
{
/// <summary>A session with AC's 18 slots scripted and every own-slot key bind recorded.</summary>
private sealed class BarRig
{
public readonly Rig R;
public DefSession S => R.S;
public uint[] RetailIds = new uint[DefSettings.RetailSlots], RetailSpells = new uint[DefSettings.RetailSlots];
public bool RetailReadable = true;
public readonly Dictionary<string, string> CommandKeys = new();
public readonly Dictionary<uint, string> Names = new();
public readonly List<(int Own, string Key)> Bound = new();
public BarRig(string name)
{
R = new Rig(name);
S.ReadRetail = (ids, spells) =>
{
if (!RetailReadable) return false;
RetailIds.CopyTo(ids, 0);
RetailSpells.CopyTo(spells, 0);
return true;
};
S.ObjectName = id => Names.TryGetValue(id, out string? n) ? n : null;
S.CommandKeys = c => CommandKeys.TryGetValue(c, out string? k) ? k : string.Empty;
S.BindOwnKey = (own, key) => { Bound.Add((own, key)); return true; };
}
}
private static void BarMappingUsualAndIndependent()
{
// The usual bar: 1-18 AC's, 18+N own N.
Check(BarMapping.IsRetail(1, false) && BarMapping.IsRetail(18, false) && !BarMapping.IsRetail(19, false), "usual: 1-18 are the game's");
Eq(BarMapping.OwnSlot(5, false), 0, "usual: a game slot is no own slot");
Eq(BarMapping.OwnSlot(19, false), 1, "usual: bar 19 is own 1");
Eq(BarMapping.OwnSlot(DefSettings.BarSlotsMax, false), DefSettings.BarSlotsMax - DefSettings.RetailSlots, "usual: the last bar slot");
Eq(BarMapping.KeyAction(3, false), "UseQuickSlot_3", "usual: a game slot's keys are AC's keymap action");
Eq(BarMapping.KeyAction(20, false), "/rdef use 2", "usual: bar 20's keys run /rdef use 2");
Eq(BarMapping.BarNumber(1, false), 19, "usual: own 1 shows at 19");
// Independent: no AC slot is mapped; bar N is own N, keys /rdef use N.
for (int n = 1; n <= DefSettings.BarSlotsMax; n++)
{
if (BarMapping.IsRetail(n, true)) { Check(false, $"independent: bar {n} must not be a game slot"); break; }
if (BarMapping.OwnSlot(n, true) != n || BarMapping.BarNumber(n, true) != n) { Check(false, $"independent: bar {n} is own {n}"); break; }
}
Eq(BarMapping.KeyAction(1, true), "/rdef use 1", "independent: bar 1's keys are an engine hotkey");
Eq(BarMapping.KeyAction(18, true), "/rdef use 18", "independent: bar 18 too");
Check(DefSettings.SlotsMax >= DefSettings.BarSlotsMax, "an independent bar as long as the usual one has an own slot for every bar slot");
for (int own = 1; own <= DefSettings.BarSlotsMax - DefSettings.RetailSlots; own++)
if (BarMapping.OwnSlot(BarMapping.BarNumber(own, false), false) != own) { Check(false, "usual: own -> bar -> own round trip " + own); break; }
Check(true, "mapping round trips");
}
private static void BarRetailKit()
{
var kit = Kit(0x7100_0001u);
var potion = Potion(0x7100_0002u);
var sword = Melee(0x7100_0003u, "Sword");
var nameKit = Item(0x7100_0004u, "Greater Stamina Kit"); // the engine couldn't read the bitfield: RynthAi's name test
var items = new List<CarriedItem> { kit, potion, sword, nameKit };
Check(BarMapping.RetailKit(kit.Id, items) == kit, "a healing kit in a game slot is the use-on-self path");
Check(BarMapping.RetailKit(nameKit.Id, items) == nameKit, "a kit known by its name only, too");
Check(BarMapping.RetailKit(potion.Id, items) == null, "a potion stays AC's");
Check(BarMapping.RetailKit(sword.Id, items) == null, "a weapon stays AC's");
Check(BarMapping.RetailKit(0x7100_00FFu, items) == null, "an object not in the pack stays AC's");
Check(BarMapping.RetailKit(0, items) == null, "an empty slot (or a spell) stays AC's");
// Through the session: the click becomes a use on yourself in the use controller.
var rig = new Rig("retail-kit");
rig.Inv = items;
Check(!rig.S.UseRetailSlot(2, potion.Id) && !rig.S.Use.HasPending, "a potion click is handed to AC (nothing queued here)");
Check(rig.S.UseRetailSlot(1, kit.Id), "a kit click is taken");
UseRequest? req = rig.S.Use.Pending;
Check(req != null && req.Mode == UseMode.OnSelf && req.Item!.Id == kit.Id && req.Source.Contains("game slot 1"), "queued as a use on yourself");
var world = new FakeWorld { Inventory = items };
rig.S.Use.Tick(world);
Check(world.Sent.Count == 1 && world.Sent[0] == $"useon {kit.Id:X} me", "sent as UseObjectOn(kit, you): " + string.Join(";", world.Sent));
}
private static void BarIndependentCopy()
{
var b = new BarRig("copy");
var kit = Kit(0x7200_0001u);
var potion = Potion(0x7200_0002u);
var sword = Melee(0x7200_0003u, "Sword");
var own1 = Potion(0x7200_0010u, "Mana Potion", 3);
var own2 = Melee(0x7200_0011u, "Axe");
b.R.Inv = new List<CarriedItem> { kit, potion, sword, own1, own2 };
// The usual bar: AC's slots 1, 2, 5 hold items, 7 a spell, 9 an item not in the pack (named), 10 one nobody can name.
b.RetailIds[0] = kit.Id; b.RetailIds[1] = potion.Id; b.RetailIds[4] = sword.Id;
b.RetailSpells[6] = 1234;
b.RetailIds[8] = 0x7200_0099u; b.Names[0x7200_0099u] = "Lucky Gold Letter";
b.RetailIds[9] = 0x7200_00AAu;
// Own slots 1 and 2 (bar 19 and 20), with keys on own 1.
b.S.SetSlot(1, own1);
b.S.SetSlot(2, own2);
b.S.Data.Slots[1].Mode = UseMode.Equip;
b.CommandKeys["/rdef use 1"] = "F9, Ctrl+F9";
DefData before = DefStore.Parse(System.Text.Json.JsonDocument.Parse(DefStore.ToJson(b.S.Data)).RootElement);
// Not independent yet: no copy.
Check(b.S.CopyRetailSlots().Contains("independent first") && b.S.Data.Slots[0].Item!.Id == own1.Id, "the copy needs the independent bar");
int saves = b.R.Saves;
string m = b.S.SetIndependent(true);
Check(b.S.Settings.IndependentBar && b.R.Saves > saves, "turned on, saved");
Eq(b.S.CopyOffer, 5, "the offer counts the game's slots with an item (not the spell)");
Check(m.Contains("independent") && m.Contains("5 items") && m.Contains("offers to copy"), "and says so: " + m);
Check(b.S.Data.Slots[0].Item!.Id == own1.Id && b.S.Data.Slots[1].Item!.Id == own2.Id && b.S.Data.Slots[2].Empty,
"turning it on copies nothing by itself");
m = b.S.CopyRetailSlots();
Eq(b.S.CopyOffer, 0, "the offer is answered");
List<DefSlot> s = b.S.Data.Slots;
Check(s[0].Item?.Id == kit.Id && s[1].Item?.Id == potion.Id && s[4].Item?.Id == sword.Id, "the game's items are in own 1, 2, 5");
Check(s[0].Mode == UseMode.Auto && s[0].Item!.Name == "Peerless Healing Kit" && s[0].Item!.Wcid == 628, "copied with their identity, automatic use");
Check(s[6].Empty, "a spell can't be copied: the slot stays empty");
Check(s[8].Item?.Name == "Lucky Gold Letter" && s[8].Item!.Id == 0x7200_0099u, "an item the pack read missed goes by the name the client knows");
Check(s[9].Empty, "one nobody can name stays empty");
Check(s[2].Empty && s[3].Empty && s[17].Empty, "the game's empty slots stay empty");
Check(s[18].Item?.Id == own1.Id && s[19].Item?.Id == own2.Id && s[19].Mode == UseMode.Equip, "the own slots moved to 19 and 20, modes and all");
Check(s.Skip(20).All(x => x.Empty), "nothing past them");
Eq(s.Count, DefSettings.SlotsMax, "still 42 own slots");
Check(b.Bound.Count == 2 && b.Bound.Contains((19, "F9")) && b.Bound.Contains((19, "Ctrl+F9")), "own 1's keys follow it to 19: " + string.Join(";", b.Bound));
Check(m.Contains("Copied 4") && m.Contains("2 couldn't") && m.Contains("2 slots moved") && m.Contains("2 keys"), "and it says what it did: " + m);
for (int n = 1; n <= 20; n++)
{
// The independent bar shows what the usual one did: bar N is own N.
ItemRef? shown = s[BarMapping.OwnSlot(n, true) - 1].Item;
ItemRef? was = n <= DefSettings.RetailSlots ? null : before.Slots[BarMapping.OwnSlot(n, false) - 1].Item;
if (n > DefSettings.RetailSlots && shown?.Id != was?.Id) { Check(false, $"bar {n} keeps its item"); break; }
}
// Declining, turning off, refusing.
b.S.SetIndependent(false);
b.S.SetIndependent(true);
b.S.DeclineCopy();
Eq(b.S.CopyOffer, 0, "no thanks clears the offer");
m = b.S.SetIndependent(false);
Check(!b.S.Settings.IndependentBar && b.S.CopyOffer == 0 && m.Contains("19"), "turned off: no offer, and says where the own slots are");
Check(s[0].Item?.Id == kit.Id && s[18].Item?.Id == own1.Id, "turning off changes no slot");
var full = new BarRig("copy-full");
full.R.Inv = new List<CarriedItem> { kit, own1 };
full.RetailIds[0] = kit.Id;
full.S.SetSlot(30, own1);
full.S.SetIndependent(true);
m = full.S.CopyRetailSlots();
Check(m.Contains("slot 30") && m.Contains("no room") && full.S.Data.Slots[0].Empty && full.S.Data.Slots[29].Item?.Id == own1.Id,
"an own slot past 24 in use: refused, nothing changed: " + m);
var unread = new BarRig("copy-unread") { RetailReadable = false };
m = unread.S.SetIndependent(true);
Check(unread.S.CopyOffer == 0 && !m.Contains("offers"), "AC's slots unreadable: no offer");
Check(unread.S.CopyRetailSlots().Contains("can't be read"), "and no copy");
// The pure copy on its own: an empty bar gets the game's items only.
var own = DefData.NewSlots();
BarCopyResult r = BarMapping.CopyRetail(own, new uint[] { kit.Id }, new uint[1], id => id == kit.Id ? ItemRef.From(kit) : null);
Check(r.Refused == null && r.Copied == 1 && r.Moved.Count == 0 && own[0].Item?.Id == kit.Id && own.Skip(1).All(x => x.Empty), "an empty bar: just the copy");
}
private static void BarStoreIndependent()
{
var st = new DefStore(Path.Combine(_temp, "indep"));
var d = new DefData();
Check(!d.Settings.IndependentBar, "off by default");
d.Settings.IndependentBar = true;
Check(st.Save("S", "Indie", d) == null, "saved");
string json = File.ReadAllText(st.PathFor("S", "Indie"));
Check(json.Contains("\"independentBar\": true"), "written in the file");
Check(st.Load("S", "Indie", out string? problem).Settings.IndependentBar && problem == null, "read back on");
// A file from before the setting existed: off, everything else as it was.
string old = st.PathFor("S", "Old");
Directory.CreateDirectory(Path.GetDirectoryName(old)!);
File.WriteAllText(old, "{\"version\":1,\"settings\":{\"slotCount\":8,\"barSlots\":20,\"swapWhileBotRuns\":true},"
+ "\"slots\":[{\"item\":{\"id\":5,\"name\":\"Kit\"},\"mode\":0}]}");
DefData o = st.Load("S", "Old", out problem);
Check(problem == null && !o.Settings.IndependentBar && o.Settings.BarSlots == 20 && o.Settings.SwapWhileBotRuns && o.Slots[0].Item?.Name == "Kit",
"an old file loads with the independent bar off");
File.WriteAllText(old, "{\"settings\":{\"independentBar\":\"yes\"}}");
Check(!st.Load("S", "Old", out _).Settings.IndependentBar, "a string is not a bool: off");
}
private static void BarSettingsWindow()
{
var b = new BarRig("settings-window");
var kit = Kit(0x7300_0001u);
b.R.Inv = new List<CarriedItem> { kit };
b.RetailIds[0] = kit.Id;
var host = new UiHost();
UiWindow win = host.Add(new UiWindow("RynthDefective/Settings", "Defective Settings") { Visible = true, ShowInBar = false });
var view = new BarSettingsView(b.S);
var shown = new Dictionary<string, bool> { [BarSettingsView.BarTitle] = true, [BarSettingsView.SelectionTitle] = false };
var told = new List<string>();
view.WindowShown = t => shown.TryGetValue(t, out bool v) ? v : null; // no Game Panels on this "engine"
view.ShowWindow = (t, v) => shown[t] = v;
view.Tell = told.Add;
void Draw() { win.Begin(); view.Draw(win); win.End(); }
string Text() => Encoding.UTF8.GetString(win.Body);
// The test window helpers send events by widget id.
var w = new Windows("settings-window-events");
w.Host.Add(win);
void Click(string id) => w.Click(win, id);
void SetBool(string id, bool v) => w.SetBool(win, id, v);
Draw();
ParseAll(host, "settings window", out int ops);
Check(ops < 1500, "inside the engine's limits");
Check(Text().Contains("Allow weapon swaps while RynthAi's macro runs"), "the weapon swap switch is reachable");
Check(Text().Contains("Shortcuts bar") && Text().Contains("Selection") && !Text().Contains("Game panel buttons"),
"the windows RynthDefective draws (Game Panels only where the engine has it)");
Check(Text().Contains("RynthDefective draws the Shortcuts bar, the Game Panels buttons and the Selection window"), "it says what draws them");
SetBool("set.win.sel", true);
Check(shown[BarSettingsView.SelectionTitle], "the Selection box shows the window");
SetBool("set.swap", true);
Check(b.S.Settings.SwapWhileBotRuns, "the swap switch");
SetBool("set.indep", true);
Check(b.S.Settings.IndependentBar && told.Count == 1 && told[0].Contains("independent"), "the independent switch, told in chat");
Eq(b.S.CopyOffer, 1, "the copy is offered");
Draw();
ParseAll(host, "settings window with the offer", out _);
Check(Text().Contains("Copy them") && Text().Contains("No thanks"), "the offer shows");
Click("set.copy");
Check(b.S.Data.Slots[0].Item?.Id == kit.Id && b.S.CopyOffer == 0 && told.Count == 2 && told[1].Contains("Copied 1"), "Copy them copies");
Draw();
Check(!Text().Contains("Copy them"), "and the offer is gone");
SetBool("set.indep", false);
SetBool("set.indep", true);
Draw();
Click("set.nocopy");
Eq(b.S.CopyOffer, 0, "No thanks declines");
b.S.LoggedIn = false;
Draw();
ParseAll(host, "settings window logged out", out _);
Check(Text().Contains("Log in"), "logged out it says so");
}
}
}

View file

@ -367,7 +367,7 @@ namespace RynthDefective.Tests
DefSettings s = r.Settings;
Check(s.SlotCount == 12 && s.SlotsPerRow == 6 && s.ButtonSize == 44 && s.PickerIconSize == 28, "sizes");
Check(!s.ShowIcons && !s.ShowCounts && s.SwapWhileBotRuns && s.BarOpen && s.PickerOpen && s.PreferredKind == KindFilter.War, "switches");
Check(r.Slots.Count == DefSettings.SlotsMax, "all 24 slots");
Check(r.Slots.Count == DefSettings.SlotsMax, "all 42 slots");
ItemRef a = r.Slots[0].Item!;
Check(a.Id == 0x7000_0001u && a.Name == "Peerless Healing Kit" && a.Wcid == 628 && a.Icon == 0x06001234 && a.Underlay == 0x06000FFF && a.Overlay == 0x06000EEE, "a slot's item with its identity and picture");
Check(r.Slots[0].Mode == UseMode.OnSelf && r.Slots[1].Item == null && r.Slots[1].Mode == UseMode.Auto, "modes and empty slots");
@ -398,28 +398,37 @@ namespace RynthDefective.Tests
File.WriteAllText(own, "{}");
d = st.Load("S", "A", out problem);
Check(problem == null && d.Settings.SlotCount == 8 && d.Slots.Count == 24, "{} = defaults");
Check(problem == null && d.Settings.SlotCount == 8 && d.Slots.Count == DefSettings.SlotsMax, "{} = defaults");
File.WriteAllText(own, "{\"settings\":{\"slotCount\":99,\"slotsPerRow\":0,\"buttonSize\":1000,\"pickerIconSize\":-5,\"preferredKind\":42,\"showIcons\":\"yes\"},"
+ "\"slots\":[7,{\"item\":{\"id\":5.0,\"name\":\"Kit\"},\"mode\":9},{\"item\":{\"id\":1}},{\"item\":{\"name\":\" \"}},{\"item\":\"x\"},null],"
+ "\"favourites\":[\"x\",{\"name\":\"Sword\"},{\"id\":3}],\"recent\":5}");
d = st.Load("S", "A", out problem);
Check(problem == null, "odd values are not a problem");
Check(d.Settings.SlotCount == DefSettings.SlotsMax && d.Settings.SlotsPerRow == DefSettings.PerRowMin && d.Settings.ButtonSize == DefSettings.ButtonMax
Check(d.Settings.SlotCount == DefSettings.SlotCountMax && d.Settings.SlotsPerRow == DefSettings.PerRowMin && d.Settings.ButtonSize == DefSettings.ButtonMax
&& d.Settings.PickerIconSize == DefSettings.PickerIconMin && d.Settings.PreferredKind == KindFilter.All && d.Settings.ShowIcons, "clamped, a string is not a bool");
Check(d.Slots[0].Empty, "a non-object slot is empty");
Check(d.Slots[1].Item?.Name == "Kit" && d.Slots[1].Item!.Id == 5 && d.Slots[1].Mode == UseMode.Auto, "2.0 is 2; an unknown mode is automatic");
Check(d.Slots[2].Empty && d.Slots[3].Empty && d.Slots[4].Empty, "an item with no name can't be found again: empty");
Check(d.Favourites.Count == 1 && d.Favourites[0].Name == "Sword" && d.Recent.Count == 0, "bad favourites are skipped; recent that isn't a list is none");
Eq(d.Slots.Count, DefSettings.SlotsMax, "still 24 slots");
Eq(d.Slots.Count, DefSettings.SlotsMax, "still 42 slots");
// More slots than the maximum in a file are cut.
var sb = new StringBuilder("{\"slots\":[");
for (int i = 0; i < 40; i++) sb.Append(i > 0 ? "," : "").Append("{\"item\":{\"id\":").Append(i + 1).Append(",\"name\":\"N").Append(i).Append("\"}}");
for (int i = 0; i < DefSettings.SlotsMax + 10; i++) sb.Append(i > 0 ? "," : "").Append("{\"item\":{\"id\":").Append(i + 1).Append(",\"name\":\"N").Append(i).Append("\"}}");
sb.Append("]}");
File.WriteAllText(own, sb.ToString());
d = st.Load("S", "A", out _);
Check(d.Slots.Count == 24 && d.Slots[23].Item!.Name == "N23", "slots past the 24th are dropped");
Check(d.Slots.Count == DefSettings.SlotsMax && d.Slots[DefSettings.SlotsMax - 1].Item!.Name == "N" + (DefSettings.SlotsMax - 1), "slots past the 42nd are dropped");
// A file from before 2026-10-27 (24 slots): its slots load, the rest are empty.
sb.Clear().Append("{\"slots\":[");
for (int i = 0; i < 24; i++) sb.Append(i > 0 ? "," : "").Append("{\"item\":{\"id\":").Append(i + 1).Append(",\"name\":\"Old").Append(i).Append("\"}}");
sb.Append("]}");
File.WriteAllText(own, sb.ToString());
d = st.Load("S", "A", out _);
Check(d.Slots.Count == DefSettings.SlotsMax && d.Slots[23].Item!.Name == "Old23" && d.Slots[24].Empty && d.Slots[DefSettings.SlotsMax - 1].Empty,
"a 24-slot file loads into the first 24 of 42");
Eq(DefStore.SafeFileName("CON"), "_CON", "reserved names");
Eq(DefStore.FileStem("Dream Weave", "Ana:Lee"), "Dream Weave_Ana_Lee", "illegal characters become underscores");
@ -505,7 +514,7 @@ namespace RynthDefective.Tests
m = rig.S.SetFromName(3, "health");
Check(rig.S.Data.Slots[2].Item?.Name == "Health Potion" && m.Contains("Slot 3"), "set by name");
Check(rig.S.SetFromName(3, "elixir").Contains("No item named"), "a name that matches nothing");
Check(rig.S.SetFromSelected(0).Contains("no slot") && rig.S.SetFromSelected(25).Contains("no slot"), "slot numbers are checked");
Check(rig.S.SetFromSelected(0).Contains("no slot") && rig.S.SetFromSelected(DefSettings.SlotsMax + 1).Contains("no slot"), "slot numbers are checked");
rig.S.SetSlotMode(1, UseMode.Use);
Eq(rig.S.Data.Slots[0].Mode, UseMode.Use, "mode");
@ -527,7 +536,7 @@ namespace RynthDefective.Tests
// Pressing a slot.
rig.S.SetSlotCount(8);
Check(rig.S.UseSlot(2)!.Contains("empty"), "an empty slot says so");
Check(rig.S.UseSlot(40)!.Contains("no slot"), "a slot that doesn't exist");
Check(rig.S.UseSlot(DefSettings.SlotsMax + 1)!.Contains("no slot"), "a slot that doesn't exist");
Check(rig.S.UseSlot(1) == null && rig.S.Use.HasPending, "a set slot queues its item");
}
@ -569,7 +578,7 @@ namespace RynthDefective.Tests
Check(rig.S.BindKey(3, "", false).Contains("Type the key"), "a blank key");
Check(rig.S.BindKey(3, "Ctrl + F9", false).Contains("no spaces"), "spaces in a key");
Check(rig.S.BindKey(4, "F9", true).Contains("empty"), "by name needs an item");
Check(rig.S.BindKey(30, "F9", false).Contains("no slot"), "slot checked");
Check(rig.S.BindKey(DefSettings.SlotsMax + 1, "F9", false).Contains("no slot"), "slot checked");
rig.S.RunChat = _ => false;
Check(rig.S.BindKey(3, "F11", false).Contains("/rc hotkey add F11 /rdef use 3"), "an engine that can't: the exact line to type");

View file

@ -79,6 +79,11 @@ namespace RynthDefective.Tests
Run("window: a bar button of its own, one-shot size request", WindowHeader);
Run("window: slot clicks and editor events reach their code", WindowEvents);
Run("window: lists stay inside the engine's limits", WindowLimits);
Run("bar: the game's slots and own slots, usual and independent", BarMappingUsualAndIndependent);
Run("bar: a healing kit in one of the game's slots is used on you here", BarRetailKit);
Run("bar: making it independent offers to copy the game's 18 slots", BarIndependentCopy);
Run("store: the independent bar setting; files from before read it off", BarStoreIndependent);
Run("window: the settings window parses and its switches reach their code", BarSettingsWindow);
}
finally
{

View file

@ -0,0 +1,325 @@
using System.Text.Json;
using RynthCore.Plugin.RynthVision;
using RynthCore.Plugin.RynthVision.Light;
using RynthCore.Plugin.RynthVision.Ui;
namespace RynthVision.Tests;
/// <summary>
/// RynthVision's dungeon light (2026-10-27): where it lights, how brightly, its chat words and status
/// line, its settings keys; and the Vision window RynthVision draws in the engine's Vision panel's
/// place (its manifest, its pure rules, the settings it edits and saves).
/// </summary>
internal static class Program
{
private static int _checks, _failed;
// An outdoor cell (Holtburg), a building room and a dungeon cell (ids only; the flag is the test's).
private const uint Outdoor = 0xA9B40019, Room = 0xA9B40105, DungeonCell = 0x01D9012A;
private static int Main()
{
Places();
Scopes();
Levels();
Floors();
Percents();
Colours();
Commands();
Status();
SettingsJson();
Manifest();
WindowFields();
WaterTypes();
EngineKeys();
Console.WriteLine($"{_checks} checks, {_failed} failed");
return _failed == 0 ? 0 : 1;
}
private static void Check(bool ok, string what)
{
_checks++;
if (ok) return;
_failed++;
Console.WriteLine("FAIL: " + what);
}
private static void Eq<T>(T got, T want, string what) =>
Check(EqualityComparer<T>.Default.Equals(got, want), $"{what}: got {got}, want {want}");
private static void Places()
{
Eq(DungeonLight.Classify(Outdoor, null), LightPlace.Outdoors, "an outdoor cell");
Eq(DungeonLight.Classify(Outdoor, true), LightPlace.Outdoors, "an outdoor cell whatever the flag says");
Eq(DungeonLight.Classify(Room, true), LightPlace.Building, "an EnvCell that sees outside is a building");
Eq(DungeonLight.Classify(DungeonCell, false), LightPlace.Dungeon, "an EnvCell that doesn't is a dungeon");
Eq(DungeonLight.Classify(DungeonCell, null), LightPlace.Dungeon, "an EnvCell nobody could read counts as a dungeon");
Eq(DungeonLight.Classify(0, null), LightPlace.NotInWorld, "cell 0: not in the world");
Eq(DungeonLight.Classify(0x0000012A, false), LightPlace.NotInWorld, "landblock 0: not in the world (portal space)");
Eq(DungeonLight.Classify(0xA9B400FF, null), LightPlace.Outdoors, "0xFF is still an outdoor cell");
Eq(DungeonLight.Classify(0xA9B40100, null), LightPlace.Dungeon, "0x100 is the first EnvCell");
}
private static void Scopes()
{
foreach (LightScope s in Enum.GetValues<LightScope>())
{
Check(DungeonLight.Applies(s, LightPlace.Dungeon), $"{s}: lights dungeons");
Check(!DungeonLight.Applies(s, LightPlace.NotInWorld), $"{s}: nothing out of the world");
}
Check(!DungeonLight.Applies(LightScope.Dungeons, LightPlace.Building), "dungeons: not buildings");
Check(!DungeonLight.Applies(LightScope.Dungeons, LightPlace.Outdoors), "dungeons: not outdoors");
Check(DungeonLight.Applies(LightScope.Indoors, LightPlace.Building), "indoors: buildings");
Check(!DungeonLight.Applies(LightScope.Indoors, LightPlace.Outdoors), "indoors: not outdoors");
Check(DungeonLight.Applies(LightScope.Everywhere, LightPlace.Building), "everywhere: buildings");
Check(DungeonLight.Applies(LightScope.Everywhere, LightPlace.Outdoors), "everywhere: outdoors");
}
private static void Levels()
{
Check(Math.Abs(DungeonLight.Level(0) - 0.2f) < 1e-6, "strength 0 = AC's own 20 %");
Check(Math.Abs(DungeonLight.Level(100) - 1f) < 1e-6, "strength 100 = 100 %");
Check(Math.Abs(DungeonLight.Level(DungeonLight.DefaultStrength) - 0.52f) < 1e-6, "the default 40 = 52 %");
Check(Math.Abs(DungeonLight.Level(-20) - 0.2f) < 1e-6 && Math.Abs(DungeonLight.Level(500) - 1f) < 1e-6, "clamped");
}
private static void Floors()
{
Eq(DungeonLight.FloorRgb(0xFFFFFFFF, 0), 0u, "strength 0 sends no floor");
Eq(DungeonLight.FloorRgb(0xFFFFFFFF, -3), 0u, "below 0 sends no floor");
Eq(DungeonLight.FloorRgb(0xFFFFFFFF, 100), 0xFFFFFFu, "100 % white");
Eq(DungeonLight.FloorRgb(0xFFFFFFFF, 40), 0x858585u, "the default: 52 % white (133)");
Eq(DungeonLight.FloorRgb(0xFFFFD8A8, 40), 0x857057u, "torch at 40");
Check((DungeonLight.FloorRgb(0xFFFFFFFF, 1) & 0xFF) > 0x33, "any strength above 0 is brighter than AC's dungeon (0x33)");
Check((DungeonLight.FloorRgb(0xFFFFFFFF, 100) & 0xFF000000) == 0, "the floor has no alpha byte");
Eq(DungeonLight.FloorFor(false, LightScope.Everywhere, 40, 0xFFFFFFFF, LightPlace.Dungeon), 0u, "off: no floor");
Eq(DungeonLight.FloorFor(true, LightScope.Dungeons, 40, 0xFFFFFFFF, LightPlace.Outdoors), 0u, "dungeons only: none outdoors");
Eq(DungeonLight.FloorFor(true, LightScope.Dungeons, 40, 0xFFFFFFFF, LightPlace.NotInWorld), 0u, "none out of the world");
Eq(DungeonLight.FloorFor(true, LightScope.Dungeons, 40, 0xFFFFFFFF, LightPlace.Dungeon), 0x858585u, "on in a dungeon");
}
private static void Percents()
{
Eq(DungeonLight.Percent(0xFF333333), 20, "AC's dungeon ambient reads 20 %");
Eq(DungeonLight.Percent(0xFF858585), 52, "the default floor reads 52 %");
Eq(DungeonLight.Percent(0x00FF0000), 100, "the brightest channel");
Eq(DungeonLight.Percent(0), 0, "black");
}
private static void Colours()
{
Check(DungeonLight.TryParseColor("FFE0C0", out uint c) && c == 0xFFFFE0C0, "RRGGBB, made opaque");
Check(DungeonLight.TryParseColor("#ffe0c0", out c) && c == 0xFFFFE0C0, "lower case with '#'");
Check(DungeonLight.TryParseColor("80FFE0C0", out c) && c == 0xFFFFE0C0, "AARRGGBB: the alpha is dropped");
Check(DungeonLight.TryParseColor(" Torch ", out c) && c == 0xFFFFD8A8, "a preset by name");
Check(!DungeonLight.TryParseColor("nope", out _), "a word that isn't a preset");
Check(!DungeonLight.TryParseColor("12345", out _), "five hex digits");
Check(!DungeonLight.TryParseColor("", out _) && !DungeonLight.TryParseColor(null, out _), "nothing");
Eq(DungeonLight.ColorName(0xFFFFFFFF), "white", "white by name");
Eq(DungeonLight.ColorName(0xFFC8D8FF), "moon", "moon by name");
Eq(DungeonLight.ColorName(0xFF102030), "102030", "any other colour as hex");
}
private static void Commands()
{
Eq(DungeonLight.ParseCommand("").Kind, LightCommandKind.Toggle, "/rv light alone toggles");
Eq(DungeonLight.ParseCommand(null).Kind, LightCommandKind.Toggle, "null toggles");
Eq(DungeonLight.ParseCommand(" on ").Kind, LightCommandKind.On, "on");
Eq(DungeonLight.ParseCommand("off").Kind, LightCommandKind.Off, "off");
Eq(DungeonLight.ParseCommand("toggle").Kind, LightCommandKind.Toggle, "toggle");
LightCommand n = DungeonLight.ParseCommand("60");
Check(n.Kind == LightCommandKind.Strength && n.Strength == 60, "a number is the strength");
n = DungeonLight.ParseCommand("75%");
Check(n.Kind == LightCommandKind.Strength && n.Strength == 75, "with a %");
Check(DungeonLight.ParseCommand("0").Kind == LightCommandKind.Strength && DungeonLight.ParseCommand("100").Strength == 100, "the ends");
Eq(DungeonLight.ParseCommand("101").Kind, LightCommandKind.Error, "above 100");
Eq(DungeonLight.ParseCommand("-5").Kind, LightCommandKind.Error, "below 0");
Eq(DungeonLight.ParseCommand("dungeons").Scope, LightScope.Dungeons, "dungeons");
Eq(DungeonLight.ParseCommand("indoors").Scope, LightScope.Indoors, "indoors");
Eq(DungeonLight.ParseCommand("everywhere").Scope, LightScope.Everywhere, "everywhere");
Eq(DungeonLight.ParseCommand("all").Kind, LightCommandKind.Scope, "all = everywhere");
LightCommand col = DungeonLight.ParseCommand("color torch");
Check(col.Kind == LightCommandKind.Color && col.ColorArgb == 0xFFFFD8A8, "color torch");
col = DungeonLight.ParseCommand("colour 00ff00");
Check(col.Kind == LightCommandKind.Color && col.ColorArgb == 0xFF00FF00, "colour 00ff00");
Eq(DungeonLight.ParseCommand("color").Kind, LightCommandKind.Error, "color without one");
Eq(DungeonLight.ParseCommand("color xyz").Kind, LightCommandKind.Error, "a bad colour");
Eq(DungeonLight.ParseCommand("show").Kind, LightCommandKind.Show, "show");
Eq(DungeonLight.ParseCommand("window").Kind, LightCommandKind.Show, "window");
Eq(DungeonLight.ParseCommand("status").Kind, LightCommandKind.Status, "status");
Eq(DungeonLight.ParseCommand("help").Kind, LightCommandKind.Help, "help");
LightCommand bad = DungeonLight.ParseCommand("brighter please");
Check(bad.Kind == LightCommandKind.Error && bad.Error.Contains("brighter please"), "an unknown word names itself");
}
private static LightStatus S(bool on = true, LightScope scope = LightScope.Dungeons, LightPlace place = LightPlace.Dungeon,
bool api = true, bool live = true, uint client = 0xFF333333, uint applied = 0xFF858585) =>
new(on, scope, 40, place, api, live, client, applied);
private static void Status()
{
string line = DungeonLight.StatusLine(S());
Check(line.Contains("dungeon") && line.Contains("20%") && line.Contains("52%"), "lighting a dungeon names the levels: " + line);
Check(DungeonLight.StatusLine(S(api: false)).Contains("newer RynthCore"), "an older engine");
Check(DungeonLight.IsWarning(S(api: false)), "an older engine is a warning");
Check(DungeonLight.StatusLine(S(on: false)).StartsWith("Off"), "off");
Check(!DungeonLight.IsWarning(S(on: false, live: false)), "off with the hook off isn't a warning");
Check(DungeonLight.StatusLine(S(live: false)).Contains("/rc hooks"), "the hook off");
Check(DungeonLight.IsWarning(S(live: false)), "the hook off is a warning");
Check(DungeonLight.StatusLine(S(place: LightPlace.Outdoors)).Contains("not lighting here"), "outdoors with dungeons only");
Check(DungeonLight.StatusLine(S(place: LightPlace.NotInWorld)).Contains("waiting"), "out of the world");
Check(DungeonLight.StatusLine(S(scope: LightScope.Everywhere, place: LightPlace.Outdoors)).StartsWith("Lighting outdoors"), "everywhere, outdoors");
Check(!DungeonLight.StatusLine(S(client: 0, applied: 0)).Contains("->"), "no levels before the first frame");
}
private static void SettingsJson()
{
var d = new VisionSettings();
Check(!d.LightOn && d.LightStrength == 40 && d.LightColorArgb == 0xFFFFFFFF && d.LightScope == 0,
"defaults: off, 40, white, dungeons");
using (JsonDocument doc = JsonDocument.Parse(d.ToJson()))
{
JsonElement r = doc.RootElement;
Check(r.GetProperty("light").GetInt32() == 0 && r.GetProperty("lightStrength").GetInt32() == 40
&& r.GetProperty("lightColor").GetUInt32() == 0xFFFFFFFF && r.GetProperty("lightScope").GetInt32() == 0,
"ToJson carries the light keys");
Check(r.TryGetProperty("radar", out _) && r.TryGetProperty("waterTypes", out _), "and still the old ones");
}
var s = new VisionSettings();
s.ApplyJson("{\"light\":1,\"lightStrength\":65,\"lightColor\":4294957216,\"lightScope\":2}");
Check(s.LightOn && s.LightStrength == 65 && s.LightColorArgb == 4294957216u && s.LightScope == 2, "ApplyJson reads them");
var back = new VisionSettings();
back.ApplyJson(s.ToJson());
Check(back.LightOn && back.LightStrength == 65 && back.LightColorArgb == s.LightColorArgb && back.LightScope == 2, "round trip");
var c = new VisionSettings();
c.ApplyJson("{\"lightStrength\":250,\"lightColor\":16777215,\"lightScope\":9}");
Check(c.LightStrength == 100 && c.LightColorArgb == 0xFFFFFFFF && c.LightScope == 2, "pulled into range; the colour made opaque");
c.ApplyJson("{\"lightStrength\":-4,\"lightScope\":-1}");
Check(c.LightStrength == 0 && c.LightScope == 0, "low values pulled up");
// One field at a time (what the engine's Vision panel sends) leaves the light alone.
s.ApplyJson("{\"radar\":0}");
Check(s.LightOn && s.LightStrength == 65 && !s.ShowRadarRing, "another key leaves the light as it was");
}
private static void Manifest()
{
using JsonDocument doc = JsonDocument.Parse(VisionManifest.Json(true));
Check(doc.RootElement.GetProperty("version").GetInt32() == 1, "manifest version 1");
Check(!doc.RootElement.TryGetProperty("sections", out _) && !doc.RootElement.TryGetProperty("contributions", out _),
"nothing for the Mini Remote's sections");
JsonElement ws = doc.RootElement.GetProperty("windows");
Eq(ws.GetArrayLength(), 1, "one window: Vision (the separate Dungeon Light window is gone)");
JsonElement w = ws[0];
// The engine panel's key (RynthCore ImGui/Panels/VisionFace.Title): the take-over keeps its saved place.
Check(w.GetProperty("id").GetString() == "vision" && w.GetProperty("title").GetString() == "Vision"
&& VisionManifest.Title == "Vision", "the window's id and title: the engine's Vision panel's key");
Check(w.GetProperty("surface").GetString() == VisionManifest.Surface && VisionManifest.Surface == "window:vision", "its surface");
Check(w.GetProperty("takeOver").GetBoolean(), "it takes the engine's Vision panel's place");
Eq(w.GetProperty("icon").GetString(), "", "no icon of its own: the engine bar's eye for Vision");
Check(w.GetProperty("bar").GetBoolean() && w.GetProperty("edgeToEdge").GetBoolean(), "a bar button (the engine's steps aside); edge to edge");
Check(!w.TryGetProperty("chrome", out _) && !w.TryGetProperty("fitHeight", out _), "the engine's header and frame, sized by the player");
Check(w.GetProperty("width").GetInt32() == VisionManifest.Width && w.GetProperty("height").GetInt32() == VisionManifest.Height
&& w.GetProperty("minWidth").GetInt32() == VisionManifest.MinWidth && w.GetProperty("minHeight").GetInt32() == VisionManifest.MinHeight,
"the constants are the JSON's");
Check(VisionManifest.Width == 320 && VisionManifest.Height == 560 && VisionManifest.MinWidth == 280 && VisionManifest.MinHeight == 240,
"the engine face's sizes (PanelSpec 320 x 560, at least 280 x 240)");
using JsonDocument none = JsonDocument.Parse(VisionManifest.Json(false));
Check(!none.RootElement.TryGetProperty("windows", out _), "an older engine: no window, its own Vision panel stays");
Check(VisionManifest.HostsWindow(true, true, true, true), "v91 with plugin windows: hosted");
Check(!VisionManifest.HostsWindow(false, true, true, true), "no light hook (before v91): not hosted");
Check(!VisionManifest.HostsWindow(true, false, true, true), "no SetPanelOpen: not hosted");
Check(!VisionManifest.HostsWindow(true, true, false, true), "no engine drawers (Nameplates, Combat text): not hosted");
Check(!VisionManifest.HostsWindow(true, true, true, false), "no engine look: not hosted");
}
private static void WindowFields()
{
Eq(VisionFields.TabNames.Length, Enum.GetValues<VisionTab>().Length, "a name per tab");
Check(VisionFields.TabNames[0] == "Terrain" && VisionFields.TabNames[1] == "Nameplates" && VisionFields.TabNames[2] == "Combat text"
&& VisionFields.TabNames[3] == "Light", "the engine's three tabs, then Light");
Eq(VisionFields.EngineTabKey(VisionTab.Nameplates), "nameplates", "Nameplates: the engine's body");
Eq(VisionFields.EngineTabKey(VisionTab.CombatText), "combattext", "Combat text: the engine's body");
Check(VisionFields.EngineTabKey(VisionTab.Terrain) == null && VisionFields.EngineTabKey(VisionTab.Light) == null,
"Terrain and Light are RynthVision's own");
Check(Math.Abs(VisionFields.OpacityPercent(0x80FFD000) - 50.196f) < 0.01f, "0x80 = 50 %");
Eq(VisionFields.WithOpacity(0x60FF2020, 100f), 0xFFFF2020u, "100 %: alpha FF, RGB kept");
Eq(VisionFields.WithOpacity(0x60FF2020, 0f), 0x00FF2020u, "0 %: alpha 00");
Eq(VisionFields.WithOpacity(0x60FF2020, 250f), 0xFFFF2020u, "clamped high");
Eq(VisionFields.WithOpacity(0x60FF2020, float.NaN), 0x00FF2020u, "NaN reads 0");
Eq(VisionFields.WithOpacity(0x60FF2020, VisionFields.OpacityPercent(0x60FF2020)), 0x60FF2020u, "untouched it round-trips");
Check(VisionFields.TryParseHex("80FFD000", out uint c) && c == 0x80FFD000, "AARRGGBB");
Check(VisionFields.TryParseHex("#ff2020", out c) && c == 0xFFFF2020, "RRGGBB with '#': opaque");
Check(!VisionFields.TryParseHex("FF20", out _) && !VisionFields.TryParseHex("", out _) && !VisionFields.TryParseHex("GG000000", out _),
"bad hex");
Check(VisionFields.ParseCsv("18, 19,x,20").SequenceEqual(new[] { 18, 19, 20 }), "csv: numbers kept, words dropped");
Check(VisionFields.ParseCsv(" ").Count == 0 && VisionFields.ParseCsv(null).Count == 0, "csv: nothing");
Eq(VisionFields.Csv(new[] { 16, 17, 18 }), "16,17,18", "csv out");
}
private static void WaterTypes()
{
int[] defaults = new VisionSettings().WaterTerrainTypes;
Check(defaults.SequenceEqual(new[] { 16, 17, 18, 19, 20 }), "the defaults: ACE's water types 16-20");
Check(VisionSettings.NormalizeWaterTypes(Array.Empty<int>()).SequenceEqual(defaults), "empty: back to the defaults");
Check(VisionSettings.NormalizeWaterTypes(new[] { 40, -1 }).SequenceEqual(defaults), "all invalid: the defaults");
Check(VisionSettings.NormalizeWaterTypes(new[] { 19, 18, 19, 99 }).SequenceEqual(new[] { 19, 18 }), "in range, each once, in order");
Check(!ReferenceEquals(VisionSettings.NormalizeWaterTypes(Array.Empty<int>()), VisionSettings.NormalizeWaterTypes(Array.Empty<int>())),
"the defaults are a fresh array each time (never shared, never changed in place)");
// ApplyJson (the engine's panels, the file) still normalises the same way.
var s = new VisionSettings();
s.ApplyJson("{\"waterTypes\":[18,18,33]}");
Check(s.WaterTerrainTypes.SequenceEqual(new[] { 18 }), "ApplyJson: 33 dropped, 18 once");
s.ApplyJson("{\"waterTypes\":[]}");
Check(s.WaterTerrainTypes.SequenceEqual(defaults), "ApplyJson: empty is the defaults");
// Clone: the window's copy. Changing it leaves the tick's settings alone.
var a = new VisionSettings { ShowRadarRing = true, SlopeRenderRadius = 9 };
VisionSettings b = a.Clone();
b.ShowRadarRing = false;
b.SlopeRenderRadius = 3;
b.WaterTerrainTypes = new[] { 18 };
Check(a.ShowRadarRing && a.SlopeRenderRadius == 9 && a.WaterTerrainTypes.SequenceEqual(defaults), "a clone is a copy");
Check(new VisionSettings { LightStrength = 77 }.Clone().LightStrength == 77, "the light's settings are copied too");
}
/// <summary>
/// Every key the engine's Vision panel saved (RynthCore UI/Data/VisionKeys) is still written and read: the
/// window edits the same settings in the same file, so a player's choices carry over.
/// </summary>
private static void EngineKeys()
{
string[] keys =
{
"radar", "slopes", "water", "waterAnyCorner", "waterImpassableOnly", "slopeColor", "waterColor", "radarColor",
"radarRange", "ringThick", "ringHeight", "slopeRadius", "slopeFloorZ", "slopeBias", "waterRadius", "waterTypes",
};
var src = new VisionSettings
{
ShowRadarRing = false, ShowUnclimbableSlopes = true, ShowImpassableWater = true, WaterAnyCorner = false,
WaterImpassableOnly = false, SlopeColorArgb = 0x11223344, WaterColorArgb = 0x55667788, RadarRingColorArgb = 0x99AABBCC,
RadarRangeWorld = 120f, RadarRingThickness = 3.5f, RadarRingHeight = 7f, SlopeRenderRadius = 5, SlopeFloorZ = 0.5f,
SlopeHeightBias = 0.25f, WaterRenderRadius = 6, WaterTerrainTypes = new[] { 17, 19 },
};
string json = src.ToJson();
using (JsonDocument doc = JsonDocument.Parse(json))
foreach (string k in keys)
Check(doc.RootElement.TryGetProperty(k, out _), $"ToJson writes \"{k}\"");
var back = new VisionSettings();
back.ApplyJson(json);
Check(!back.ShowRadarRing && back.ShowUnclimbableSlopes && back.ShowImpassableWater && !back.WaterAnyCorner && !back.WaterImpassableOnly,
"the toggles round-trip");
Check(back.SlopeColorArgb == 0x11223344 && back.WaterColorArgb == 0x55667788 && back.RadarRingColorArgb == 0x99AABBCC, "the colours");
Check(back.RadarRangeWorld == 120f && back.RadarRingThickness == 3.5f && back.RadarRingHeight == 7f && back.SlopeRenderRadius == 5
&& back.SlopeFloorZ == 0.5f && back.SlopeHeightBias == 0.25f && back.WaterRenderRadius == 6, "the tuning");
Check(back.WaterTerrainTypes.SequenceEqual(new[] { 17, 19 }), "the water types");
}
}

View file

@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<!--
Offline checks for RynthVision's dungeon light (2026-10-27): the rules (Light\DungeonLight.cs:
where the player is the way AC decides it, where the light applies, the floor it hands RynthCore
for a strength and colour, the colour words, /rv light, the status line), the settings' new JSON
keys (VisionSettings.cs: defaults, round trip, out-of-range values pulled in; Save/Load and
%APPDATA% aren't touched). Since 2026-10-27 RynthVision draws the whole Vision window (it takes
over the engine's Vision panel): its manifest (Ui\VisionManifest.cs: the engine panel's title and
sizes, "takeOver", only on an engine that hosts it), its pure rules (Ui\VisionFields.cs: opacity,
hex, the water-type list, the tabs), the water types' normalising and Clone, and that every key the
engine's panel saved is still read and written. The window itself draws with ImGui and isn't
compiled here.
Run: dotnet run -c Release (exit 0 = pass, 1 = fail)
-->
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<RootNamespace>RynthVision.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthVision\Light\DungeonLight.cs" Link="RynthVision\DungeonLight.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthVision\Ui\VisionManifest.cs" Link="RynthVision\VisionManifest.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthVision\Ui\VisionFields.cs" Link="RynthVision\VisionFields.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthVision\VisionSettings.cs" Link="RynthVision\VisionSettings.cs" />
</ItemGroup>
</Project>