RynthSuite as of 2026-11-26 (internal 1db112e): release 2026.11.26.1
This commit is contained in:
parent
90e76a6561
commit
25552fa794
175 changed files with 23428 additions and 494 deletions
249
Tools/RynthSort.Tests/AddSelectedTests.cs
Normal file
249
Tools/RynthSort.Tests/AddSelectedTests.cs
Normal file
|
|
@ -0,0 +1,249 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthSort;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
using RynthCore.Plugin.RynthSort.Views;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// "Add selected": the selected item's name goes into a pack's rules (rule text, no duplicates,
|
||||
// which pack already takes the item, nothing selected / not an item), and the window's button.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static SelectedItem ItemSel(SortItem it) => new() { Kind = SelectionKind.Item, Id = it.Id, Name = it.Name, Item = it };
|
||||
|
||||
private static void AddSelectedText()
|
||||
{
|
||||
Eq(AddSelectedRules.EntryFor("Black Opal"), "Black Opal", "a plain name stays");
|
||||
Eq(AddSelectedRules.EntryFor("Salvaged Iron (100)"), "Salvaged Iron", "a bag's count is left out");
|
||||
Eq(AddSelectedRules.EntryFor(" Salvaged Steel (3) "), "Salvaged Steel", "whatever the count, spaces too");
|
||||
Eq(AddSelectedRules.EntryFor("Sword (Flaming)"), "Sword (Flaming)", "a bracket that isn't a count stays");
|
||||
Eq(AddSelectedRules.EntryFor("(5)"), "(5)", "a name that is only a count stays");
|
||||
Eq(AddSelectedRules.EntryFor(new string('x', 100)).Length, SortRule.MaxNameLength, "a long name is cut like a typed one");
|
||||
Eq(AddSelectedRules.EntryFor(null), "", "no name, no entry");
|
||||
|
||||
// The entry matches the item it came from, and the same item at another stack size.
|
||||
var iron100 = It(1, "Salvaged Iron (100)", ObjectClasses.Salvage);
|
||||
var iron37 = It(2, "Salvaged Iron (37)", ObjectClasses.Salvage);
|
||||
SortRule r = SortRule.ForName(AddSelectedRules.EntryFor(iron100.Name), 4);
|
||||
Check(SortRules.Matches(r, iron100) && SortRules.Matches(r, iron37), "the entry takes the bag and other bags of it");
|
||||
Eq(SortRules.Describe(r), "name has \"Salvaged Iron\"", "the rule's text");
|
||||
}
|
||||
|
||||
private static void AddSelectedLookup()
|
||||
{
|
||||
var inv = Inv(2);
|
||||
inv.Main.Items.Add(It(10, "Black Opal", ObjectClasses.Gem));
|
||||
inv.Packs[1].Items.Add(It(20, "Lead Scarab", ObjectClasses.SpellComponent));
|
||||
inv.Slots.Add(new SortSlot(inv.Packs[0].Id, 24));
|
||||
inv.Slots.Add(new SortSlot(0x40000F01, 0));
|
||||
|
||||
Eq(SelectionLookup.Find(inv, 0, "").Kind, SelectionKind.Nothing, "id 0: nothing selected");
|
||||
SelectedItem a = SelectionLookup.Find(inv, 10, "x");
|
||||
Check(a.Kind == SelectionKind.Item && a.Item!.Name == "Black Opal" && a.Name == "Black Opal", "an item in the main pack");
|
||||
Eq(SelectionLookup.Find(inv, 20, "").Kind, SelectionKind.Item, "an item in a side pack");
|
||||
SelectedItem pack = SelectionLookup.Find(inv, inv.Packs[0].Id, "Sack");
|
||||
Check(pack.Kind == SelectionKind.Pack && pack.Name == "Sack", "a pack is not an item");
|
||||
Eq(SelectionLookup.Find(inv, 0x40000F01, "Foci").Kind, SelectionKind.Pack, "a focus is not an item");
|
||||
SelectedItem far = SelectionLookup.Find(inv, 0x70000001, "Drudge");
|
||||
Check(far.Kind == SelectionKind.NotInPacks && far.Name == "Drudge", "an object that isn't in the packs");
|
||||
}
|
||||
|
||||
private static void AddSelectedRefusals()
|
||||
{
|
||||
var inv = Inv(3);
|
||||
var c = Sorter();
|
||||
c.Planner.Plan(inv, c.Data.Rules, SortScope.Main, true, 0, 0);
|
||||
List<SortRule> rules = c.Data.Rules;
|
||||
string before = string.Join("|", rules.Select(SortRules.Describe));
|
||||
SortView v = c.Planner.View;
|
||||
|
||||
foreach (SelectionKind kind in new[] { SelectionKind.Unavailable, SelectionKind.NoInventory, SelectionKind.Nothing, SelectionKind.Pack, SelectionKind.NotInPacks })
|
||||
{
|
||||
AddOutcome o = AddSelectedRules.Apply(rules, v, 1, SelectedItem.Of(kind, 7, "Thing"));
|
||||
Check(o.Status == AddStatus.Refused && o.Rule == null && o.Message.Contains("Nothing was added"), $"{kind}: refused, says nothing was added ({o.Message})");
|
||||
}
|
||||
Check(AddSelectedRules.Apply(rules, v, 1, SelectedItem.Of(SelectionKind.Nothing)).Message.Contains("Nothing is selected"), "nothing selected says so");
|
||||
Check(AddSelectedRules.Apply(rules, v, 1, SelectedItem.Of(SelectionKind.Pack, 7, "Sack")).Message.Contains("is a pack"), "a pack says so");
|
||||
Check(AddSelectedRules.Apply(rules, v, 1, SelectedItem.Of(SelectionKind.NotInPacks, 7, "Drudge")).Message.Contains("isn't an item in your packs"), "not in the packs says so");
|
||||
|
||||
var opal = It(10, "Black Opal", ObjectClasses.Gem);
|
||||
Eq(AddSelectedRules.Apply(rules, v, 4, ItemSel(opal)).Status, AddStatus.Refused, "a pack you don't carry");
|
||||
Eq(AddSelectedRules.Apply(rules, v, 0, ItemSel(opal)).Status, AddStatus.Refused, "pack 0");
|
||||
Eq(AddSelectedRules.Apply(rules, v, 1, ItemSel(It(11, "", ObjectClasses.Gem))).Status, AddStatus.Refused, "an item with no name yet");
|
||||
Eq(AddSelectedRules.Apply(rules, v, 1, new SelectedItem { Kind = SelectionKind.Item, Id = 5 }).Status, AddStatus.Refused, "an item selection without its item");
|
||||
Eq(string.Join("|", rules.Select(SortRules.Describe)), before, "no refusal changed a rule");
|
||||
}
|
||||
|
||||
private static void AddSelectedAdds()
|
||||
{
|
||||
var inv = Inv(4);
|
||||
var c = Sorter();
|
||||
c.Planner.Plan(inv, c.Data.Rules, SortScope.Main, true, 0, 0);
|
||||
List<SortRule> rules = c.Data.Rules;
|
||||
SortView v = c.Planner.View;
|
||||
int count = rules.Count;
|
||||
|
||||
// A new rule (pack 4 has none): one name, the pack's id kept.
|
||||
var tapers = It(30, "Prismatic Taper", ObjectClasses.SpellComponent, stack: 80, max: 100);
|
||||
AddOutcome o = AddSelectedRules.Apply(rules, v, 4, ItemSel(tapers));
|
||||
Check(o.Status == AddStatus.Added && o.Rule != null && rules.Contains(o.Rule!), "added as a new rule");
|
||||
Eq(rules.Count, count + 1, "one rule more");
|
||||
Check(o.Rule!.Pack == 4 && o.Rule.PackId == inv.Packs[3].Id, "the rule is pack 4's, by id");
|
||||
Check(o.Rule.Names.Count == 1 && o.Rule.HasName("Prismatic Taper") && o.Rule.Classes.Count == 0, "one name, no class");
|
||||
Check(o.Message.Contains("Added \"Prismatic Taper\" to pack 4 (Pack 4) as a new rule"), $"says what it added ({o.Message})");
|
||||
Check(o.Message.Contains("It was going to pack 1") && o.Message.Contains("Now it goes here"), $"says the class rule had it, and that it goes here now ({o.Message})");
|
||||
Eq(SortRules.RuleFor(rules, tapers)?.Pack, 4, "the name beats the class: it goes to pack 4 now");
|
||||
|
||||
// A second item goes into the same rule (it already lists names), not a rule each.
|
||||
var opal = It(31, "Black Opal", ObjectClasses.Gem);
|
||||
AddOutcome o2 = AddSelectedRules.Apply(rules, v, 4, ItemSel(opal));
|
||||
Check(o2.Status == AddStatus.Added && ReferenceEquals(o2.Rule, o.Rule), "the next name joins that rule");
|
||||
Eq(rules.Count, count + 1, "no rule more");
|
||||
Check(o.Rule.HasName("Black Opal") && o.Rule.Names.Count == 2, "both names are in it");
|
||||
Check(!o2.Message.Contains("as a new rule") && o2.Message.Contains("name has \"Black Opal\", name has \"Prismatic Taper\""), $"shows the rule ({o2.Message})");
|
||||
|
||||
// A bag of salvage (no rule wants it): its name without the count, no "was going to".
|
||||
var iron = It(32, "Salvaged Iron (100)", ObjectClasses.Misc);
|
||||
AddOutcome o3 = AddSelectedRules.Apply(rules, v, 4, ItemSel(iron));
|
||||
Check(o3.Status == AddStatus.Added && o3.Rule!.HasName("Salvaged Iron") && !o3.Rule.HasName("Salvaged Iron (100)"), "a bag is added without its count");
|
||||
Check(!o3.Message.Contains("was going to"), "no rule had it before");
|
||||
Eq(SortRules.RuleFor(rules, It(33, "Salvaged Iron (12)", ObjectClasses.Misc))?.Pack, 4, "another bag of it goes there too");
|
||||
|
||||
// A rule that is off isn't joined.
|
||||
o.Rule.On = false;
|
||||
AddOutcome o4 = AddSelectedRules.Apply(rules, v, 4, ItemSel(It(34, "Buckler", ObjectClasses.Armor)));
|
||||
Check(o4.Status == AddStatus.Added && !ReferenceEquals(o4.Rule, o.Rule) && o4.Message.Contains("as a new rule"), "an off rule is left as it is");
|
||||
o.Rule.On = true;
|
||||
|
||||
// Full rules (16 names) aren't joined: a new rule.
|
||||
foreach (SortRule r in rules.Where(r => r.Pack == 4))
|
||||
for (int i = 0; r.Names.Count < SortRule.MaxNames; i++) r.AddName("filler " + r.Uid + " " + i);
|
||||
AddOutcome o5 = AddSelectedRules.Apply(rules, v, 4, ItemSel(It(35, "Ruby", ObjectClasses.Gem)));
|
||||
Check(o5.Status == AddStatus.Added && o5.Rule != null && o5.Rule.Names.Count == 1 && o5.Message.Contains("as a new rule"), "full rules: a new one");
|
||||
|
||||
// At the rule limit the name goes into a rule of the pack that has room; none: refused.
|
||||
var many = new List<SortRule>();
|
||||
for (int i = 0; i < SortStore.MaxRules - 1; i++) many.Add(SortRule.ForClass(ObjectClasses.Armor, 1));
|
||||
var roomy = SortRule.ForClass(ObjectClasses.Food, 2);
|
||||
many.Add(roomy);
|
||||
AddOutcome o6 = AddSelectedRules.Apply(many, v, 2, ItemSel(It(36, "Apple", ObjectClasses.Misc)));
|
||||
Check(o6.Status == AddStatus.Added && ReferenceEquals(o6.Rule, roomy) && roomy.HasName("Apple") && many.Count == SortStore.MaxRules, "at the limit: into the pack's rule with room");
|
||||
AddOutcome o7 = AddSelectedRules.Apply(many, v, 3, ItemSel(It(37, "Pear", ObjectClasses.Misc)));
|
||||
Check(o7.Status == AddStatus.Refused && many.Count == SortStore.MaxRules && o7.Message.Contains("no room"), $"at the limit, pack without a rule: refused ({o7.Message})");
|
||||
}
|
||||
|
||||
private static void AddSelectedDuplicates()
|
||||
{
|
||||
var inv = Inv(4);
|
||||
var c = Sorter();
|
||||
c.Planner.Plan(inv, c.Data.Rules, SortScope.Main, true, 0, 0);
|
||||
List<SortRule> rules = c.Data.Rules; // components 1, salvage 2, gems/stones/keys 3
|
||||
SortView v = c.Planner.View;
|
||||
rules.Add(SortRule.For(4, Array.Empty<int>(), "Opal"));
|
||||
SortRule four = rules[^1];
|
||||
string Dump() => string.Join("|", rules.Select(r => SortRules.Describe(r) + ">" + r.Pack + (r.On ? "" : "off")));
|
||||
string before = Dump();
|
||||
|
||||
var blackOpal = It(40, "Black Opal", ObjectClasses.Gem);
|
||||
AddOutcome same = AddSelectedRules.Apply(rules, v, 4, ItemSel(It(41, "Opal", ObjectClasses.Gem)));
|
||||
Check(same.Status == AddStatus.AlreadyThere && same.Message.Contains("already in pack 4"), $"the same name: already there ({same.Message})");
|
||||
AddOutcome inside = AddSelectedRules.Apply(rules, v, 4, ItemSel(blackOpal));
|
||||
Check(inside.Status == AddStatus.AlreadyThere && inside.Message.Contains("name has \"Opal\""), $"a shorter name in the pack covers it ({inside.Message})");
|
||||
AddOutcome anyCase = AddSelectedRules.Apply(rules, v, 4, ItemSel(It(42, "OPAL", ObjectClasses.Gem)));
|
||||
Eq(anyCase.Status, AddStatus.AlreadyThere, "any case");
|
||||
Eq(Dump(), before, "duplicates change nothing");
|
||||
|
||||
// Taken by a class rule of this pack (and no name elsewhere): already goes here.
|
||||
AddOutcome byClass = AddSelectedRules.Apply(rules, v, 3, ItemSel(It(43, "Ruby", ObjectClasses.Gem)));
|
||||
Check(byClass.Status == AddStatus.AlreadyThere && byClass.Message.Contains("already goes to pack 3") && byClass.Message.Contains("Gem"), $"a class rule of the pack: already goes there ({byClass.Message})");
|
||||
Eq(Dump(), before, "and nothing changes");
|
||||
|
||||
// A rule that is off doesn't take it, but a second copy isn't added either.
|
||||
four.On = false;
|
||||
string beforeOff = Dump();
|
||||
AddOutcome off = AddSelectedRules.Apply(rules, v, 4, ItemSel(blackOpal));
|
||||
Check(off.Status == AddStatus.AlreadyThere && off.Message.Contains("turned off"), $"an off rule: say so ({off.Message})");
|
||||
Eq(Dump(), beforeOff, "nothing changes");
|
||||
four.On = true;
|
||||
|
||||
// Another pack's name rule wins over this pack's covering rule: said, nothing added.
|
||||
var wins = SortRule.For(1, Array.Empty<int>(), "Black");
|
||||
rules.Insert(0, wins);
|
||||
AddOutcome loses = AddSelectedRules.Apply(rules, v, 4, ItemSel(blackOpal));
|
||||
Check(loses.Status == AddStatus.AlreadyThere && loses.Message.Contains("rule for pack 1") && loses.Message.Contains("wins"), $"already there but another pack's rule wins ({loses.Message})");
|
||||
rules.Remove(wins);
|
||||
}
|
||||
|
||||
private static void AddSelectedOtherPack()
|
||||
{
|
||||
var inv = Inv(4);
|
||||
var c = Sorter();
|
||||
c.Planner.Plan(inv, c.Data.Rules, SortScope.Main, true, 0, 0);
|
||||
List<SortRule> rules = c.Data.Rules;
|
||||
SortView v = c.Planner.View;
|
||||
var opal = It(50, "Black Opal", ObjectClasses.Gem); // gems go to pack 3
|
||||
|
||||
// Claimed by pack 3's class rule: pressing Add for pack 4 adds there and says pack 3 had it.
|
||||
AddOutcome o = AddSelectedRules.Apply(rules, v, 4, ItemSel(opal));
|
||||
Check(o.Status == AddStatus.Added && o.Message.Contains("It was going to pack 3") && o.Message.Contains("Gem"), $"says which pack had it ({o.Message})");
|
||||
Check(o.Message.Contains("Now it goes here") && SortRules.RuleFor(rules, opal)?.Pack == 4, "and that the new name wins");
|
||||
Check(rules.Count(r => r.Pack == 3) == 1 && rules.Single(r => r.Pack == 3).HasClass(ObjectClasses.Gem), "pack 3's rule is untouched (nothing moved)");
|
||||
|
||||
// Claimed by another pack's NAME rule that comes first: still added, and it says that rule still wins.
|
||||
var rules2 = new List<SortRule> { SortRule.For(2, Array.Empty<int>(), "Opal") };
|
||||
AddOutcome o2 = AddSelectedRules.Apply(rules2, v, 4, ItemSel(opal));
|
||||
Check(o2.Status == AddStatus.Added && o2.Message.Contains("It was going to pack 2") && o2.Message.Contains("still wins"), $"a name rule that wins is said ({o2.Message})");
|
||||
Eq(SortRules.RuleFor(rules2, opal)?.Pack, 2, "it really does still win");
|
||||
Check(rules2.Count == 2 && rules2[0].Names.Count == 1 && rules2[1].HasName("Black Opal"), "the other pack's rule is untouched");
|
||||
|
||||
// A rule for a pack the character doesn't carry isn't a claim: this pack gets the item.
|
||||
var rules3 = new List<SortRule> { SortRule.ForClass(ObjectClasses.Gem, 9) };
|
||||
AddOutcome o3 = AddSelectedRules.Apply(rules3, v, 1, ItemSel(opal));
|
||||
Check(o3.Status == AddStatus.Added && SortRules.RuleFor(rules3, opal)?.Pack == 1, "a rule for a pack you don't have: this pack gets it");
|
||||
}
|
||||
|
||||
private static void AddSelectedWindow()
|
||||
{
|
||||
var (c, panel, host, w) = Window();
|
||||
var opal = It(10, "Black Opal", ObjectClasses.Gem);
|
||||
SelectedItem current = SelectedItem.Of(SelectionKind.Nothing);
|
||||
panel.ReadSelected = () => current;
|
||||
Draw(w, panel);
|
||||
Check(BodyText(w).Contains("+ Add selected"), "every pack has an Add selected button");
|
||||
uint seq = 0;
|
||||
void Press(string id)
|
||||
{
|
||||
Apply(host, Event(1, ++seq, w.Hash, w.KeyOf(id), Click));
|
||||
Draw(w, panel);
|
||||
}
|
||||
int rules = c.Data.Rules.Count;
|
||||
|
||||
Press("addsel.40000004");
|
||||
Eq(c.Data.Rules.Count, rules, "nothing selected: no rule");
|
||||
Check(BodyText(w).Contains("Nothing is selected"), "and the window says so");
|
||||
|
||||
current = ItemSel(opal);
|
||||
Press("addsel.40000004");
|
||||
Eq(c.Data.Rules.Count, rules + 1, "an item: a rule");
|
||||
SortRule added = c.Data.Rules[^1];
|
||||
Check(added.HasName("Black Opal") && added.PackId == 0x40000004 && ReferenceEquals(panel.Selected, added), "its name, pack 4, editor open");
|
||||
string body = BodyText(w);
|
||||
Check(body.Contains("Added \"Black Opal\" to pack 4") && body.Contains("name has \"Black Opal\""), "the window says what was added and shows the rule");
|
||||
Check(body.IndexOf("Added \"Black Opal\"", StringComparison.Ordinal) > body.IndexOf("Pack 4: ", StringComparison.Ordinal), "the note sits in pack 4's section");
|
||||
|
||||
Press("addsel.40000004");
|
||||
Eq(c.Data.Rules.Count, rules + 1, "again: no duplicate");
|
||||
Check(BodyText(w).Contains("already in pack 4"), "the window says it is there already");
|
||||
|
||||
AddOutcome viaCommand = panel.AddSelected(2);
|
||||
Check(viaCommand.Status == AddStatus.Added && c.Data.Rules.Any(r => r.Pack == 2 && r.HasName("Black Opal")), "the command's path adds to the pack it names");
|
||||
Check(viaCommand.Message.Contains("pack 4"), $"and says pack 4 had it ({viaCommand.Message})");
|
||||
Eq(panel.AddSelected(9).Status, AddStatus.Refused, "a pack that doesn't exist");
|
||||
|
||||
// The display list still goes through the engine's parser.
|
||||
ParseAll(host, "add selected", out _);
|
||||
}
|
||||
}
|
||||
}
|
||||
69
Tools/RynthSort.Tests/DropTests.cs
Normal file
69
Tools/RynthSort.Tests/DropTests.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthSort.Screen;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
using RynthCore.Plugin.RynthSort.Window;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// RynthSort 0.6.0: an item dragged out of RynthCore's Inventory window (its ImGui payload
|
||||
// "RYNTH_INV_ITEM") and let go on a pack card gets the same three choices as one dragged inside
|
||||
// the window. The engine also offers that drop through its drop target, so the window takes the
|
||||
// first of the two and ignores the echo.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void DropFromInventory()
|
||||
{
|
||||
// One drop, one set of choices.
|
||||
var once = new DropOnce();
|
||||
Check(once.Take(42, 10.0), "the first arrival opens the choices");
|
||||
Check(!once.Take(42, 10.2), "the same item a moment later (the other path) is the same drop");
|
||||
Check(once.Take(43, 10.3), "another item is another drop");
|
||||
Check(once.Take(42, 10.4), "back to the first item: a new drop (another item came between)");
|
||||
Check(!once.Take(42, 11.0) && once.Take(42, 11.5), "the same item again after a second: a new drop");
|
||||
Check(!once.Take(0, 20.0), "no item, no drop");
|
||||
once.Reset();
|
||||
Check(once.Take(42, 11.6), "after a reset anything is new");
|
||||
|
||||
// The payload type is the engine's, and RynthAi's Mini Remote takes the same one.
|
||||
Eq(SortWindow.InvPayloadType, "RYNTH_INV_ITEM", "the payload type");
|
||||
string root = RepoRoot();
|
||||
string engine = Path.Combine(root, "..", "RynthCore", "src", "RynthCore.Engine", "ImGui");
|
||||
string bridge = Path.Combine(engine, "ItemDragBridge.cs"), face = Path.Combine(engine, "Panels", "InventoryFace.cs");
|
||||
if (File.Exists(bridge) && File.Exists(face))
|
||||
{
|
||||
Check(File.ReadAllText(bridge).Contains("PayloadType = \"" + SortWindow.InvPayloadType + "\""), "the engine's drag bridge publishes it");
|
||||
Check(File.ReadAllText(face).Contains("ItemPayloadType = \"" + SortWindow.InvPayloadType + "\""), "the engine's Inventory publishes it");
|
||||
}
|
||||
else Console.WriteLine(" (no RynthCore checkout beside the repo: the engine's payload names weren't compared)");
|
||||
string remote = Path.Combine(root, "Plugins", "RynthCore.Plugin.RynthAi", "Huds", "MiniRemoteHud.cs");
|
||||
if (File.Exists(remote)) Check(File.ReadAllText(remote).Contains("ItemPayloadType = \"" + SortWindow.InvPayloadType + "\""), "RynthAi's Mini Remote takes the same payload");
|
||||
|
||||
// Dragging the item held it (the player's hands on it). Picking "All gems" on the drop
|
||||
// lets it go again, so the sort the player asked for moves it.
|
||||
var w = new FakeWorld();
|
||||
w.Inv.Main.Items.Add(It(10, "Black Opal", ObjectClasses.Gem));
|
||||
SortController c = Controller(auto: true);
|
||||
c.Data.Rules.Clear();
|
||||
Ticks(c, w, 0, 500);
|
||||
c.Touch.NoteDrag(10, c.Clock);
|
||||
Check(c.IsHeld(10), "dragged: left alone");
|
||||
EditResult r = RuleEdits.SendKind(c.Data.Rules, c.Planner.View, 2, ObjectClasses.Gem);
|
||||
Check(r.Changed, "All gems to pack 2");
|
||||
Ticks(c, w, 500, 2000);
|
||||
Check(w.Inv.Main.Items.Any(i => i.Id == 10), "still held: it waits where it is");
|
||||
c.Touch.Release(10); // the drop's choice (ISortWindowActions.Unhold)
|
||||
Ticks(c, w, 2000, 4000);
|
||||
Check(w.Inv.Packs[1].Items.Any(i => i.Id == 10), "let go: it goes to the pack it was dropped on");
|
||||
}
|
||||
|
||||
/// <summary>The RynthSuite checkout these tests run from (the folder with RynthSuite.slnx).</summary>
|
||||
private static string RepoRoot()
|
||||
{
|
||||
string? d = AppContext.BaseDirectory;
|
||||
while (d != null && !File.Exists(Path.Combine(d, "RynthSuite.slnx"))) d = Path.GetDirectoryName(d);
|
||||
return d ?? Directory.GetCurrentDirectory();
|
||||
}
|
||||
}
|
||||
}
|
||||
75
Tools/RynthSort.Tests/FeedNameTests.cs
Normal file
75
Tools/RynthSort.Tests/FeedNameTests.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthSort.Screen;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// RynthSort 0.6.0: the activity feed names packs ("Mana Potion -> Satchel"), with the pack's
|
||||
// number when two carried packs share a name ("-> Satchel (3)"), as the cards' badges show it.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void FeedPackNames()
|
||||
{
|
||||
// The names themselves.
|
||||
string[] names = { "Sack", "Satchel", "Satchel", "" };
|
||||
Eq(PackNames.Label(names, 0), "main pack", "0 is the main pack");
|
||||
Eq(PackNames.Label(names, 1), "Sack", "a name no other pack has");
|
||||
Eq(PackNames.Label(names, 2), "Satchel (2)", "two packs called Satchel: the number too");
|
||||
Eq(PackNames.Label(names, 3), "Satchel (3)", "the other one");
|
||||
Eq(PackNames.Label(names, 4), "pack 4", "a pack the client hasn't named yet");
|
||||
Eq(PackNames.Label(names, 9), "pack 9", "past the packs carried");
|
||||
Eq(PackNames.Label(new[] { "Satchel", "satchel " }, 1), "Satchel (1)", "any case, spaces trimmed");
|
||||
Eq(PackNames.Label((SortInventory?)null, 2), "pack 2", "no packs read yet");
|
||||
|
||||
// In the loop: the feed says the pack's name, the log (/rsort status) keeps the number.
|
||||
var w = new FakeWorld();
|
||||
SortInventory inv = Inv(3);
|
||||
inv.Packs[0].Name = "Sack";
|
||||
inv.Packs[1].Name = "Satchel";
|
||||
inv.Packs[2].Name = "Satchel";
|
||||
w.Inv = inv;
|
||||
inv.Main.Items.Add(It(10, "Black Opal", ObjectClasses.Gem));
|
||||
inv.Main.Items.Add(It(11, "Prismatic Taper", ObjectClasses.SpellComponent));
|
||||
SortController c = Controller(auto: true);
|
||||
c.Data.Rules = SortRules.Defaults(); // components 1, salvage 2, gems 3
|
||||
Ticks(c, w, 0, 4000);
|
||||
Check(inv.Packs[2].Items.Any(i => i.Id == 10) && inv.Packs[0].Items.Any(i => i.Id == 11), "both moved");
|
||||
FeedLine opal = c.Feed.First(f => f.ItemId == 10), taper = c.Feed.First(f => f.ItemId == 11);
|
||||
Eq(opal.Text, "Black Opal -> Satchel (3)", "two Satchels: the feed adds the number");
|
||||
Eq(taper.Text, "Prismatic Taper -> Sack", "a unique name: just the name");
|
||||
Check(c.Log.Contains("Black Opal -> pack 3") && c.Log.Contains("Prismatic Taper -> pack 1"), "the log keeps the numbers");
|
||||
|
||||
// Sent from the window, to the main pack.
|
||||
c.StartSend(10, Me);
|
||||
Ticks(c, w, 4000, 6000);
|
||||
Eq(c.Feed[0].Text, "Black Opal -> main pack (you sent it)", "a send names the main pack");
|
||||
|
||||
// Put in order inside a pack: one line that counts up, by name.
|
||||
var ow = new FakeWorld { Can = SortAbilities.All };
|
||||
SortInventory oi = Inv(1);
|
||||
oi.Packs[0].Name = "Hide Sack";
|
||||
oi.Packs[0].OrderKnown = true;
|
||||
oi.Packs[0].Items.Add(It(1, "Zircon", ObjectClasses.Gem));
|
||||
oi.Packs[0].Items.Add(It(2, "Amber", ObjectClasses.Gem));
|
||||
oi.Packs[0].Items.Add(It(3, "Jet", ObjectClasses.Gem));
|
||||
ow.Inv = oi;
|
||||
SortController co = Controller(auto: true);
|
||||
co.Data.Rules = new List<SortRule> { SortRule.ForClass(ObjectClasses.Gem, 1) };
|
||||
Ticks(co, ow, 0, 6000);
|
||||
Check(co.Feed.Count > 0 && co.Feed[0].Text.EndsWith("put in order in Hide Sack", StringComparison.Ordinal), $"reorders by name ({co.Feed[0].Text})");
|
||||
Check(co.Log[0].EndsWith("put in order in pack 1", StringComparison.Ordinal), "the log by number");
|
||||
|
||||
// The window's sentences use the same names.
|
||||
SortController cs = ScreenController(inv);
|
||||
cs.Data.Rules = SortRules.Defaults();
|
||||
ScreenModel m = Screen(cs);
|
||||
Check(m.PackName(2) == "Satchel (2)" && m.PackName(3) == "Satchel (3)" && m.PackName(1) == "Sack" && m.PackName(0) == "main pack", "PackName for toasts and rows");
|
||||
Check(m.Packs[1].Name == "Satchel" && m.Packs[1].Label == "Satchel (2)", "the card keeps its name; its badge shows the number");
|
||||
SortView view = cs.Planner.View;
|
||||
EditResult r = RuleEdits.SendKind(cs.Data.Rules, view, 2, ObjectClasses.Plant);
|
||||
Check(r.Text.Contains("go to Satchel (2)"), $"a toast names the right Satchel ({r.Text})");
|
||||
}
|
||||
}
|
||||
}
|
||||
80
Tools/RynthSort.Tests/FoldTests.cs
Normal file
80
Tools/RynthSort.Tests/FoldTests.cs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthSort;
|
||||
using RynthCore.Plugin.RynthSort.Screen;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// RynthSort 0.6.1: pack cards fold down to their header and rules (by the pack's object id, saved
|
||||
// with the character), and "+ Add a rule" takes a typed name (no item needed).
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void FoldedPacks()
|
||||
{
|
||||
var s = new SortSettings();
|
||||
Check(s.CollapsedPacks.Count == 0 && !s.MainCollapsed, "nothing folded for a new character");
|
||||
Check(s.SetCollapsed(0x500, true) && !s.SetCollapsed(0x500, true) && s.CollapsedPacks.SequenceEqual(new uint[] { 0x500 }), "folded once");
|
||||
Check(!s.SetCollapsed(0, true), "no pack id: nothing");
|
||||
Check(s.SetCollapsed(0x500, false) && s.CollapsedPacks.Count == 0 && !s.SetCollapsed(0x500, false), "opened");
|
||||
for (uint i = 1; i <= SortSettings.MaxCollapsed + 5; i++) s.SetCollapsed(i, true);
|
||||
Check(s.CollapsedPacks.Count == SortSettings.MaxCollapsed && s.CollapsedPacks[0] == 6 && s.CollapsedPacks[^1] == SortSettings.MaxCollapsed + 5,
|
||||
"at most 64, the oldest dropped");
|
||||
|
||||
// The file: saved and read back; an older file has none; odd values are skipped.
|
||||
var d = new CharacterSortData();
|
||||
d.Settings.MainCollapsed = true;
|
||||
d.Settings.SetCollapsed(0x80001234, true);
|
||||
d.Settings.SetCollapsed(7, true);
|
||||
using var doc1 = System.Text.Json.JsonDocument.Parse(SortStore.ToJson(d));
|
||||
CharacterSortData back = SortStore.Parse(doc1.RootElement);
|
||||
Check(back.Settings.MainCollapsed && back.Settings.CollapsedPacks.SequenceEqual(new uint[] { 0x80001234, 7 }), "saved and read back");
|
||||
using var doc0 = System.Text.Json.JsonDocument.Parse("{\"rules\":[],\"settings\":{\"auto\":true}}");
|
||||
CharacterSortData old = SortStore.Parse(doc0.RootElement);
|
||||
Check(!old.Settings.MainCollapsed && old.Settings.CollapsedPacks.Count == 0, "an older file: nothing folded");
|
||||
using var doc2 = System.Text.Json.JsonDocument.Parse("{\"settings\":{\"mainCollapsed\":\"yes\",\"collapsed\":[5,5,-1,\"x\",1.5,9]}}");
|
||||
CharacterSortData odd = SortStore.Parse(doc2.RootElement);
|
||||
Check(!odd.Settings.MainCollapsed && odd.Settings.CollapsedPacks.SequenceEqual(new uint[] { 5, 9 }), "odd values skipped");
|
||||
|
||||
// The window's model: the folded pack by its id, wherever it sits in the column.
|
||||
SortInventory inv = Inv(3);
|
||||
SortController c = ScreenController(inv);
|
||||
c.Data.Settings.SetCollapsed(inv.Packs[1].Id, true);
|
||||
ScreenModel m = Screen(c);
|
||||
Check(!m.Packs[0].Collapsed && m.Packs[1].Collapsed && !m.Packs[2].Collapsed && !m.Main.Collapsed, "pack 2 folded, the rest open");
|
||||
c.Data.Settings.MainCollapsed = true;
|
||||
Check(Screen(c).Main.Collapsed, "the main pack folded");
|
||||
}
|
||||
|
||||
private static void TypedNameRule()
|
||||
{
|
||||
SortInventory inv = Inv(3);
|
||||
inv.Main.Items.Add(It(1, "Pyreal Scarab", ObjectClasses.Misc));
|
||||
inv.Main.Items.Add(It(2, "Copper Scarab", ObjectClasses.Misc));
|
||||
var rules = new List<SortRule>();
|
||||
SortView view = SortPreview.Build(inv, rules, default, null).View;
|
||||
|
||||
EditResult r = RuleEdits.SendNameText(rules, view, 2, " Scarab ");
|
||||
Check(r.Changed && rules.Count == 1 && rules[0].HasName("Scarab") && rules[0].PackId == inv.Packs[1].Id, $"a new name rule tied to the pack: {r.Text}");
|
||||
Check(inv.Main.Items.All(i => SortRules.RuleFor(rules, i) == rules[0]), "both scarabs follow it");
|
||||
Check(!RuleEdits.SendNameText(rules, view, 2, "scarab").Changed, "again (any case): nothing changes");
|
||||
Check(!RuleEdits.SendNameText(rules, view, 2, " ").Changed && !RuleEdits.SendNameText(rules, view, 9, "Gem").Changed, "blank, or a pack not carried");
|
||||
|
||||
// The same name typed on another pack moves it there; the emptied rule goes.
|
||||
r = RuleEdits.SendNameText(rules, view, 3, "Scarab");
|
||||
Check(r.Changed && rules.Count == 1 && Views.SortPanelProxy.Shown(view, rules[0]) == 3, $"moved to pack 3: {r.Text}");
|
||||
|
||||
// A second name joins the pack's name rule; too long a name is cut to the limit.
|
||||
RuleEdits.SendNameText(rules, view, 3, "Pea");
|
||||
Check(rules.Count == 1 && rules[0].Names.Count == 2, "joins the same rule");
|
||||
RuleEdits.SendNameText(rules, view, 1, new string('a', SortRule.MaxNameLength + 10));
|
||||
Check(rules.Any(x => x.Names.Any(n => n.Length == SortRule.MaxNameLength)), "cut to the name limit");
|
||||
|
||||
// A name in a rule of this pack that is off: says so, changes nothing.
|
||||
SortRule here = rules.First(x => x.HasName("Pea"));
|
||||
here.On = false;
|
||||
r = RuleEdits.SendNameText(rules, view, 3, "Pea");
|
||||
Check(!r.Changed && r.Text.Contains("turned off"), $"off: {r.Text}");
|
||||
}
|
||||
}
|
||||
}
|
||||
145
Tools/RynthSort.Tests/FullPackTests.cs
Normal file
145
Tools/RynthSort.Tests/FullPackTests.cs
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthSort.Screen;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// RynthSort 0.6.0: a full pack. Items spill into the next pack with the same rule (an overflow
|
||||
// pack); when there is none, the window's red banner and one chat line per sort say what didn't
|
||||
// fit and where, and the pack's fill bar turns red. Each pack's own capacity counts.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void FullPackSpill()
|
||||
{
|
||||
// Gems: the Satchel (pack 1, 2 slots) first, the Backpack (pack 2) when it is full.
|
||||
SortInventory inv = Inv(3);
|
||||
inv.Packs[0].Name = "Satchel";
|
||||
inv.Packs[0].Capacity = 2;
|
||||
inv.Packs[1].Name = "Backpack";
|
||||
inv.Packs[2].Name = "Sack";
|
||||
inv.Packs[0].Items.Add(It(1, "Fire Opal", ObjectClasses.Gem));
|
||||
for (uint i = 10; i < 14; i++) inv.Main.Items.Add(It(i, "Gem " + i, ObjectClasses.Gem));
|
||||
var rules = new List<SortRule> { SortRule.ForClass(ObjectClasses.Gem, 1), SortRule.ForClass(ObjectClasses.Gem, 2) };
|
||||
Check(SortRules.RulesFor(rules, inv.Main.Items[0]).Count == 2 && SortRules.RulesFor(rules, inv.Main.Items[0])[0] == rules[0], "both rules match; the first is the gem's own");
|
||||
|
||||
var planner = new SortPlanner();
|
||||
List<SortMove> moves = planner.Plan(inv, rules, SortScope.All, force: true, 0, 0);
|
||||
Check(moves.Count == 4 && moves[0].DestIndex == 1 && moves.Skip(1).All(m => m.DestIndex == 2), "one gem fills the Satchel, the rest spill into the Backpack");
|
||||
Check(planner.View.Full.Contains(1) && planner.View.NoFit.Count == 0, "the Satchel is full, nothing left over");
|
||||
|
||||
// An item already in the overflow pack stays there while its own pack is full...
|
||||
foreach (SortMove m in moves) ServerApply(inv, m);
|
||||
Eq(planner.Plan(inv, rules, SortScope.All, force: true, 0, 0).Count, 0, "spilled items stay put");
|
||||
// ... and goes to its own pack when that has room again.
|
||||
inv.Packs[0].Items.RemoveAt(0);
|
||||
moves = planner.Plan(inv, rules, SortScope.All, force: true, 0, 0);
|
||||
Check(moves.Count == 1 && moves[0].DestIndex == 1 && moves[0].FromIndex == 2, "a slot free in the Satchel: one gem goes back to it");
|
||||
Check(planner.Plan(inv, rules, SortScope.Clean, force: true, 0, 0).All(m => m.FromIndex != 2 || m.DestIndex == 1), "Clean doesn't pull overflow gems out to the main pack");
|
||||
|
||||
// No overflow with room: the items stay where they are, and the view names them.
|
||||
SortInventory tight = Inv(2, cap: 1);
|
||||
tight.Packs[0].Name = "Satchel";
|
||||
tight.Packs[0].Items.Add(It(1, "Fire Opal", ObjectClasses.Gem));
|
||||
tight.Packs[1].Items.Add(It(2, "Junk", ObjectClasses.Misc));
|
||||
tight.Main.Items.Add(It(10, "Black Opal", ObjectClasses.Gem));
|
||||
tight.Main.Items.Add(It(11, "Amethyst", ObjectClasses.Gem));
|
||||
moves = planner.Plan(tight, rules, SortScope.All, force: true, 0, 0);
|
||||
Eq(moves.Count, 0, "both packs full: nothing moves");
|
||||
Check(planner.View.NoFit.Count == 2 && planner.View.NoFit.All(l => l.Pack == 1 && l.From == 0), "two gems didn't fit the Satchel; they stay in the main pack");
|
||||
Check(planner.View.WaitFull == 2, "counted as waiting on a full pack");
|
||||
Eq(SortController.NoFitText(planner.View.NoFit, tight), "Satchel is full: Black Opal and Amethyst stay where they are.", "the words");
|
||||
var one = new List<NoFitLine> { planner.View.NoFit[0] };
|
||||
Eq(SortController.NoFitText(one, tight), "Satchel is full: Black Opal stays where it is.", "one item");
|
||||
var many = Enumerable.Range(0, 6).Select(i => new NoFitLine(It((uint)(50 + i), "Gem" + i, ObjectClasses.Gem), 1, 0)).ToList();
|
||||
Eq(SortController.NoFitText(many, tight), "Satchel is full: Gem0, Gem1, Gem2 and 3 more stay where they are.", "at most three names");
|
||||
|
||||
// A stack it can join still takes it in a full pack (as before).
|
||||
SortInventory stack = Inv(1, cap: 1);
|
||||
stack.Packs[0].Items.Add(It(1, "Lead Scarab", ObjectClasses.SpellComponent, wcid: 7, stack: 5, max: 100));
|
||||
stack.Main.Items.Add(It(2, "Lead Scarab", ObjectClasses.SpellComponent, wcid: 7, stack: 3, max: 100));
|
||||
moves = planner.Plan(stack, SortRules.Defaults(), SortScope.All, force: true, 0, 0);
|
||||
Check(moves.Count == 1 && moves[0].MergeInto == 1 && planner.View.NoFit.Count == 0, "joins the stack there: not a no-fit");
|
||||
|
||||
// Each pack's real capacity: a 30-slot pack with 24 items still takes more.
|
||||
SortInventory big = Inv(1, cap: 30);
|
||||
Fill(big.Packs[0], 24, 100);
|
||||
big.Main.Items.Add(It(5, "Black Opal", ObjectClasses.Gem));
|
||||
moves = planner.Plan(big, new List<SortRule> { SortRule.ForClass(ObjectClasses.Gem, 1) }, SortScope.All, force: true, 0, 0);
|
||||
Check(moves.Count == 1 && planner.View.NoFit.Count == 0, "24 of 30: room");
|
||||
}
|
||||
|
||||
private static void FullPackWarnings()
|
||||
{
|
||||
// In the loop: one chat line when items stop fitting, not one per tick.
|
||||
var w = new FakeWorld { Inv = Inv(1, cap: 1) };
|
||||
w.Inv.Packs[0].Name = "Satchel";
|
||||
w.Inv.Packs[0].Items.Add(It(1, "Fire Opal", ObjectClasses.Gem));
|
||||
w.Inv.Main.Items.Add(It(10, "Black Opal", ObjectClasses.Gem));
|
||||
SortController c = Controller(auto: true);
|
||||
c.Data.Rules = new List<SortRule> { SortRule.ForClass(ObjectClasses.Gem, 1) };
|
||||
var said = new List<string>();
|
||||
c.Warn = said.Add;
|
||||
Ticks(c, w, 0, 5000);
|
||||
Check(said.Count == 1 && said[0] == "Satchel is full: Black Opal stays where it is.", $"one line ({string.Join(" | ", said)})");
|
||||
Check(c.Feed.Any(f => f.Text == said[0]), "and in the feed");
|
||||
Ticks(c, w, 5000, 15_000);
|
||||
Eq(said.Count, 1, "ten seconds later: still one line");
|
||||
w.Inv.Main.Items.Add(It(11, "Amethyst", ObjectClasses.Gem));
|
||||
Ticks(c, w, 15_000, 18_000);
|
||||
Check(said.Count == 2 && said[1] == "Satchel is full: Black Opal and Amethyst stay where they are.", "a new item that doesn't fit: a new line naming them all");
|
||||
// Sort now says it once, at its end.
|
||||
c.StartJob(SortScope.All);
|
||||
Ticks(c, w, 18_000, 20_000);
|
||||
Eq(said.Count, 3, "Sort now: one line when it ends");
|
||||
// Room again: forgotten, so it is said again if it stops fitting.
|
||||
w.Inv.Packs[0].Capacity = 3;
|
||||
Ticks(c, w, 20_000, 24_000);
|
||||
Check(w.Inv.Packs[0].Items.Count == 3, "room: both gems went");
|
||||
w.Inv.Main.Items.Add(It(12, "Jet", ObjectClasses.Gem));
|
||||
Ticks(c, w, 24_000, 27_000);
|
||||
Check(said.Count == 4 && said[3].Contains("Jet"), "full again: a new line");
|
||||
// Auto-sort off: nothing sorts, nothing said.
|
||||
c.SetAuto(false);
|
||||
w.Inv.Main.Items.Add(It(13, "Agate", ObjectClasses.Gem));
|
||||
Ticks(c, w, 27_000, 32_000);
|
||||
Eq(said.Count, 4, "off: no chat");
|
||||
|
||||
// The window: the red banner, the card's line and its red bar, the main pack's bar.
|
||||
SortInventory inv = Inv(2, cap: 2);
|
||||
inv.Packs[0].Name = "Satchel";
|
||||
inv.Packs[1].Name = "Backpack";
|
||||
inv.Packs[0].Items.Add(It(1, "Fire Opal", ObjectClasses.Gem));
|
||||
inv.Packs[0].Items.Add(It(2, "Jet", ObjectClasses.Gem));
|
||||
inv.Main.Items.Add(It(10, "Black Opal", ObjectClasses.Gem));
|
||||
SortController cs = ScreenController(inv);
|
||||
cs.Data.Rules = new List<SortRule> { SortRule.ForClass(ObjectClasses.Gem, 1) };
|
||||
ScreenModel m = Screen(cs);
|
||||
Check(m.NoFit.Length == 1 && m.NoFit[0] == "Satchel is full: Black Opal stays where it is.", $"the banner ({string.Join(" | ", m.NoFit)})");
|
||||
Check(m.Packs[0].Full && !m.Packs[1].Full && m.Packs[0].Warnings.Contains("Full: 1 item for it waits where it is."), "the Satchel's bar is red and its card says so");
|
||||
Check(!m.Main.Full, "the main pack isn't full");
|
||||
|
||||
// An overflow pack: the banner goes, the card says the rest go on, the chip says overflow.
|
||||
EditResult r = RuleEdits.AddOverflow(cs.Data.Rules, cs.Planner.View, 2, ObjectClasses.Gem);
|
||||
Check(r.Changed && r.Text == "Gems go to Satchel, and to Backpack when it is full. Nothing has moved yet.", $"overflow ({r.Text})");
|
||||
Check(cs.Data.Rules.Count == 2 && cs.Data.Rules[1].HasClass(ObjectClasses.Gem), "a new rule after the first");
|
||||
Check(!RuleEdits.AddOverflow(cs.Data.Rules, cs.Planner.View, 2, ObjectClasses.Gem).Changed, "again: nothing");
|
||||
Check(!RuleEdits.AddOverflow(cs.Data.Rules, cs.Planner.View, 1, ObjectClasses.Gem).Changed, "the pack that has it can't be its own overflow");
|
||||
Check(!RuleEdits.AddOverflow(cs.Data.Rules, cs.Planner.View, 2, ObjectClasses.Scroll).Changed, "a kind no pack has: add it first");
|
||||
m = Screen(cs);
|
||||
Check(m.NoFit.Length == 0 && m.Packs[0].Warnings.Contains("Full: the next pack with the same rule takes the rest."), "spilling: no banner");
|
||||
ChipModel chip = m.Packs[1].Chips.Single();
|
||||
Check(chip.Overflow && chip.Label == "Gems (overflow)" && chip.Tip.StartsWith("Gems come here when Satchel is full", StringComparison.Ordinal), "the overflow chip");
|
||||
Check(!m.Packs[0].Chips.Single().Overflow, "the Satchel's chip is the kind's own");
|
||||
Check(m.Moves.Length == 1 && m.Moves[0].Right == "Backpack", "Next moves: to the Backpack");
|
||||
Eq(m.KindChoices.Single(k => k.Cls == ObjectClasses.Gem).InPack, 1, "the picker still names the Satchel as the kind's pack");
|
||||
|
||||
// A full main pack: red too.
|
||||
SortInventory fullMain = Inv(1, mainCap: 2);
|
||||
fullMain.Main.Items.Add(It(1, "A", ObjectClasses.Misc));
|
||||
fullMain.Main.Items.Add(It(2, "B", ObjectClasses.Misc));
|
||||
Check(Screen(ScreenController(fullMain)).Main.Full, "a full main pack's bar is red");
|
||||
}
|
||||
}
|
||||
}
|
||||
180
Tools/RynthSort.Tests/HandyTests.cs
Normal file
180
Tools/RynthSort.Tests/HandyTests.cs
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthSort;
|
||||
using RynthCore.Plugin.RynthSort.Screen;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// RynthSort 0.6.0: "Keep handy items at the front of the main pack". Healing kits, mana stones,
|
||||
// food, potions and elixirs (the player's list) sit in the main pack's first slots. A move to a
|
||||
// slot is the engine's PutItemInContainer (plugin API v80), the same move that puts items in
|
||||
// order inside packs; without it the option does nothing. Items left alone are never moved for it.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static SortInventory HandyPack(params (string Name, int Cls)[] items)
|
||||
{
|
||||
SortInventory inv = Inv(2);
|
||||
inv.Main.OrderKnown = true;
|
||||
uint id = 1;
|
||||
foreach (var (n, cls) in items) inv.Main.Items.Add(It(id++, n, cls));
|
||||
return inv;
|
||||
}
|
||||
|
||||
private static string Names(SortPack p) => string.Join(",", p.Items.Select(i => i.Name));
|
||||
|
||||
private static Func<SortItem, bool> DefaultHandy() =>
|
||||
it => HandyItems.Matches(HandyItems.DefaultClasses, HandyItems.DefaultNames, it);
|
||||
|
||||
/// <summary>Plans and applies moves as the server would until none is left; returns how many.</summary>
|
||||
private static int RunOut(SortInventory inv, List<SortRule> rules, PlanOptions opt, Func<uint, bool>? held = null, int max = 200)
|
||||
{
|
||||
var planner = new SortPlanner { Held = held };
|
||||
int n = 0;
|
||||
for (; n < max; n++)
|
||||
{
|
||||
List<SortMove> moves = planner.Plan(inv, rules, SortScope.All, force: true, 0, 0, opt);
|
||||
if (moves.Count == 0) return n;
|
||||
ServerApply(inv, moves[0]);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
private static void HandyFront()
|
||||
{
|
||||
Func<SortItem, bool> handy = DefaultHandy();
|
||||
Check(handy(It(1, "Treated Healing Kit", ObjectClasses.HealingKit)) && handy(It(2, "Mana Stone", ObjectClasses.ManaStone))
|
||||
&& handy(It(3, "Peppermint Stick", ObjectClasses.Food)), "kits, mana stones and food by kind");
|
||||
Check(handy(It(4, "Mana Potion", ObjectClasses.Misc)) && handy(It(5, "health elixir", ObjectClasses.Unknown)), "potions and elixirs by name, any case");
|
||||
Check(!handy(It(6, "Black Opal", ObjectClasses.Gem)) && !handy(It(7, "", ObjectClasses.Misc)), "gems aren't handy; a nameless misc item isn't either");
|
||||
Eq(HandyItems.Describe(HandyItems.DefaultClasses, HandyItems.DefaultNames), "healing kits, mana stones, food, potions and elixirs", "the list in words");
|
||||
|
||||
// The front run, and one move per handy item behind it (ordering off: the rest keep their order).
|
||||
SortInventory inv = HandyPack(("Black Opal", ObjectClasses.Gem), ("Amuli Coat", ObjectClasses.Armor), ("Healing Kit", ObjectClasses.HealingKit),
|
||||
("Zircon", ObjectClasses.Gem), ("Mana Potion", ObjectClasses.Misc), ("Celdon Girth", ObjectClasses.Armor));
|
||||
Func<SortItem, bool> any = _ => true;
|
||||
Eq(PackOrder.FrontRun(inv.Main.Items, handy, any), 0, "nothing handy in front yet");
|
||||
Eq(PackOrder.HandyBehind(inv.Main.Items, handy, any), 2, "two handy items behind");
|
||||
Check(PackOrder.FrontMove(inv.Main.Items, handy, any, out SortItem first, out int at) && first.Name == "Healing Kit" && at == 0, "the first handy item goes to slot 0");
|
||||
var opt = new PlanOptions { Place = true, Merge = true, Handy = handy };
|
||||
int moves = RunOut(inv, new List<SortRule>(), opt);
|
||||
Eq(Names(inv.Main), "Healing Kit,Mana Potion,Black Opal,Amuli Coat,Zircon,Celdon Girth", "handy in front, the rest as they were");
|
||||
Eq(moves, 2, "one move per handy item");
|
||||
|
||||
// Ordering on: the whole main pack in order, handy items first.
|
||||
SortInventory ord = HandyPack(("Zircon", ObjectClasses.Gem), ("Mana Potion", ObjectClasses.Misc), ("Amber", ObjectClasses.Gem),
|
||||
("Healing Kit", ObjectClasses.HealingKit), ("Apple", ObjectClasses.Food));
|
||||
RunOut(ord, new List<SortRule>(), new PlanOptions { Order = true, Place = true, Merge = true, Handy = handy });
|
||||
Eq(Names(ord.Main), "Apple,Healing Kit,Mana Potion,Amber,Zircon", "handy first (A-Z), then the rest A-Z");
|
||||
Eq(RunOut(ord, new List<SortRule>(), new PlanOptions { Order = true, Place = true, Merge = true, Handy = handy }), 0, "then it stays still");
|
||||
|
||||
// Left alone: a held item is never moved for it, and handy items go after a held one in front.
|
||||
SortInventory hold = HandyPack(("Black Opal", ObjectClasses.Gem), ("Zircon", ObjectClasses.Gem), ("Healing Kit", ObjectClasses.HealingKit),
|
||||
("Mana Stone", ObjectClasses.ManaStone));
|
||||
uint opalId = hold.Main.Items[0].Id, stoneId = hold.Main.Items[3].Id;
|
||||
RunOut(hold, new List<SortRule>(), opt, held: id => id == opalId || id == stoneId);
|
||||
Eq(Names(hold.Main), "Black Opal,Healing Kit,Zircon,Mana Stone", "the opal (held) keeps slot 0; the kit goes after it; the held stone stays");
|
||||
|
||||
// No moves to a slot (an engine before API v80): nothing happens for it.
|
||||
SortInventory old = HandyPack(("Black Opal", ObjectClasses.Gem), ("Healing Kit", ObjectClasses.HealingKit));
|
||||
Eq(RunOut(old, new List<SortRule>(), new PlanOptions { Merge = true, Handy = handy }), 0, "no slot moves: nothing moves");
|
||||
SortInventory unknown = HandyPack(("Black Opal", ObjectClasses.Gem), ("Healing Kit", ObjectClasses.HealingKit));
|
||||
unknown.Main.OrderKnown = false;
|
||||
Eq(RunOut(unknown, new List<SortRule>(), opt), 0, "the main pack's order not known: nothing moves");
|
||||
|
||||
// A kind a side pack's rule names goes to that pack instead.
|
||||
SortInventory ruled = HandyPack(("Black Opal", ObjectClasses.Gem), ("Healing Kit", ObjectClasses.HealingKit), ("Mana Stone", ObjectClasses.ManaStone));
|
||||
RunOut(ruled, new List<SortRule> { SortRule.ForClass(ObjectClasses.HealingKit, 2) }, opt);
|
||||
Check(ruled.Packs[1].Items.Any(i => i.Name == "Healing Kit") && Names(ruled.Main) == "Mana Stone,Black Opal", $"the kit to its pack, the stone to the front ({Names(ruled.Main)})");
|
||||
|
||||
// An item coming back to the main pack (Clean) lands in the handy run when it is handy.
|
||||
SortInventory back = HandyPack(("Healing Kit", ObjectClasses.HealingKit), ("Black Opal", ObjectClasses.Gem));
|
||||
back.Packs[0].Items.Add(It(50, "Mana Potion", ObjectClasses.Misc));
|
||||
var cp = new SortPlanner();
|
||||
List<SortMove> clean = cp.Plan(back, new List<SortRule>(), SortScope.Clean, force: true, 0, 0, opt);
|
||||
Check(clean.Count == 1 && clean[0].Item.Id == 50 && clean[0].DestIndex == 0 && clean[0].Placement == 1, "a potion cleaned out of a pack goes right after the kit");
|
||||
|
||||
// New loot settling: the main pack waits (as for ordering).
|
||||
SortInventory fresh = HandyPack(("Black Opal", ObjectClasses.Gem), ("Healing Kit", ObjectClasses.HealingKit));
|
||||
var fp = new SortPlanner();
|
||||
Eq(fp.Plan(fresh, new List<SortRule>(), SortScope.All, force: false, 0, 5000, opt).Count, 0, "items still settling: the main pack isn't touched");
|
||||
Eq(fp.Plan(fresh, new List<SortRule>(), SortScope.All, force: false, 6000, 5000, opt).Count, 1, "settled: the kit moves");
|
||||
Check(fp.View.Handy && fp.View.HandyBehind == 1, "the view counts what is left");
|
||||
}
|
||||
|
||||
private static void HandyLoopAndStore()
|
||||
{
|
||||
// In the loop: auto-sort brings them to the front, then stays still; off by default.
|
||||
var w = new FakeWorld { Can = SortAbilities.All };
|
||||
w.Inv.Main.OrderKnown = true;
|
||||
w.Inv.Main.Items.Add(It(1, "Black Opal Ring", ObjectClasses.Jewelry));
|
||||
w.Inv.Main.Items.Add(It(2, "Celdon Girth", ObjectClasses.Armor));
|
||||
w.Inv.Main.Items.Add(It(3, "Treated Healing Kit", ObjectClasses.HealingKit));
|
||||
w.Inv.Main.Items.Add(It(4, "Mana Potion", ObjectClasses.Misc));
|
||||
SortController c = Controller(auto: true);
|
||||
c.Data.Rules.Clear();
|
||||
c.Data.Settings.OrderInPacks = false;
|
||||
Check(!c.Data.Settings.HandyFront, "off for a new character");
|
||||
Ticks(c, w, 0, 4000);
|
||||
Eq(w.Sent.Count, 0, "off: nothing moves");
|
||||
c.Data.Settings.HandyFront = true;
|
||||
Ticks(c, w, 4000, 12_000);
|
||||
Eq(Names(w.Inv.Main), "Treated Healing Kit,Mana Potion,Black Opal Ring,Celdon Girth", "on: the kit and the potion in front");
|
||||
int sent = w.Sent.Count;
|
||||
Ticks(c, w, 12_000, 20_000);
|
||||
Eq(w.Sent.Count, sent, "then nothing more moves");
|
||||
Check(w.Sent.All(m => m.Kind == MoveKind.Reorder && m.Dest.Id == Me), "only moves inside the main pack");
|
||||
|
||||
// The player picks up the potion (selects it): it stays where they put it.
|
||||
SortItem potion = w.Inv.Main.Items.First(i => i.Id == 4);
|
||||
PackOrder.Apply(w.Inv.Main.Items, potion, 3);
|
||||
c.Touch.NoteSelected(4, c.Clock);
|
||||
Ticks(c, w, 20_000, 26_000);
|
||||
Eq(w.Inv.Main.Items.FindIndex(i => i.Id == 4), 3, "held: not moved back to the front");
|
||||
|
||||
// The window: the switch, the list as chips, the picker, the note under the main pack.
|
||||
SortController cs = ScreenController(w.Inv);
|
||||
cs.Tick(new FakeWorld { Inv = w.Inv, Can = SortAbilities.All }, 100);
|
||||
cs.Data.Settings.HandyFront = true;
|
||||
ScreenModel m = Screen(cs);
|
||||
Check(m.Settings.HandyOn && m.Settings.HandyChips.Length == 5, "five chips: three kinds, two names");
|
||||
Check(m.Settings.HandyChips[0].Label == "Healing kits" && m.Settings.HandyChips[3].IsName && m.Settings.HandyChips[3].Label == "named \"Potion\"", "kinds, then names");
|
||||
Check(!m.Settings.HandyChoices.Any(k => k.Cls == ObjectClasses.ManaStone) && m.Settings.HandyChoices.Any(k => k.Cls == ObjectClasses.Gem), "the picker offers what isn't on the list");
|
||||
Eq(m.Main.Handy, "Handy at the front: healing kits, mana stones, food, potions and elixirs.", "the main pack says so");
|
||||
cs.Data.Settings.HandyFront = false;
|
||||
Eq(Screen(cs).Main.Handy, "", "off: nothing said");
|
||||
|
||||
// Editing the list.
|
||||
var s = new SortSettings();
|
||||
Check(HandyItems.AddClass(s, ObjectClasses.Scroll) && !HandyItems.AddClass(s, ObjectClasses.Scroll) && !HandyItems.AddClass(s, ObjectClasses.Monster),
|
||||
"a kind once; only kinds the picker offers");
|
||||
Check(HandyItems.AddName(s, " Draught ") && s.HandyNames.Contains("Draught") && !HandyItems.AddName(s, "draught") && !HandyItems.AddName(s, " "),
|
||||
"a name trimmed, once (any case), never blank");
|
||||
Check(HandyItems.RemoveName(s, "DRAUGHT") && !s.HandyNames.Contains("Draught"), "taken off, any case");
|
||||
s.HandyClasses.Clear();
|
||||
s.HandyNames.Clear();
|
||||
s.HandyFront = true;
|
||||
Check(HandyItems.For(s) == null, "an empty list: off");
|
||||
|
||||
// The file: off and the default list for files from before it; kept as set.
|
||||
using var doc0 = System.Text.Json.JsonDocument.Parse("{\"rules\":[],\"settings\":{\"auto\":true,\"holdMin\":3}}");
|
||||
CharacterSortData old = SortStore.Parse(doc0.RootElement);
|
||||
Check(!old.Settings.HandyFront && old.Settings.HandyClasses.SequenceEqual(HandyItems.DefaultClasses) && old.Settings.HandyNames.SequenceEqual(HandyItems.DefaultNames),
|
||||
"an older file: off, with the default list");
|
||||
var d = new CharacterSortData();
|
||||
d.Settings.HandyFront = true;
|
||||
d.Settings.HandyClasses = new List<int> { ObjectClasses.HealingKit, ObjectClasses.Scroll };
|
||||
d.Settings.HandyNames = new List<string> { "Elixir" };
|
||||
using var doc1 = System.Text.Json.JsonDocument.Parse(SortStore.ToJson(d));
|
||||
CharacterSortData back = SortStore.Parse(doc1.RootElement);
|
||||
Check(back.Settings.HandyFront && back.Settings.HandyClasses.SequenceEqual(new[] { ObjectClasses.HealingKit, ObjectClasses.Scroll })
|
||||
&& back.Settings.HandyNames.SequenceEqual(new[] { "Elixir" }), "saved and read back");
|
||||
using var doc2 = System.Text.Json.JsonDocument.Parse("{\"settings\":{\"handyFront\":\"yes\",\"handyClasses\":[29,29,-4,\"x\",5],\"handyNames\":[\"\",7,\"Tonic\"]}}");
|
||||
CharacterSortData odd = SortStore.Parse(doc2.RootElement);
|
||||
Check(!odd.Settings.HandyFront && odd.Settings.HandyClasses.SequenceEqual(new[] { ObjectClasses.HealingKit }) && odd.Settings.HandyNames.SequenceEqual(new[] { "Tonic" }),
|
||||
"odd values: off, each kind once, only real kinds and names");
|
||||
}
|
||||
}
|
||||
}
|
||||
259
Tools/RynthSort.Tests/HoldTests.cs
Normal file
259
Tools/RynthSort.Tests/HoldTests.cs
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthSort;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// "Leave my items alone" (#rynth-issues "The bag sort feature is lacking in UX": it moves the items
|
||||
// you're working with): what counts as the player touching an item, that sorting leaves those
|
||||
// items where they are for the hold time, and the setting in the file.
|
||||
internal static partial class Program
|
||||
{
|
||||
private const long Min = 60_000;
|
||||
|
||||
private static void HoldWatch()
|
||||
{
|
||||
SortInventory inv = Inv(2);
|
||||
SortItem taper = It(10, "Prismatic Taper", ObjectClasses.SpellComponent);
|
||||
SortItem opal = It(11, "Black Opal", ObjectClasses.Gem);
|
||||
inv.Main.Items.Add(taper);
|
||||
inv.Packs[0].Items.Add(opal);
|
||||
inv.Worn.Add(20);
|
||||
var t = new TouchWatch();
|
||||
|
||||
t.Observe(inv, 0);
|
||||
Check(!t.IsHeld(10, 0, 3 * Min) && !t.IsHeld(11, 0, 3 * Min), "the first read only learns where things are");
|
||||
|
||||
// The player moves the opal to pack 2: held, as moved, for the hold time.
|
||||
inv.Packs[0].Items.Remove(opal);
|
||||
inv.Packs[1].Items.Add(opal);
|
||||
t.Observe(inv, 1000);
|
||||
Check(t.TryGetHeld(11, 1000, 3 * Min, out long at, out TouchKind kind) && at == 1000 && kind == TouchKind.Moved, "a pack change RynthSort didn't make: held, as moved");
|
||||
Check(t.IsHeld(11, 1000 + 3 * Min - 1, 3 * Min) && !t.IsHeld(11, 1000 + 3 * Min, 3 * Min), "until the hold time is up");
|
||||
Check(!t.IsHeld(11, 2000, 0), "a hold of 0 holds nothing");
|
||||
|
||||
// RynthSort's own move isn't the player's.
|
||||
t.NoteOwnMove(10, inv.Packs[0].Id, 2000);
|
||||
inv.Main.Items.Remove(taper);
|
||||
inv.Packs[0].Items.Add(taper);
|
||||
t.Observe(inv, 2500);
|
||||
Check(!t.IsHeld(10, 2500, 3 * Min), "RynthSort's own move: not held");
|
||||
// ... but the same item moved again by the player is.
|
||||
inv.Packs[0].Items.Remove(taper);
|
||||
inv.Main.Items.Add(taper);
|
||||
t.Observe(inv, 3000);
|
||||
Check(t.IsHeld(10, 3000, 3 * Min), "moved back by the player: held");
|
||||
// An own move to somewhere else doesn't cover a move the player made.
|
||||
t.ReleaseAll();
|
||||
Check(!t.IsHeld(10, 3000, 3 * Min) && !t.IsHeld(11, 3000, 3 * Min), "Sort them too: every hold dropped");
|
||||
t.NoteOwnMove(10, inv.Packs[1].Id, 3100);
|
||||
inv.Main.Items.Remove(taper);
|
||||
inv.Packs[0].Items.Add(taper);
|
||||
t.Observe(inv, 3200);
|
||||
Check(t.IsHeld(10, 3200, 3 * Min), "RynthSort sent it to pack 2 but it is in pack 1: the player's");
|
||||
|
||||
// Taken off: worn at the last read, in a pack now.
|
||||
inv.Worn.Remove(20);
|
||||
SortItem shield = It(20, "Shield", ObjectClasses.Armor);
|
||||
inv.Main.Items.Add(shield);
|
||||
t.Observe(inv, 4000);
|
||||
Check(t.TryGetHeld(20, 4000, 3 * Min, out _, out kind) && kind == TouchKind.TakenOff, "taken off: held");
|
||||
|
||||
// New items: only just after a drop (picked up, a stack split off).
|
||||
inv.Main.Items.Add(It(30, "Pyreal Mote", ObjectClasses.Misc));
|
||||
t.Observe(inv, 5000);
|
||||
Check(!t.IsHeld(30, 5000, 3 * Min), "new loot is not the player's");
|
||||
t.NoteDrop(10, 6000);
|
||||
Check(t.TryGetHeld(10, 6000, 3 * Min, out _, out kind) && kind == TouchKind.Dragged, "the dropped item itself: held");
|
||||
inv.Main.Items.Add(It(31, "Prismatic Taper", ObjectClasses.SpellComponent, stack: 5, max: 100));
|
||||
t.Observe(inv, 6500);
|
||||
Check(t.TryGetHeld(31, 6500, 3 * Min, out _, out kind) && kind == TouchKind.PickedUp, "new just after a drop (a split stack): held");
|
||||
inv.Main.Items.Add(It(32, "Prismatic Taper", ObjectClasses.SpellComponent));
|
||||
t.Observe(inv, 6000 + TouchWatch.DropWindowMs + 1);
|
||||
Check(!t.IsHeld(32, 6000 + TouchWatch.DropWindowMs + 1, 3 * Min), "new well after the drop: not held");
|
||||
|
||||
// Drags and selections.
|
||||
t.NoteDrag(11, 7000);
|
||||
Check(t.TryGetHeld(11, 7000, 3 * Min, out _, out kind) && kind == TouchKind.Dragged, "dragged: held");
|
||||
t.NoteSelected(30, 8000);
|
||||
Check(t.TryGetHeld(30, 8000, 3 * Min, out at, out kind) && kind == TouchKind.Selected && at == 8000, "selected: held");
|
||||
t.NoteSelected(30, 9000);
|
||||
Check(t.TryGetHeld(30, 9000, 3 * Min, out at, out _) && at == 9000, "still selected: the hold counts from the latest tick");
|
||||
t.NoteSelected(0x7000_0001, 9000);
|
||||
t.NoteSelected(20 + 1000, 9000);
|
||||
Eq(t.HeldCount(9000, 3 * Min), 5, "a selected monster or unknown object isn't counted");
|
||||
t.NoteSelected(inv.Packs[0].Id, 9000);
|
||||
Check(!t.IsHeld(inv.Packs[0].Id, 9000, 3 * Min), "a selected pack isn't an item");
|
||||
|
||||
// A pack missing from a read for a moment: its items are remembered.
|
||||
SortItem salvage = It(40, "Salvaged Iron", ObjectClasses.Salvage);
|
||||
inv.Packs[1].Items.Add(salvage);
|
||||
t.Observe(inv, 10_000);
|
||||
inv.Packs[1].Items.Remove(salvage);
|
||||
t.Observe(inv, 11_000);
|
||||
inv.Main.Items.Add(salvage);
|
||||
t.Observe(inv, 12_000);
|
||||
Check(t.TryGetHeld(40, 12_000, 3 * Min, out _, out kind) && kind == TouchKind.Moved, "missing from one read, then in another pack: moved");
|
||||
|
||||
// After a reset the next read only learns again.
|
||||
t.Reset();
|
||||
inv.Main.Items.Remove(salvage);
|
||||
inv.Packs[1].Items.Add(salvage);
|
||||
t.Observe(inv, 13_000);
|
||||
Check(!t.IsHeld(40, 13_000, 3 * Min), "after a reset: learning again");
|
||||
|
||||
Eq(TouchWatch.Words(TouchKind.TakenOff), "you took it off", "plain words");
|
||||
}
|
||||
|
||||
private static void HoldPlan()
|
||||
{
|
||||
SortInventory inv = Inv(3);
|
||||
inv.Main.Items.Add(It(10, "Prismatic Taper", ObjectClasses.SpellComponent));
|
||||
inv.Main.Items.Add(It(11, "Lead Scarab", ObjectClasses.SpellComponent));
|
||||
inv.Packs[1].Items.Add(It(12, "Black Opal", ObjectClasses.Gem)); // gems go to pack 3
|
||||
inv.Packs[2].Items.Add(It(13, "Junk", ObjectClasses.Misc)); // no rule: Clean evicts it
|
||||
var held = new System.Collections.Generic.HashSet<uint> { 10, 12, 13 };
|
||||
var p = new SortPlanner { Held = id => held.Contains(id) };
|
||||
|
||||
var moves = p.Plan(inv, Defaults, SortScope.All, force: true, 0, 0);
|
||||
Check(moves.Count == 1 && moves[0].Item.Id == 11, "only the scarab moves: the taper and the opal are held");
|
||||
Eq(moves[0].FromIndex, 0, "a move says where it came from (main pack)");
|
||||
Eq(moves[0].FromId, Me, "and its pack's object");
|
||||
Check(p.View.Held.Count == 2 && p.View.Held.Any(h => h.Item.Id == 10 && h.From == 0 && h.To == 1)
|
||||
&& p.View.Held.Any(h => h.Item.Id == 12 && h.From == 2 && h.To == 3), "held items listed with where they'd go");
|
||||
|
||||
moves = p.Plan(inv, Defaults, SortScope.Clean, force: true, 0, 0);
|
||||
Check(moves.All(m => m.Item.Id != 13) && p.View.Held.Any(h => h.Item.Id == 13 && h.To == 0), "Clean leaves a held stray where it is too");
|
||||
|
||||
// Not held any more: they move.
|
||||
held.Clear();
|
||||
moves = p.Plan(inv, Defaults, SortScope.All, force: true, 0, 0);
|
||||
Eq(moves.Count, 3, "nothing held: all three move");
|
||||
Eq(p.View.Held.Count, 0, "and none are listed");
|
||||
|
||||
// Stacks: a held stack is never joined into (or joined from), another one still is.
|
||||
SortInventory st = Inv(1);
|
||||
st.Packs[0].Items.Add(It(20, "Prismatic Taper", ObjectClasses.SpellComponent, wcid: 7, stack: 50, max: 100));
|
||||
st.Packs[0].Items.Add(It(21, "Prismatic Taper", ObjectClasses.SpellComponent, wcid: 7, stack: 5, max: 100));
|
||||
st.Packs[0].Items.Add(It(22, "Prismatic Taper", ObjectClasses.SpellComponent, wcid: 7, stack: 3, max: 100));
|
||||
held.Add(20);
|
||||
moves = p.Plan(st, Defaults, SortScope.All, force: true, 0, 0, PlanOptions.Full);
|
||||
Check(moves.Count == 1 && moves[0].Kind == MoveKind.Stack && moves[0].Item.Id == 22 && moves[0].MergeInto == 21,
|
||||
"the held big stack is left alone: the two others join");
|
||||
held.Add(21);
|
||||
moves = p.Plan(st, Defaults, SortScope.All, force: true, 0, 0, PlanOptions.Full);
|
||||
Check(moves.All(m => m.Kind != MoveKind.Stack), "two of three held: nothing to join");
|
||||
// A new item isn't joined into a held stack in its pack either.
|
||||
Eq(SortPlanner.StackTarget(It(23, "Prismatic Taper", ObjectClasses.SpellComponent, wcid: 7, stack: 1, max: 100), st.Packs[0], id => held.Contains(id)), 22u,
|
||||
"a route joins a stack the player isn't holding");
|
||||
|
||||
// Order: a held item isn't put in order (the others are, around it).
|
||||
SortInventory ord = Inv(1);
|
||||
ord.Packs[0].Items.Add(It(30, "Zircon", ObjectClasses.Gem));
|
||||
ord.Packs[0].Items.Add(It(31, "Amber", ObjectClasses.Gem));
|
||||
ord.Packs[0].OrderKnown = true;
|
||||
held.Clear();
|
||||
held.Add(30);
|
||||
var rules = new System.Collections.Generic.List<SortRule> { SortRule.ForClass(ObjectClasses.Gem, 1) };
|
||||
moves = p.Plan(ord, rules, SortScope.All, force: true, 0, 0, PlanOptions.Full);
|
||||
Check(moves.Count == 1 && moves[0].Kind == MoveKind.Reorder && moves[0].Item.Id == 31 && moves[0].Placement == 0, "Amber goes before the held Zircon, Zircon stays");
|
||||
held.Clear();
|
||||
held.Add(31);
|
||||
moves = p.Plan(ord, rules, SortScope.All, force: true, 0, 0, PlanOptions.Full);
|
||||
Eq(moves.Count, 0, "the item out of place is held: that pack waits for the hold to end");
|
||||
|
||||
// Unpack ignores holds (the player asked for everything).
|
||||
held.Add(12);
|
||||
Check(p.PlanUnpack(inv, null, 0).Any(m => m.Item.Id == 12), "Unpack moves a held item too");
|
||||
}
|
||||
|
||||
private static void HoldLoop()
|
||||
{
|
||||
// Components go to pack 1; the player takes a taper out to the main pack to use it.
|
||||
var w = new FakeWorld();
|
||||
SortItem taper = It(10, "Prismatic Taper", ObjectClasses.SpellComponent);
|
||||
w.Inv.Packs[0].Items.Add(taper);
|
||||
SortController c = Controller(settleSec: 5);
|
||||
c.Data.Rules = SortRules.Defaults();
|
||||
Ticks(c, w, 0, 2000);
|
||||
Eq(w.Sent.Count, 0, "in its pack: nothing to do");
|
||||
|
||||
w.Inv.Packs[0].Items.Remove(taper);
|
||||
w.Inv.Main.Items.Add(taper);
|
||||
Ticks(c, w, 2000, 60_000);
|
||||
Eq(w.Sent.Count, 0, "taken out by the player: left in the main pack");
|
||||
Check(c.Planner.View.Held.Any(h => h.Item.Id == 10 && h.To == 1), "the window can say it is left alone and where it would go");
|
||||
Check(c.IsHeld(10), "the controller says it is held");
|
||||
c.StartJob(SortScope.All);
|
||||
Ticks(c, w, 60_000, 70_000);
|
||||
Eq(w.Sent.Count, 0, "Sort now leaves it alone too");
|
||||
Check(c.Job == null, "and finishes");
|
||||
|
||||
// After the hold (3 minutes by default) auto-sort takes it back.
|
||||
Ticks(c, w, 70_000, 2000 + 3 * Min + 8000);
|
||||
Check(w.Sent.Count == 1 && w.Sent[0].Item.Id == 10 && w.Sent[0].DestIndex == 1, "after the hold it goes back to its pack");
|
||||
Check(!c.IsHeld(10), "no longer held");
|
||||
|
||||
// RynthSort's own move back didn't make it held.
|
||||
long t0 = 2000 + 3 * Min + 8000;
|
||||
Ticks(c, w, t0, t0 + 5000);
|
||||
Check(!c.IsHeld(10), "RynthSort's own move doesn't count as the player's");
|
||||
|
||||
// A selected item in the main pack (just looted) stays while selected.
|
||||
SortItem scarab = It(11, "Lead Scarab", ObjectClasses.SpellComponent);
|
||||
w.Inv.Main.Items.Add(scarab);
|
||||
long t1 = t0 + 5000;
|
||||
for (long t = t1; t <= t1 + 30_000; t += 16)
|
||||
{
|
||||
c.Touch.NoteSelected(11, t);
|
||||
c.Tick(w, t);
|
||||
}
|
||||
Eq(w.Sent.Count(m => m.Item.Id == 11), 0, "selected: not moved");
|
||||
// "Sort them too".
|
||||
c.Touch.ReleaseAll();
|
||||
Ticks(c, w, t1 + 30_016, t1 + 40_000);
|
||||
Eq(w.Sent.Count(m => m.Item.Id == 11), 1, "released: it moves");
|
||||
|
||||
// Hold 0 = off: a moved item goes back at once.
|
||||
c.Data.Settings.HoldMin = 0;
|
||||
SortItem moved = w.Inv.Packs[0].Items.First(i => i.Id == 11);
|
||||
w.Inv.Packs[0].Items.Remove(moved);
|
||||
w.Inv.Main.Items.Add(moved);
|
||||
int before = w.Sent.Count;
|
||||
Ticks(c, w, t1 + 40_000, t1 + 50_000);
|
||||
Check(w.Sent.Count == before + 1 && w.Sent[^1].Item.Id == 11, "hold off: moved straight back");
|
||||
}
|
||||
|
||||
private static void HoldStore()
|
||||
{
|
||||
SortStore st = TempStore("hold");
|
||||
CharacterSortData d = st.Load("S", "A", out _);
|
||||
Eq(d.Settings.HoldMin, SortSettings.HoldMinDefault, "a new character: the default hold");
|
||||
Eq(SortSettings.HoldMinDefault, 3, "three minutes");
|
||||
d.Settings.HoldMin = 7;
|
||||
st.Save("S", "A", d);
|
||||
Check(File.ReadAllText(st.PathFor("S", "A")).Contains("\"holdMin\": 7"), "written");
|
||||
Eq(st.Load("S", "A", out _).Settings.HoldMin, 7, "read back");
|
||||
|
||||
// A file from before the setting: the default. Out of range: clamped. A Lua double: rounded.
|
||||
File.WriteAllText(st.PathFor("S", "A"), "{\"version\":3,\"rules\":[],\"settings\":{\"auto\":true,\"settleSec\":5}}");
|
||||
CharacterSortData old = st.Load("S", "A", out string? problem);
|
||||
Check(problem == null && old.Settings.HoldMin == SortSettings.HoldMinDefault && old.Settings.Auto, "an older file: the default hold, its own settings kept");
|
||||
File.WriteAllText(st.PathFor("S", "A"), "{\"settings\":{\"holdMin\":99}}");
|
||||
Eq(st.Load("S", "A", out _).Settings.HoldMin, SortSettings.HoldMinMax, "clamped to the most");
|
||||
File.WriteAllText(st.PathFor("S", "A"), "{\"settings\":{\"holdMin\":-2}}");
|
||||
Eq(st.Load("S", "A", out _).Settings.HoldMin, 0, "clamped to off");
|
||||
File.WriteAllText(st.PathFor("S", "A"), "{\"settings\":{\"holdMin\":2.0}}");
|
||||
Eq(st.Load("S", "A", out _).Settings.HoldMin, 2, "2.0 = 2");
|
||||
|
||||
// The Lua script's file has no hold: the default.
|
||||
SortStore imp = TempStore("hold-import");
|
||||
string lua = imp.LuaPathFor("DreamWeave", "Tester");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(lua)!);
|
||||
File.WriteAllText(lua, LuaFile);
|
||||
Eq(imp.Load("DreamWeave", "Tester", out _).Settings.HoldMin, SortSettings.HoldMinDefault, "a Lua import: the default hold");
|
||||
}
|
||||
}
|
||||
}
|
||||
176
Tools/RynthSort.Tests/JobTests.cs
Normal file
176
Tools/RynthSort.Tests/JobTests.cs
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthSort;
|
||||
using RynthCore.Plugin.RynthSort.Screen;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// RynthSort 0.6.0: pack jobs. A side pack can hold what RynthAi picks: Salvage (its loot
|
||||
// profile's first matching rule says Salvage), Sell (its AutoVendor would sell it), Mule (its
|
||||
// AutoTrade would give it to the mule). RynthAi answers through RynthAi.Hub (read only); when it
|
||||
// can't (not loaded, too old, no profile), that pack changes nothing and the window says why.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static JobAnswers Answers(JobKind kind, params uint[] marked)
|
||||
{
|
||||
var a = new JobAnswers();
|
||||
var ja = new JobAnswer { Known = true, Text = "Hunting.utl" };
|
||||
foreach (uint id in marked) ja.Marked.Add(id);
|
||||
a.ByKind[kind] = ja;
|
||||
return a;
|
||||
}
|
||||
|
||||
private static PlanOptions JobOpt(SortInventory inv, List<PackJob> jobs, JobAnswers? answers) =>
|
||||
new() { Jobs = JobPlan.For(jobs, inv, answers) };
|
||||
|
||||
private static void JobsPlan()
|
||||
{
|
||||
// Pack 3 salvages; armor goes to pack 2 by kind.
|
||||
SortInventory inv = Inv(3);
|
||||
inv.Packs[2].Name = "Salvage Sack";
|
||||
inv.Main.Items.Add(It(10, "Celdon Girth", ObjectClasses.Armor)); // the loot profile says Salvage
|
||||
inv.Main.Items.Add(It(11, "Amuli Coat", ObjectClasses.Armor)); // it says Keep
|
||||
inv.Main.Items.Add(It(12, "Black Opal", ObjectClasses.Gem)); // Salvage, but a name rule sends it to pack 1
|
||||
var rules = new List<SortRule> { SortRule.ForClass(ObjectClasses.Armor, 2), SortRule.ForName("Black Opal", 1) };
|
||||
var jobs = new List<PackJob>();
|
||||
Check(PackJobs.Set(jobs, inv, 3, JobKind.Salvage, null) && !PackJobs.Set(jobs, inv, 3, JobKind.Salvage, null), "a job set once");
|
||||
Check(jobs.Single().PackId == inv.Packs[2].Id && PackJobs.On(jobs, inv, 3)?.Kind == JobKind.Salvage, "kept by the pack's id");
|
||||
Check(!PackJobs.Set(jobs, inv, 7, JobKind.Sell, null), "a pack not carried");
|
||||
|
||||
var planner = new SortPlanner();
|
||||
List<SortMove> moves = planner.Plan(inv, rules, SortScope.All, force: true, 0, 0, JobOpt(inv, jobs, Answers(JobKind.Salvage, 10, 12)));
|
||||
SortMove Of(uint id) => moves.Single(m => m.Item.Id == id);
|
||||
Eq(Of(10).DestIndex, 3, "marked Salvage: to the Salvage pack, before its kind's pack");
|
||||
Eq(Of(11).DestIndex, 2, "not marked: its kind's pack");
|
||||
Eq(Of(12).DestIndex, 1, "a name rule beats the job");
|
||||
|
||||
// RynthAi can't answer: nothing new goes in, and what is in the pack stays (Clean too).
|
||||
inv.Packs[2].Items.Add(It(20, "Celdon Sleeves", ObjectClasses.Armor));
|
||||
foreach (JobAnswers? none in new[] { null, new JobAnswers { ByKind = { [JobKind.Salvage] = JobAnswer.Unknown("RynthAi isn't loaded") } } })
|
||||
{
|
||||
moves = planner.Plan(inv, rules, SortScope.Clean, force: true, 0, 0, JobOpt(inv, jobs, none));
|
||||
Check(!moves.Any(m => m.Item.Id == 20) && !moves.Any(m => m.DestIndex == 3), "unknown: the Salvage pack's items stay, nothing goes in");
|
||||
Eq(moves.Single(m => m.Item.Id == 10).DestIndex, 2, "the marked coat goes by its kind meanwhile");
|
||||
}
|
||||
// Known, and an item in the pack is no longer marked: it follows its rules again.
|
||||
moves = planner.Plan(inv, rules, SortScope.All, force: true, 0, 0, JobOpt(inv, jobs, Answers(JobKind.Salvage, 10)));
|
||||
Eq(moves.Single(m => m.Item.Id == 20).DestIndex, 2, "not salvage any more: to its kind's pack");
|
||||
inv.Packs[2].Items.Add(It(21, "Odd Thing", ObjectClasses.Misc));
|
||||
moves = planner.Plan(inv, rules, SortScope.Clean, force: true, 0, 0, JobOpt(inv, jobs, Answers(JobKind.Salvage, 10)));
|
||||
Eq(moves.Single(m => m.Item.Id == 21).DestIndex, 0, "Clean: an unmarked item no rule wants goes back to the main pack");
|
||||
moves = planner.Plan(inv, rules, SortScope.All, force: true, 0, 0, JobOpt(inv, jobs, Answers(JobKind.Salvage, 10, 21)));
|
||||
Check(!moves.Any(m => m.Item.Id == 21), "marked and in its job pack: it stays");
|
||||
|
||||
// Held items aren't moved for a job; a full job pack says what didn't fit.
|
||||
var held = new SortPlanner { Held = id => id == 10 };
|
||||
moves = held.Plan(inv, rules, SortScope.All, force: true, 0, 0, JobOpt(inv, jobs, Answers(JobKind.Salvage, 10)));
|
||||
Check(!moves.Any(m => m.Item.Id == 10) && held.View.Held.Any(h => h.Item.Id == 10 && h.To == 3), "held: left alone, would go to the Salvage pack");
|
||||
SortInventory full = Inv(1, cap: 1);
|
||||
full.Packs[0].Name = "Salvage Sack";
|
||||
full.Packs[0].Items.Add(It(1, "Celdon Girth", ObjectClasses.Armor));
|
||||
full.Main.Items.Add(It(2, "Amuli Coat", ObjectClasses.Armor));
|
||||
var fj = new List<PackJob>();
|
||||
PackJobs.Set(fj, full, 1, JobKind.Salvage, null);
|
||||
moves = planner.Plan(full, new List<SortRule>(), SortScope.All, force: true, 0, 0, JobOpt(full, fj, Answers(JobKind.Salvage, 1, 2)));
|
||||
Check(moves.Count == 0 && planner.View.NoFit.Single().Pack == 1, "a full Salvage pack: it waits, and the banner names it");
|
||||
|
||||
// Two packs with the same job: the second takes what the first can't.
|
||||
SortInventory two = Inv(2, cap: 1);
|
||||
two.Main.Items.Add(It(1, "A", ObjectClasses.Armor));
|
||||
two.Main.Items.Add(It(2, "B", ObjectClasses.Armor));
|
||||
var tj = new List<PackJob>();
|
||||
PackJobs.Set(tj, two, 1, JobKind.Sell, null);
|
||||
PackJobs.Set(tj, two, 2, JobKind.Sell, null);
|
||||
moves = planner.Plan(two, new List<SortRule>(), SortScope.All, force: true, 0, 0, JobOpt(two, tj, Answers(JobKind.Sell, 1, 2)));
|
||||
Check(moves.Count == 2 && moves[0].DestIndex == 1 && moves[1].DestIndex == 2, "Sell: the first pack, then the next with the same job");
|
||||
|
||||
// What to ask RynthAi, and the mule.
|
||||
var mj = new List<PackJob>();
|
||||
PackJobs.Set(mj, two, 1, JobKind.Mule, " Packmule ");
|
||||
PackJobs.Set(mj, two, 2, JobKind.Salvage, null);
|
||||
List<JobKind> wanted = PackJobs.Wanted(mj, two, out string mule);
|
||||
Check(wanted.SequenceEqual(new[] { JobKind.Mule, JobKind.Salvage }) && mule == "Packmule", "the jobs carried, and the mule's name trimmed");
|
||||
Check(PackJobs.Set(mj, two, 1, JobKind.Mule, "Other") && PackJobs.On(mj, two, 1)!.Mule == "Other", "another mule: changed");
|
||||
Check(PackJobs.Set(mj, two, 1, JobKind.None, null) && PackJobs.On(mj, two, 1) == null && !PackJobs.Set(mj, two, 1, JobKind.None, null), "taken off once");
|
||||
SortInventory moved = Inv(2);
|
||||
moved.Packs.RemoveAt(1);
|
||||
Eq(PackJobs.Wanted(mj, moved, out _).Count, 0, "a job's pack not carried: nothing to ask");
|
||||
}
|
||||
|
||||
/// <summary>The fake world with RynthAi's answers (FakeWorld answers nothing, as with RynthAi not loaded).</summary>
|
||||
private sealed class JobWorld : ISortWorld
|
||||
{
|
||||
public readonly FakeWorld W = new();
|
||||
public JobAnswers? Answers;
|
||||
public int Asked;
|
||||
public SortInventory? ReadInventory() => W.ReadInventory();
|
||||
public GateInputs ReadGate(bool sortInCombat, long nowMs) => W.ReadGate(sortInCombat, nowMs);
|
||||
public bool SendMove(in SortMove move) => W.SendMove(in move);
|
||||
public MoveObservation Observe(in SortMove move) => W.Observe(in move);
|
||||
public int ErrorSeqNow() => W.ErrorSeqNow();
|
||||
public SortAbilities Abilities => W.Abilities;
|
||||
public JobAnswers? AskJobs(SortInventory inv, IReadOnlyList<JobKind> wanted, string mule, long nowMs) { Asked++; return Answers; }
|
||||
}
|
||||
|
||||
private static void JobsLoopWindowStore()
|
||||
{
|
||||
var w = new JobWorld();
|
||||
w.W.Inv.Packs[2].Name = "Junk Bag";
|
||||
w.W.Inv.Main.Items.Add(It(10, "Plain Ring", ObjectClasses.Jewelry));
|
||||
SortController c = Controller(auto: true);
|
||||
c.Data.Rules.Clear();
|
||||
for (long t = 0; t <= 2000; t += 16) c.Tick(w, t);
|
||||
Eq(w.Asked, 0, "no job: RynthAi isn't asked");
|
||||
PackJobs.Set(c.Data.Jobs, w.W.Inv, 3, JobKind.Sell, null);
|
||||
for (long t = 2000; t <= 5000; t += 16) c.Tick(w, t);
|
||||
Check(w.Asked > 0 && w.W.Inv.Main.Items.Any(i => i.Id == 10), "asked; no answer (RynthAi not loaded): the ring stays");
|
||||
ScreenModel m = Screen(c);
|
||||
Check(m.Packs[2].JobLabel == "Sell" && m.Packs[2].JobLine == "Asking RynthAi which items belong here...", $"the card ({m.Packs[2].JobLine})");
|
||||
w.Answers = new JobAnswers { ByKind = { [JobKind.Sell] = JobAnswer.Unknown("RynthAi isn't loaded") } };
|
||||
for (long t = 5000; t <= 7000; t += 16) c.Tick(w, t);
|
||||
m = Screen(c);
|
||||
Check(m.Packs[2].JobProblem && m.Packs[2].JobLine == "Sell can't work now: RynthAi isn't loaded. What is in this pack stays put until it can.", $"says why ({m.Packs[2].JobLine})");
|
||||
w.Answers = Answers(JobKind.Sell, 10);
|
||||
w.Answers.ByKind[JobKind.Sell].Text = "default.utl";
|
||||
for (long t = 7000; t <= 10_000; t += 16) c.Tick(w, t);
|
||||
Check(w.W.Inv.Packs[2].Items.Any(i => i.Id == 10), "RynthAi says sell: the ring went to the Junk Bag");
|
||||
Check(c.Feed.Any(f => f.Text == "Plain Ring -> Junk Bag"), "the feed names it");
|
||||
m = Screen(c);
|
||||
Check(!m.Packs[2].JobProblem && m.Packs[2].JobLine == "Takes what RynthAi's AutoVendor would sell (default.utl).", m.Packs[2].JobLine);
|
||||
TileModel ring = m.TilesById[10];
|
||||
Check(ring.Rule == TileRule.Job && ring.RuleText == "Sell", "the tile knows its job");
|
||||
Eq(string.Concat(ScreenText.Why(ring, m).Select(r => r.Text)), "In its pack: Junk Bag, by its job Sell.", "why");
|
||||
|
||||
// A move row for a job.
|
||||
w.W.Inv.Main.Items.Add(It(11, "Gold Ring", ObjectClasses.Jewelry));
|
||||
w.Answers.ByKind[JobKind.Sell].Marked.Add(11);
|
||||
c.SetAuto(false);
|
||||
for (long t = 10_000; t <= 12_000; t += 16) c.Tick(w, t);
|
||||
m = Screen(c);
|
||||
Check(m.Moves.Any(r => r.ItemId == 11 && r.Sub == "Job: Sell" && r.Right == "Junk Bag"), "Next moves: Job: Sell");
|
||||
Check(m.Packs[2].Ghosts.Any(g => g.ItemId == 11), "a ghost on the job pack");
|
||||
|
||||
// Mule label.
|
||||
PackJobs.Set(c.Data.Jobs, w.W.Inv, 1, JobKind.Mule, "Packmule");
|
||||
Eq(Screen(c).Packs[0].JobLabel, "Mule: Packmule", "a mule's pill");
|
||||
|
||||
// The file: kept by pack id; files from before have none; odd entries are dropped.
|
||||
var d = new CharacterSortData();
|
||||
d.Jobs.Add(new PackJob { PackId = 0x40000003, Pack = 3, Kind = JobKind.Salvage });
|
||||
d.Jobs.Add(new PackJob { PackId = 0x40000001, Pack = 1, Kind = JobKind.Mule, Mule = "Packmule" });
|
||||
using var doc = System.Text.Json.JsonDocument.Parse(SortStore.ToJson(d));
|
||||
CharacterSortData back = SortStore.Parse(doc.RootElement);
|
||||
Check(back.Jobs.Count == 2 && back.Jobs[0].Kind == JobKind.Salvage && back.Jobs[0].PackId == 0x40000003
|
||||
&& back.Jobs[1].Kind == JobKind.Mule && back.Jobs[1].Mule == "Packmule", "saved and read back");
|
||||
using var old = System.Text.Json.JsonDocument.Parse("{\"rules\":[]}");
|
||||
Eq(SortStore.Parse(old.RootElement).Jobs.Count, 0, "an older file: no jobs");
|
||||
using var odd = System.Text.Json.JsonDocument.Parse("{\"jobs\":[{\"job\":\"juggle\",\"pack\":1},7,{\"job\":\"SELL\",\"pack\":99,\"mule\":\"x\"}]}");
|
||||
CharacterSortData o = SortStore.Parse(odd.RootElement);
|
||||
Check(o.Jobs.Count == 1 && o.Jobs[0].Kind == JobKind.Sell && o.Jobs[0].Pack == SortStore.MaxPack && o.Jobs[0].Mule == "", "odd entries: unknown jobs dropped, numbers clamped, a mule only for Mule");
|
||||
using var none = System.Text.Json.JsonDocument.Parse(SortStore.ToJson(new CharacterSortData()));
|
||||
Check(!none.RootElement.TryGetProperty("jobs", out _), "no jobs: nothing written");
|
||||
}
|
||||
}
|
||||
}
|
||||
121
Tools/RynthSort.Tests/LayoutTests.cs
Normal file
121
Tools/RynthSort.Tests/LayoutTests.cs
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// Starter layouts (#rynth-issues "The bag sort feature is lacking in UX": complex rules, no
|
||||
// common-sense default) fitted to the packs a character carries, and the preview of what a
|
||||
// sort would move.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void LayoutCatalog()
|
||||
{
|
||||
Check(StarterLayouts.All.Length >= 3, "a few layouts to pick from");
|
||||
Eq(StarterLayouts.All[0].Key, "everyday", "the one to suggest first");
|
||||
Check(StarterLayouts.All.Select(l => l.Key).Distinct().Count() == StarterLayouts.All.Length
|
||||
&& StarterLayouts.All.Select(l => l.Name).Distinct().Count() == StarterLayouts.All.Length, "keys and names are unique");
|
||||
foreach (StarterLayout l in StarterLayouts.All)
|
||||
{
|
||||
Check(l.Groups.Length >= 3 && l.Blurb.Length > 0 && l.Blurb.Length <= 120, $"{l.Name}: kinds and a short line ({l.Blurb.Length})");
|
||||
var seen = new HashSet<int>();
|
||||
foreach (StarterGroup g in l.Groups)
|
||||
foreach (int c in g.Classes)
|
||||
{
|
||||
Check(seen.Add(c), $"{l.Name}: {ObjectClasses.Label(c)} is in one kind only");
|
||||
Check(ObjectClasses.ChoiceIndex(c) >= 0, $"{l.Name}: {ObjectClasses.Label(c)} is a class the rule editor offers");
|
||||
}
|
||||
}
|
||||
Check(StarterLayouts.Find("HUNTING") == StarterLayouts.Hunting && StarterLayouts.Find("nope") == null && StarterLayouts.Find(null) == null, "found by key");
|
||||
}
|
||||
|
||||
private static void LayoutFit()
|
||||
{
|
||||
// No side packs: every kind stays in the main pack.
|
||||
LayoutPlan none = StarterLayouts.Fit(StarterLayouts.Everyday, Inv(0));
|
||||
Check(none.Placed.Count == 0 && none.Rules.Count == 0 && none.Left.Count == StarterLayouts.Everyday.Groups.Length, "no packs: nothing placed");
|
||||
|
||||
// Three empty packs: the first three kinds, top pack first.
|
||||
SortInventory three = Inv(3);
|
||||
LayoutPlan p3 = StarterLayouts.Fit(StarterLayouts.Everyday, three);
|
||||
Eq(string.Join(",", p3.Placed.Select(x => x.Group.Key + x.Pack)), "components1,gems2,salvage3", "most wanted kinds on the top packs");
|
||||
Eq(string.Join(",", p3.Left.Select(g => g.Key)), "notes,supplies,scrolls", "the rest stay in the main pack");
|
||||
Check(p3.Spare.Count == 0 && p3.AlreadyThere == 0, "no spare pack, nothing in place yet");
|
||||
Check(p3.Rules.Count == 3 && p3.Rules[0].PackId == 0x40000001 && p3.Rules[0].Pack == 1 && p3.Rules[0].HasClass(ObjectClasses.SpellComponent)
|
||||
&& p3.Rules[1].HasClass(ObjectClasses.Gem) && p3.Rules[1].HasClass(ObjectClasses.ManaStone) && p3.Rules[1].HasClass(ObjectClasses.Key),
|
||||
"one rule per kind, tied to its pack's id");
|
||||
Check(p3.Rules[0].PackNote == "Pack 1 - empty", "and noted as the pack was");
|
||||
|
||||
// Packs that already hold a kind keep it (the fewest moves); the rest go to the roomiest packs.
|
||||
SortInventory four = Inv(4);
|
||||
Fill(four.Packs[0], 20, 1000); // pack 1: 20 other things
|
||||
for (uint i = 0; i < 5; i++) four.Packs[2].Items.Add(It(2000 + i, "Salvaged Iron", ObjectClasses.Salvage));
|
||||
for (uint i = 0; i < 8; i++) four.Packs[3].Items.Add(It(3000 + i, "Prismatic Taper", ObjectClasses.SpellComponent));
|
||||
LayoutPlan p4 = StarterLayouts.Fit(StarterLayouts.Basics, four);
|
||||
Eq(string.Join(",", p4.Placed.Select(x => x.Group.Key + x.Pack)), "gems2,salvage3,components4", "components stay in 4, salvage in 3, gems to the empty pack 2");
|
||||
Eq(p4.AlreadyThere, 13, "13 items already where their kind goes");
|
||||
Eq(string.Join(",", p4.Spare), "1", "pack 1 (full of other things) is left free");
|
||||
|
||||
// More packs than kinds: spares, top first.
|
||||
LayoutPlan p7 = StarterLayouts.Fit(StarterLayouts.Basics, Inv(5));
|
||||
Check(p7.Placed.Count == 3 && p7.Left.Count == 0 && string.Join(",", p7.Spare) == "4,5", "five packs, three kinds: packs 4 and 5 spare");
|
||||
LayoutPlan all = StarterLayouts.Fit(StarterLayouts.Everyday, Inv(7));
|
||||
Check(all.Placed.Count == 6 && all.Left.Count == 0 && all.Spare.Count == 1, "seven packs: every kind placed, one spare");
|
||||
|
||||
// The rules mean what the plan says.
|
||||
SortInventory inv = Inv(3);
|
||||
inv.Main.Items.Add(It(10, "Prismatic Taper", ObjectClasses.SpellComponent));
|
||||
inv.Main.Items.Add(It(11, "Black Opal", ObjectClasses.Gem));
|
||||
inv.Main.Items.Add(It(12, "Trade Note (250,000)", ObjectClasses.TradeNote));
|
||||
LayoutPlan fit = StarterLayouts.Fit(StarterLayouts.Everyday, inv);
|
||||
Eq(SortRules.Resolve(SortRules.RuleFor(fit.Rules, inv.Main.Items[0])!, inv, out _), 1, "the taper goes to pack 1");
|
||||
Eq(SortRules.Resolve(SortRules.RuleFor(fit.Rules, inv.Main.Items[1])!, inv, out _), 2, "the opal to pack 2");
|
||||
Check(SortRules.RuleFor(fit.Rules, inv.Main.Items[2]) == null, "the trade note's kind had no pack: it stays");
|
||||
}
|
||||
|
||||
private static void PreviewMoves()
|
||||
{
|
||||
SortInventory inv = Inv(3);
|
||||
inv.Main.Items.Add(It(10, "Prismatic Taper", ObjectClasses.SpellComponent));
|
||||
inv.Main.Items.Add(It(11, "Lead Scarab", ObjectClasses.SpellComponent));
|
||||
inv.Packs[1].Items.Add(It(12, "Black Opal", ObjectClasses.Gem));
|
||||
inv.Packs[2].Items.Add(It(13, "Junk", ObjectClasses.Misc));
|
||||
int before = inv.Main.Items.Count + inv.Packs.Sum(p => p.Items.Count);
|
||||
|
||||
SortPreview p = SortPreview.Build(inv, Defaults, PlanOptions.Full, null);
|
||||
Eq(p.Moves.Count, 3, "three items would move");
|
||||
Check(p.Into[1] == 2 && p.Into[3] == 1 && p.OutOf[0] == 2 && p.OutOf[2] == 1, "counted by pack in and out");
|
||||
Check(p.Moves.All(m => m.Kind == MoveKind.Route) && !p.Empty, "only moves to other packs");
|
||||
Eq(inv.Main.Items.Count + inv.Packs.Sum(x => x.Items.Count), before, "the preview moves nothing");
|
||||
Check(inv.Main.Items.Any(i => i.Id == 10), "the inventory is as it was");
|
||||
|
||||
SortPreview clean = SortPreview.Build(inv, Defaults, PlanOptions.Full, null, clean: true);
|
||||
Check(clean.Moves.Count == 4 && clean.Into[0] == 1, "Clean also sends the stray home");
|
||||
|
||||
SortPreview held = SortPreview.Build(inv, Defaults, PlanOptions.Full, id => id == 10);
|
||||
Check(held.Moves.Count == 2 && held.View.Held.Count == 1 && held.View.Held[0].Item.Id == 10, "a held item is shown apart, not as a move");
|
||||
|
||||
// Settle times and blocks of the real planner don't matter to the preview, and it doesn't touch them.
|
||||
var real = new SortPlanner();
|
||||
real.Plan(inv, Defaults, SortScope.All, force: false, 0, 60_000);
|
||||
Eq(real.View.WaitSettle, 2, "the real planner: both new items settling");
|
||||
SortPreview again = SortPreview.Build(inv, Defaults, PlanOptions.Full, null);
|
||||
Check(again.Moves.Count == 3 && real.View.WaitSettle == 2, "the preview moves them now; the real view is unchanged");
|
||||
|
||||
// Nothing to move: empty, and how much tidying inside the packs follows.
|
||||
SortInventory tidy = Inv(1);
|
||||
tidy.Packs[0].Items.Add(It(20, "Zircon", ObjectClasses.Gem));
|
||||
tidy.Packs[0].Items.Add(It(21, "Amber", ObjectClasses.Gem));
|
||||
tidy.Packs[0].OrderKnown = true;
|
||||
SortPreview t = SortPreview.Build(tidy, new List<SortRule> { SortRule.ForClass(ObjectClasses.Gem, 1) }, PlanOptions.Full, null);
|
||||
Check(t.Empty && t.ToOrder == 1, "nothing to move; one item to put in order");
|
||||
Eq(SortPreview.Build(tidy, Defaults, default, null).ToOrder, 0, "ordering off: nothing to order");
|
||||
|
||||
// A layout's preview: its rules on the packs as they are.
|
||||
LayoutPlan fit = StarterLayouts.Fit(StarterLayouts.Everyday, inv);
|
||||
SortPreview lp = SortPreview.Build(inv, fit.Rules, PlanOptions.Full, null);
|
||||
Check(lp.Into[1] == 2 && lp.Moves.Count == 2, $"Everyday on these packs: two components to pack 1, the opal stays in pack 2, which gets the gems ({string.Join(",", lp.Into)})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -103,7 +103,7 @@ namespace RynthSort.Tests
|
|||
|
||||
private static void PackColumnWindow()
|
||||
{
|
||||
var c = new SortController();
|
||||
var c = Sorter();
|
||||
var selected = new List<uint>();
|
||||
var panel = new SortPanel(c, () => { })
|
||||
{
|
||||
|
|
|
|||
|
|
@ -301,7 +301,8 @@ namespace RynthSort.Tests
|
|||
{
|
||||
SortStore st = TempStore("packids");
|
||||
CharacterSortData d = st.Load("S", "A", out _);
|
||||
Check(!d.PacksFixed, "new character: the defaults get tied to packs on the first read");
|
||||
Check(!d.PacksFixed, "new character: rules made by number get tied to packs on the first read");
|
||||
d.Rules = SortRules.Defaults();
|
||||
d.Rules[0].PackId = 0x8000ABCD;
|
||||
d.Rules[0].PackNote = "Sack - Components";
|
||||
d.PacksFixed = true;
|
||||
|
|
|
|||
319
Tools/RynthSort.Tests/PanelTests.cs
Normal file
319
Tools/RynthSort.Tests/PanelTests.cs
Normal file
|
|
@ -0,0 +1,319 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RynthCore.Engine.UI.ScriptWindows;
|
||||
using RynthCore.Plugin.RynthSort;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
using RynthCore.Plugin.RynthSort.Ui;
|
||||
using RynthCore.Plugin.RynthSort.Views;
|
||||
using RynthCore.Plugin.Shared;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// The redesigned window (#rynth-issues "The bag sort feature is lacking in UX"): what the status
|
||||
// line says, the four pages, starter layouts through the window, the moves preview, items left
|
||||
// alone, the kind picker, Undo and Put back, all driven by widget key as the engine sends them;
|
||||
// and op level 3 (tables, a bold status) only when the engine has it.
|
||||
internal static partial class Program
|
||||
{
|
||||
/// <summary>A window on a pretend game: the controller has read the packs once (auto-sort off).</summary>
|
||||
private static (SortController C, SortPanel Panel, UiHost Host, UiWindow W, FakeWorld World) Live(bool rules = true)
|
||||
{
|
||||
var world = new FakeWorld();
|
||||
world.Inv.Main.Items.Add(It(10, "Black Opal", ObjectClasses.Gem));
|
||||
world.Inv.Main.Items.Add(It(11, "Prismatic Taper", ObjectClasses.SpellComponent));
|
||||
world.Inv.Packs[1].Items.Add(It(12, "Salvaged Iron", ObjectClasses.Salvage));
|
||||
SortController c = Controller(auto: false);
|
||||
if (!rules) c.Data.Rules.Clear();
|
||||
Ticks(c, world, 0, 1000);
|
||||
var panel = new SortPanel(c, () => { }) { Character = () => "Tester", Now = () => c.Clock };
|
||||
var host = new UiHost();
|
||||
UiWindow w = host.Add(new UiWindow("RynthSort/Main", "RynthSort") { Visible = true });
|
||||
return (c, panel, host, w, world);
|
||||
}
|
||||
|
||||
private static Action<ushort, string, byte[]> Sender(UiHost host, UiWindow w, SortPanel panel)
|
||||
{
|
||||
uint seq = 100;
|
||||
return (type, id, payload) =>
|
||||
{
|
||||
Apply(host, Event(type, ++seq, w.Hash, w.KeyOf(id), payload));
|
||||
Draw(w, panel);
|
||||
};
|
||||
}
|
||||
|
||||
private static void PanelStatusWords()
|
||||
{
|
||||
SortController c = Sorter();
|
||||
var v = new SortView();
|
||||
Eq(SortPanel.Headline(c, v, false).Text, "Off: nothing moves by itself", "off");
|
||||
Eq(SortPanel.Headline(c, v, false).Color, UiColors.Grey, "off is grey");
|
||||
c.Data.Settings.Auto = true;
|
||||
var w = new FakeWorld();
|
||||
c.Tick(w, 0);
|
||||
Eq(SortPanel.Headline(c, c.Planner.View, false).Text, "On: all tidy", "on, nothing to do");
|
||||
Eq(SortPanel.Headline(c, c.Planner.View, false).Color, UiColors.Green, "green");
|
||||
Eq(SortPanel.Headline(c, c.Planner.View, true).Text, "On: no rules yet", "on without rules says so");
|
||||
v.WaitSettle = 2;
|
||||
v.NextSettleMs = 2100;
|
||||
Eq(SortPanel.Headline(c, v, false).Text, "On: 2 new items move in 3 s", "settling, with the time");
|
||||
v.WaitSettle = 1;
|
||||
Eq(SortPanel.Headline(c, v, false).Text, "On: 1 new item moves in 3 s", "one settling");
|
||||
v.WaitFull = 3;
|
||||
var (stuck, color) = SortPanel.Headline(c, v, false);
|
||||
Check(stuck == "On: 3 items can't move" && color == UiColors.Amber, "stuck items: amber");
|
||||
c.StartJob(SortScope.Clean);
|
||||
Eq(SortPanel.Headline(c, v, false).Text, "Cleaning packs", "a job says which");
|
||||
Eq(SortPanel.Headline(c, v, false).Color, UiColors.Blue, "blue while working");
|
||||
|
||||
var paused = new FakeWorld { Gate = new GateInputs { Looting = true } };
|
||||
SortController p = Controller();
|
||||
p.Tick(paused, 0);
|
||||
Eq(SortPanel.Headline(p, p.Planner.View, false).Text, "Paused: a corpse or chest is open", "paused, in plain words");
|
||||
Eq(SortPanel.PausedWords("RynthAi is buffing"), "RynthAi is buffing", "RynthAi's reasons as they are");
|
||||
Eq(SortPanel.PausedWords("busy"), "you are casting or using something", "busy");
|
||||
|
||||
var d = new SortView { WaitFull = 1, WaitNoPack = 2 };
|
||||
List<string> lines = SortPanel.Details(c, d, null, true);
|
||||
Check(lines[0].StartsWith("No rules yet", StringComparison.Ordinal), "no rules: said first");
|
||||
Check(lines.Contains("1 item waits for a full pack; 2 items for a pack you don't carry."), $"what waits, in one line ({string.Join(" | ", lines)})");
|
||||
Eq(SortPanel.Count(1, "item"), "1 item", "one");
|
||||
Eq(SortPanel.Ago(30_000) + "," + SortPanel.Ago(150_000), "just now,2 min ago", "how long ago");
|
||||
}
|
||||
|
||||
private static void PanelLayouts()
|
||||
{
|
||||
var (c, panel, host, w, _) = Live(rules: false);
|
||||
var send = Sender(host, w, panel);
|
||||
Draw(w, panel);
|
||||
ParseAll(host, "no rules", out _);
|
||||
string body = BodyText(w);
|
||||
Eq(panel.Tab, PanelTab.Layouts, "no rules: the window opens on the layouts");
|
||||
Check(body.Contains("Everyday (a good start)") && body.Contains("Hunting") && body.Contains("Crafting") && body.Contains("Just the basics"), "the layouts listed");
|
||||
Check(body.Contains("No rules yet"), "and says there are no rules");
|
||||
Check(!body.Contains("###layout.use"), "nothing to use until one is picked");
|
||||
w.MarkSubmitted(true);
|
||||
|
||||
send(1, "layout.everyday", Click);
|
||||
ParseAll(host, "a layout's preview", out _);
|
||||
body = BodyText(w);
|
||||
Check(panel.PickedLayout == "everyday", "picked");
|
||||
Check(body.Contains("Everyday on your 3 packs") && body.Contains("Spell components") && body.Contains("Gems, mana stones and keys"), "where each kind goes");
|
||||
Check(body.Contains("No pack left for trade notes and coins; healing kits, lockpicks and food; scrolls and books: they stay in the main pack."), "what has no pack");
|
||||
Check(body.Contains("Pack 2") && body.Contains("Salvage") , "salvage stays in pack 2, which holds it");
|
||||
Check(body.Contains("2 items would move; 1 already in place."), "how much would move");
|
||||
Check(body.Contains("Use this layout###layout.use") && body.Contains("Cancel###layout.cancel"), "use or cancel");
|
||||
Check(!body.Contains("This replaces"), "no rules to replace");
|
||||
Eq(c.Data.Rules.Count, 0, "looking changes nothing");
|
||||
|
||||
send(1, "layout.cancel", Click);
|
||||
Check(panel.PickedLayout == null && !BodyText(w).Contains("###layout.use"), "Cancel closes it");
|
||||
send(1, "layout.everyday", Click);
|
||||
send(1, "layout.use", Click);
|
||||
Eq(c.Data.Rules.Count, 3, "Use this layout: one rule per pack");
|
||||
Check(c.Data.Rules.Any(r => r.PackId == 0x40000002 && r.HasClass(ObjectClasses.Salvage)), "salvage tied to the pack that holds it");
|
||||
Check(!c.Data.Settings.Auto && c.Job == null, "nothing moves: auto-sort stays off, no job");
|
||||
Eq(panel.Tab, PanelTab.Packs, "back to the packs, to see the rules");
|
||||
body = BodyText(w);
|
||||
Check(body.Contains("Rules set from Everyday") && body.Contains("Nothing has moved yet"), "it says what happened");
|
||||
Check(body.Contains("Undo: the Everyday layout###undo"), "and offers Undo");
|
||||
Check(body.Contains("Spell Component (1 to move in)") || body.Contains("Spell Component (1"), "a rule says what it would bring in");
|
||||
|
||||
send(1, "undo", Click);
|
||||
Eq(c.Data.Rules.Count, 0, "Undo: the rules as they were (none)");
|
||||
Check(!BodyText(w).Contains("Undo:"), "Undo is used up");
|
||||
|
||||
// With rules already: picking says they are replaced.
|
||||
c.Data.Rules.AddRange(SortRules.Defaults());
|
||||
send(1, "tab.layouts", Click);
|
||||
send(1, "layout.basics", Click);
|
||||
Check(BodyText(w).Contains("This replaces your 3 rules (Undo brings them back)."), "replacing rules is said first");
|
||||
|
||||
// From the packs page with no rules: a button to the layouts.
|
||||
c.Data.Rules.Clear();
|
||||
send(1, "tab.packs", Click);
|
||||
Check(BodyText(w).Contains("Pick a starter layout###go.layouts"), "no rules: a way to the layouts on the packs page");
|
||||
send(1, "go.layouts", Click);
|
||||
Eq(panel.Tab, PanelTab.Layouts, "and it goes there");
|
||||
|
||||
// No side packs: nowhere to put things.
|
||||
var bare = new FakeWorld { Inv = Inv(0) };
|
||||
bare.Inv.Main.Items.Add(It(1, "Black Opal", ObjectClasses.Gem));
|
||||
SortController c0 = Controller(auto: false);
|
||||
c0.Data.Rules.Clear();
|
||||
Ticks(c0, bare, 0, 1000);
|
||||
var p0 = new SortPanel(c0, () => { }) { Character = () => "Someone" };
|
||||
var h0 = new UiHost();
|
||||
UiWindow w0 = h0.Add(new UiWindow("RynthSort/Main", "RynthSort") { Visible = true });
|
||||
Draw(w0, p0);
|
||||
ParseAll(h0, "no packs", out _);
|
||||
Check(BodyText(w0).Contains("You carry no side packs"), "no packs: says so");
|
||||
}
|
||||
|
||||
private static void PanelMoves()
|
||||
{
|
||||
var (c, panel, host, w, world) = Live();
|
||||
var send = Sender(host, w, panel);
|
||||
Draw(w, panel);
|
||||
Eq(panel.Tab, PanelTab.Packs, "with rules: the packs page first");
|
||||
string body = BodyText(w);
|
||||
Check(body.Contains("Moves (2)###tab.moves"), "the page button counts the moves");
|
||||
Check(body.Contains("2 items would move when you sort (see Moves)."), "the status says what a sort would do");
|
||||
send(1, "tab.moves", Click);
|
||||
ParseAll(host, "moves page", out _);
|
||||
body = BodyText(w);
|
||||
Check(body.Contains("A sort would move 2 items:"), "how many");
|
||||
Check(body.Contains("Black Opal") && body.Contains("main pack -> pack 3"), "the opal: from and to");
|
||||
Check(body.Contains("Prismatic Taper") && body.Contains("main pack -> pack 1") && !body.Contains("Salvaged Iron"), "the taper to pack 1; the salvage is in its pack already");
|
||||
Check(body.Contains("Nothing moves until you press Sort now or turn on Auto-sort."), "and that nothing moves yet");
|
||||
Check(body.Contains("Its rule: Gem, Key, Mana Stone."), "a move's tooltip says which rule");
|
||||
Check(!ContainsOp(w.Body, UiFormat.OpTable) && !ContainsOp(w.Body, UiFormat.OpPushFont), "op level 2: no tables, no fonts");
|
||||
|
||||
// The player selects the opal: it is left alone, and the page says so.
|
||||
c.Touch.NoteSelected(10, 1100);
|
||||
Ticks(c, world, 1100, 2200);
|
||||
Draw(w, panel);
|
||||
ParseAll(host, "left alone", out _);
|
||||
body = BodyText(w);
|
||||
Check(body.Contains("Left alone") && body.Contains("you selected it just now; would go to pack 3"), "left alone, how and where it would go");
|
||||
Check(body.Contains("A sort would move 1 item:"), "and it isn't counted as a move");
|
||||
Check(body.Contains("for 3 minutes (Settings)"), "for how long");
|
||||
Check(body.Contains("1 item left alone because you used it lately (see Moves)."), "the status says so too");
|
||||
send(1, "hold.release", Click);
|
||||
Check(!c.IsHeld(10) && !BodyText(w).Contains("Left alone"), "Sort them too: no longer held");
|
||||
|
||||
// A sort, then the log and Put back.
|
||||
send(1, "job.all", Click);
|
||||
Ticks(c, world, 2200, 6000);
|
||||
Draw(w, panel);
|
||||
body = BodyText(w);
|
||||
Check(body.Contains("Nothing to move: every item is in its pack."), "sorted: nothing left to move");
|
||||
Check(body.Contains("Black Opal -> pack 3") && body.Contains("Packs sorted"), "the moves in Done lately");
|
||||
Check(body.Contains("Put back###job.back") && body.Contains("Put back 2 items###moves.back"), "Put back beside Sort now and on this page");
|
||||
send(1, "moves.back", Click);
|
||||
Check(c.Job == SortScope.PutBack && !c.Data.Settings.Auto, "Put back starts (auto-sort off)");
|
||||
Ticks(c, world, 6000, 10_000);
|
||||
Check(world.Inv.Main.Items.Any(i => i.Id == 10) && world.Inv.Main.Items.Any(i => i.Id == 11), "the two items are back in the main pack");
|
||||
Draw(w, panel);
|
||||
Check(!BodyText(w).Contains("Put back###job.back"), "nothing left to put back: no button");
|
||||
|
||||
// Op level 3: the list is a table and the status bold; still accepted by the engine.
|
||||
panel.OpLevel = () => 3;
|
||||
Draw(w, panel);
|
||||
ParseAll(host, "op level 3", out _);
|
||||
Check(ContainsOp(w.Body, UiFormat.OpTable) && ContainsOp(w.Body, UiFormat.OpTableNextRow) && ContainsOp(w.Body, UiFormat.OpPushFont), "op level 3: a table and the bold status");
|
||||
body = BodyText(w);
|
||||
Check(body.Contains("Item") && body.Contains("From") && body.Contains("To"), "the table's columns");
|
||||
int engineLevel = DisplayListParser.OpLevel; // 2 with the sibling checkout, 3 with -p:EngineParser=<an op level 3 engine>
|
||||
if (engineLevel >= 3)
|
||||
{
|
||||
List<ParsedWindow> parsed = ParseWindows(host);
|
||||
var ops = parsed[0].List!.Ops.Take(parsed[0].List!.OpCount).Select(o => (byte)o.Code).ToList();
|
||||
Check(ops.Contains(UiFormat.OpTable) && ops.Count(o => o == UiFormat.OpTableNextRow) == 2 && ops.Contains(UiFormat.OpPushFont),
|
||||
"an op level 3 engine keeps the table, its two rows and the font");
|
||||
}
|
||||
}
|
||||
|
||||
private static void PanelPacks()
|
||||
{
|
||||
var (c, panel, host, w, world) = Live();
|
||||
panel.Icons = () => true;
|
||||
var send = Sender(host, w, panel);
|
||||
Draw(w, panel);
|
||||
ParseAll(host, "packs page", out _);
|
||||
string body = BodyText(w);
|
||||
Check(body.Contains("Goes here:"), "what goes in each pack");
|
||||
Check(body.Contains("Salvage (1 here)"), "a rule says how many items it keeps there");
|
||||
Check(body.Contains("Gem, Key, Mana Stone (1 to move in)"), "and how many would move in");
|
||||
Check(body.Contains("###kind.40000001") && body.Contains("Add a kind of item..."), "a kind picker per pack");
|
||||
Check(body.Contains("Salvaged Iron"), "the pack's contents strip names its items");
|
||||
|
||||
// Gems to pack 1 with the kind picker: taken from pack 3's rule.
|
||||
SortRule gems = c.Data.Rules.First(r => r.HasClass(ObjectClasses.Gem));
|
||||
int pick = ObjectClasses.Choices.Where(x => x != ObjectClasses.SpellComponent).ToList().IndexOf(ObjectClasses.Gem) + 1;
|
||||
send(3, "kind.40000001", BitConverter.GetBytes(pick));
|
||||
Check(!gems.HasClass(ObjectClasses.Gem) && gems.HasClass(ObjectClasses.Key), "pack 3's rule gave up Gem");
|
||||
Check(c.Data.Rules.Any(r => r.HasClass(ObjectClasses.Gem) && r.HasClass(ObjectClasses.SpellComponent) && SortPanel.ShownPack(c.Planner.View, r) == 1),
|
||||
"and pack 1's rule took it");
|
||||
Check(BodyText(w).Contains("Gems now go here (taken from pack 3). Nothing has moved yet."), "it says so under the pack");
|
||||
Check(BodyText(w).Contains("Undo: Gems to pack 1###undo"), "with Undo");
|
||||
send(1, "undo", Click);
|
||||
Check(c.Data.Rules.Count == 3 && c.Data.Rules.Single(r => r.HasClass(ObjectClasses.Gem)).HasClass(ObjectClasses.Key), "Undo: back as it was");
|
||||
send(3, "kind.40000001", BitConverter.GetBytes(0));
|
||||
Eq(c.Data.Rules.Count(r => r.HasClass(ObjectClasses.Gem)), 1, "the picker's first line does nothing");
|
||||
|
||||
// A kind no pack had goes into the pack's rule; a pack with no rule gets a new one.
|
||||
send(3, "kind.40000003", BitConverter.GetBytes(ObjectClasses.Choices.Where(x => x != ObjectClasses.Gem && x != ObjectClasses.ManaStone && x != ObjectClasses.Key).ToList().IndexOf(ObjectClasses.Lockpick) + 1));
|
||||
Check(c.Data.Rules.Single(r => r.HasClass(ObjectClasses.Gem)).HasClass(ObjectClasses.Lockpick), "lockpicks join pack 3's rule");
|
||||
world.Inv.Packs.Add(new SortPack { Id = 0x40000004, Name = "Pack 4", Capacity = 24 });
|
||||
Ticks(c, world, 1000, 2500);
|
||||
Draw(w, panel);
|
||||
Check(BodyText(w).Contains("Nothing goes here yet."), "a new pack: nothing goes there yet");
|
||||
int before = c.Data.Rules.Count;
|
||||
send(3, "kind.40000004", BitConverter.GetBytes(ObjectClasses.ChoiceIndex(ObjectClasses.Food) + 1));
|
||||
Check(c.Data.Rules.Count == before + 1 && c.Data.Rules[^1].HasClass(ObjectClasses.Food) && c.Data.Rules[^1].PackId == 0x40000004, "a pack with no rule gets one");
|
||||
|
||||
// Removing a rule can be undone.
|
||||
SortRule food = c.Data.Rules[^1];
|
||||
send(1, $"r{food.Uid}.row", Click);
|
||||
send(1, $"r{food.Uid}.remove", Click);
|
||||
Check(!c.Data.Rules.Contains(food) && BodyText(w).Contains("Undo: rule removed"), "removed, with Undo");
|
||||
send(1, "undo", Click);
|
||||
Check(c.Data.Rules.Any(r => r.HasClass(ObjectClasses.Food) && r.PackId == 0x40000004), "and back");
|
||||
|
||||
// The setting for leaving items alone.
|
||||
send(1, "tab.settings", Click);
|
||||
send(3, "hold", BitConverter.GetBytes(12));
|
||||
Eq(c.Data.Settings.HoldMin, 12, "Leave alone (min)");
|
||||
send(3, "hold", BitConverter.GetBytes(500));
|
||||
Eq(c.Data.Settings.HoldMin, SortSettings.HoldMinMax, "clamped");
|
||||
Check(BodyText(w).Contains("stays put for 30 minutes"), "the line under it says what it does");
|
||||
send(3, "hold", BitConverter.GetBytes(0));
|
||||
Check(BodyText(w).Contains("Off: an item you take out of its pack goes back at the next sort."), "and when it is off");
|
||||
|
||||
// Another character: the window starts fresh.
|
||||
panel.Character = () => "Someone";
|
||||
c.Data.Rules.Clear();
|
||||
Draw(w, panel);
|
||||
Eq(panel.Tab, PanelTab.Layouts, "another character with no rules: the layouts");
|
||||
Check(panel.UndoWhat.Length == 0, "and no Undo from the last one");
|
||||
}
|
||||
|
||||
private static void PanelBudget()
|
||||
{
|
||||
// A full character: eight packs of 24, a full main pack, 64 rules, icons, every page.
|
||||
var world = new FakeWorld { Inv = Inv(8, cap: 40) };
|
||||
uint id = 1;
|
||||
for (int p = 0; p < 8; p++)
|
||||
for (int i = 0; i < 24; i++) world.Inv.Packs[p].Items.Add(It(id++, $"Thing {p}-{i}", ObjectClasses.Choices[(p + i) % ObjectClasses.Choices.Length]));
|
||||
for (int i = 0; i < 102; i++) world.Inv.Main.Items.Add(It(id++, $"Loot {i}", ObjectClasses.Choices[i % ObjectClasses.Choices.Length]));
|
||||
SortController c = Controller(auto: false);
|
||||
c.Data.Rules.Clear();
|
||||
for (int i = 0; i < SortStore.MaxRules; i++)
|
||||
c.Data.Rules.Add(SortRule.For(1 + i % 8, new[] { ObjectClasses.Choices[i % ObjectClasses.Choices.Length] }, "x" + i));
|
||||
Ticks(c, world, 0, 1000);
|
||||
var panel = new SortPanel(c, () => { }) { Character = () => "Tester", Icons = () => true, CanSelect = () => true };
|
||||
var host = new UiHost();
|
||||
UiWindow w = host.Add(new UiWindow("RynthSort/Main", "RynthSort") { Visible = true });
|
||||
foreach (int level in new[] { 2, 3 })
|
||||
{
|
||||
panel.OpLevel = () => level;
|
||||
foreach (PanelTab tab in Enum.GetValues<PanelTab>())
|
||||
{
|
||||
panel.ShowTab(tab);
|
||||
Draw(w, panel);
|
||||
ParseAll(host, $"level {level}, {tab}", out int ops);
|
||||
Check(ops < 1500 && !BodyText(w).Contains("more than fits in one window"), $"level {level}, {tab}: fits ({ops} ops)");
|
||||
Console.WriteLine($" level {level}, {tab}: {ops} ops, {w.Body.Length} bytes");
|
||||
w.MarkSubmitted(true);
|
||||
}
|
||||
panel.ShowTab(PanelTab.Layouts);
|
||||
Apply(host, Event(1, 1, w.Hash, w.KeyOf("layout.everyday"), Click));
|
||||
Draw(w, panel);
|
||||
ParseAll(host, $"level {level}, a layout preview", out int lops);
|
||||
Check(lops < 1500, $"level {level}: a layout preview fits ({lops} ops)");
|
||||
Apply(host, Event(1, 2, w.Hash, w.KeyOf("layout.cancel"), Click));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -92,6 +92,46 @@ namespace RynthSort.Tests
|
|||
Run("plan: a fixed inventory runs out of moves", Converges);
|
||||
Run("loop: auto-sort tidies every pack, then stays still", ConvergesInTheLoop);
|
||||
Run("remote: another plugin's \"rsort\" command reaches /rsort, anything else is not ours", RemoteCommand);
|
||||
Run("add selected: the rule text from an item's name", AddSelectedText);
|
||||
Run("add selected: finding the selected object in the packs", AddSelectedLookup);
|
||||
Run("add selected: nothing selected, not an item, no pack", AddSelectedRefusals);
|
||||
Run("add selected: where the name goes", AddSelectedAdds);
|
||||
Run("add selected: duplicates", AddSelectedDuplicates);
|
||||
Run("add selected: an item another pack's rule takes", AddSelectedOtherPack);
|
||||
Run("add selected: the window button and the command", AddSelectedWindow);
|
||||
Run("hold: what counts as the player touching an item", HoldWatch);
|
||||
Run("hold: touched items are left where they are (moves, stacks, order)", HoldPlan);
|
||||
Run("hold: in the loop (taken out, selected, released, off)", HoldLoop);
|
||||
Run("hold: the setting in the file (old files, clamps, Lua import)", HoldStore);
|
||||
Run("put back: the last sort undone, in the loop", PutBackLoop);
|
||||
Run("put back: what can go back (room, packs, gone)", PutBackPlan);
|
||||
Run("layouts: the starter layouts", LayoutCatalog);
|
||||
Run("layouts: fitted to the packs carried (contents first, then room)", LayoutFit);
|
||||
Run("preview: what a sort would move, before anything moves", PreviewMoves);
|
||||
Run("window: what the status line says (off, on, settling, stuck, paused, jobs)", PanelStatusWords);
|
||||
Run("window: starter layouts picked, previewed, used and undone", PanelLayouts);
|
||||
Run("window: the moves page (preview, left alone, Sort them too, Put back, op level 3)", PanelMoves);
|
||||
Run("window: the packs page (counts, kind picker, Undo) and the hold setting", PanelPacks);
|
||||
Run("window: a full character fits on every page at op levels 2 and 3", PanelBudget);
|
||||
Run("layouts: a pack keeps the kind it already holds, before kinds no pack holds", LayoutHeldKindsFirst);
|
||||
Run("hold: one item left alone, or let go", HoldOneItem);
|
||||
Run("send: an item sent to a pack from the window (Just move it, Send to)", SendFromWindow);
|
||||
Run("screen: the activity feed with times, and settling items", ScreenFeedAndSettling);
|
||||
Run("screen: the view-model's packs, tiles, chips, moves, left alone and status", ScreenModelPacks);
|
||||
Run("screen: rules for packs not carried, and the layouts popup", ScreenModelOrphansAndLayouts);
|
||||
Run("screen: rule changes (All a kind, Only a name, the x), toasts and Undo", ScreenRuleEdits);
|
||||
Run("window: the sections manifest (frameless, drawn at its own size)", WindowManifest);
|
||||
Run("window: tiles that just arrived pop in", WindowArrivals);
|
||||
Run("feed: packs by name, with the number when two share it", FeedPackNames);
|
||||
Run("drop: an item from RynthCore's Inventory on a pack card (one drop, the engine's payload)", DropFromInventory);
|
||||
Run("handy: kits, stones, food, potions and elixirs at the front of the main pack", HandyFront);
|
||||
Run("handy: in the loop, held items, the window and the file", HandyLoopAndStore);
|
||||
Run("fold: packs fold to their header and rules, saved by pack id", FoldedPacks);
|
||||
Run("rules: a typed name on \"+ Add a rule\" (no item needed)", TypedNameRule);
|
||||
Run("full pack: overflow into the next pack with the same rule, else it waits", FullPackSpill);
|
||||
Run("full pack: one chat line per sort, the banner, the red bar, overflow chips", FullPackWarnings);
|
||||
Run("jobs: Salvage, Sell and Mule packs in the planner (name, job, kind; RynthAi can't answer)", JobsPlan);
|
||||
Run("jobs: in the loop, the window and the file", JobsLoopWindowStore);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -596,9 +636,17 @@ namespace RynthSort.Tests
|
|||
return false;
|
||||
}
|
||||
|
||||
private static SortController Controller(bool auto = true, int gapMs = 300, int settleSec = 0)
|
||||
/// <summary>A controller with the old script's three rules (components 1, salvage 2, gems/stones/keys 3): a new character has none now.</summary>
|
||||
private static SortController Sorter()
|
||||
{
|
||||
var c = new SortController();
|
||||
c.Data.Rules = SortRules.Defaults();
|
||||
return c;
|
||||
}
|
||||
|
||||
private static SortController Controller(bool auto = true, int gapMs = 300, int settleSec = 0)
|
||||
{
|
||||
var c = Sorter();
|
||||
c.Data.Settings.Auto = auto;
|
||||
c.Data.Settings.GapMs = gapMs;
|
||||
c.Data.Settings.SettleSec = settleSec;
|
||||
|
|
@ -833,11 +881,13 @@ namespace RynthSort.Tests
|
|||
{
|
||||
SortStore st = TempStore("roundtrip");
|
||||
CharacterSortData d = st.Load("DreamWeave", "Drakkon", out string? problem);
|
||||
Check(problem == null && d.Rules.Count == 3 && d.ImportedFrom.Length == 0, "no file: the defaults");
|
||||
Check(problem == null && d.Rules.Count == 0 && d.ImportedFrom.Length == 0, "no file: no rules (the window offers starter layouts)");
|
||||
Check(!d.Settings.WindowOpen, "no file: the window starts closed (the bar button opens it)");
|
||||
Check(!d.Settings.Auto, "no file: auto-sort starts off until it is turned on");
|
||||
d.Rules = SortRules.Defaults();
|
||||
d.Rules.Add(SortRule.ForName("Pyreal \"Mote\"", 6));
|
||||
d.Rules[0].On = false;
|
||||
d.Settings.Auto = false;
|
||||
d.Settings.Auto = true;
|
||||
d.Settings.SettleSec = 12;
|
||||
d.Settings.GapMs = 900;
|
||||
d.Settings.SortInCombat = true;
|
||||
|
|
@ -849,7 +899,7 @@ namespace RynthSort.Tests
|
|||
Eq(back.Rules.Count, 4, "rules");
|
||||
Check(!back.Rules[0].On && back.Rules[3].Classes.Count == 0 && back.Rules[3].Names.Count == 1 && back.Rules[3].Names[0] == "Pyreal \"Mote\"" && back.Rules[3].Pack == 6, "rule fields");
|
||||
Check(back.Rules[2].SameAs(SortRules.Defaults()[2]), "a rule with three classes comes back whole");
|
||||
Check(!back.Settings.Auto && back.Settings.SettleSec == 12 && back.Settings.GapMs == 900 && back.Settings.SortInCombat && back.Settings.WindowOpen, "settings");
|
||||
Check(back.Settings.Auto && back.Settings.SettleSec == 12 && back.Settings.GapMs == 900 && back.Settings.SortInCombat && back.Settings.WindowOpen, "settings");
|
||||
Eq(SortStore.FileStem("Dream:Weave", "Con"), "Dream_Weave_Con", "unsafe characters replaced like RynthLua");
|
||||
Eq(SortStore.SafeFileName("CON"), "_CON", "reserved names guarded");
|
||||
}
|
||||
|
|
@ -890,7 +940,7 @@ namespace RynthSort.Tests
|
|||
Directory.CreateDirectory(Path.GetDirectoryName(own)!);
|
||||
File.WriteAllText(own, "{ not json");
|
||||
CharacterSortData d = st.Load("S", "A", out string? problem);
|
||||
Check(problem != null && d.Rules.Count == 3, "broken file: defaults, problem reported");
|
||||
Check(problem != null && d.Rules.Count == 0, "broken file: no rules, problem reported");
|
||||
|
||||
// The Lua script saved an empty rule list as {}; numbers as doubles; out-of-range values clamped.
|
||||
File.WriteAllText(own, "{\"rules\":{},\"settings\":{\"auto\":true,\"settleSec\":99.0,\"gapMs\":5,\"x\":1}}");
|
||||
|
|
@ -923,7 +973,7 @@ namespace RynthSort.Tests
|
|||
|
||||
private static (SortController, SortPanel, UiHost, UiWindow) Window()
|
||||
{
|
||||
var c = new SortController();
|
||||
var c = Sorter();
|
||||
var panel = new SortPanel(c, () => { }) { Character = () => "Drakkon" };
|
||||
var host = new UiHost();
|
||||
UiWindow w = host.Add(new UiWindow("RynthSort/Main", "RynthSort") { Visible = true });
|
||||
|
|
@ -1002,11 +1052,13 @@ namespace RynthSort.Tests
|
|||
ParseAll(host, "default rules", out int ops);
|
||||
Check(ops > 10 && ops < 1500, $"ops in range ({ops})");
|
||||
string body = BodyText(w);
|
||||
Check(body.Contains("Auto-sort") && body.Contains("Sort now") && body.Contains("Clean packs") && body.Contains("Empty side packs"), "buttons and toggle");
|
||||
Check(body.Contains("Auto-sort") && body.Contains("Sort now") && body.Contains("Clean packs") && body.Contains("Off: nothing moves by itself"), "buttons, toggle and what it is doing");
|
||||
Check(body.Contains("Packs###tab.packs") && body.Contains("Moves###tab.moves") && body.Contains("Layouts###tab.layouts") && body.Contains("Settings###tab.settings"), "the four pages");
|
||||
Check(!body.Contains("Empty side packs"), "Empty side packs is on the Settings page, not beside Sort now");
|
||||
Check(body.Contains("Main pack (1/102)"), "the main pack's line");
|
||||
Check(body.Contains("Pack 1: Pack 1 (24/24) - Junk 0, Junk 1, Junk 2"), "a section per pack, named with its room and contents");
|
||||
Check(body.Contains("Pack 3: Pack 3 (0/24) - empty") && body.Contains("Gem, Key, Mana Stone"), "a rule with three classes as one row under its pack");
|
||||
Check(body.Contains("Pack 4: Pack 4 (0/24) - empty") && body.Contains("No rules send items here."), "a pack without rules says so");
|
||||
Check(body.Contains("Pack 4: Pack 4 (0/24) - empty") && body.Contains("Nothing goes here yet."), "a pack without rules says so");
|
||||
Check(body.IndexOf("Pack 1: ", StringComparison.Ordinal) < body.IndexOf("Spell Component", StringComparison.Ordinal)
|
||||
&& body.IndexOf("Spell Component", StringComparison.Ordinal) < body.IndexOf("Pack 2: ", StringComparison.Ordinal), "a rule sits under its pack");
|
||||
Check(!body.Contains("Classes:"), "no editor until a rule is picked");
|
||||
|
|
@ -1015,7 +1067,6 @@ namespace RynthSort.Tests
|
|||
// The gem rule's editor, the settings open, warnings and a log.
|
||||
SortRule gemRule = c.Data.Rules[2];
|
||||
Apply(host, Event(1, 1, w.Hash, w.KeyOf($"r{gemRule.Uid}.row"), Click));
|
||||
Apply(host, Event(6, 2, w.Hash, w.KeyOf("settings"), new byte[] { 1 }));
|
||||
c.Note("Prismatic Taper -> pack 1");
|
||||
panel.Warnings = () => new[] { "The RynthSort Lua script is set to start too" };
|
||||
Draw(w, panel);
|
||||
|
|
@ -1024,12 +1075,21 @@ namespace RynthSort.Tests
|
|||
Check(body.Contains("Classes:") && body.Contains("Gem x") && body.Contains("Key x") && body.Contains("Mana Stone x"), "the rule's classes as chips");
|
||||
Check(body.Contains("Add a class...") && body.Contains("Name has") && body.Contains("Remove rule"), "add a class, add a name, remove");
|
||||
Check(body.Contains("Pack 3: Pack 3 (0/24) - empty") && body.Contains("Pack 7 (none)"), "the pack picker");
|
||||
Check(body.Contains("Settle (s)") && body.Contains("Gap (ms)") && body.Contains("Sort during fights")
|
||||
&& body.Contains("Put items in order inside packs") && body.Contains("Group by kind first"), "settings shown");
|
||||
Check(body.Contains("plugin API 80"), "an engine that can't read orders: said in the settings");
|
||||
Check(body.Contains("Lua script is set to start"), "warning shown");
|
||||
Check(body.Contains("Last: Prismatic Taper -> pack 1"), "the last move under the status");
|
||||
w.MarkSubmitted(true);
|
||||
|
||||
Apply(host, Event(1, 2, w.Hash, w.KeyOf("tab.settings"), Click));
|
||||
Draw(w, panel);
|
||||
ParseAll(host, "settings page", out _);
|
||||
body = BodyText(w);
|
||||
Check(body.Contains("Settle (s)") && body.Contains("Gap (ms)") && body.Contains("Sort during fights") && body.Contains("Leave alone (min)")
|
||||
&& body.Contains("Put items in order inside packs") && body.Contains("Group by kind first") && body.Contains("Empty side packs"), "settings shown");
|
||||
Check(body.Contains("plugin API 80"), "an engine that can't read orders: said in the settings");
|
||||
Check(!body.Contains("Classes:"), "the packs aren't drawn on the settings page");
|
||||
w.MarkSubmitted(true);
|
||||
Apply(host, Event(1, 3, w.Hash, w.KeyOf("tab.packs"), Click));
|
||||
|
||||
gemRule.AddName("Opal");
|
||||
gemRule.AddName("a##b");
|
||||
Draw(w, panel);
|
||||
|
|
@ -1160,7 +1220,7 @@ namespace RynthSort.Tests
|
|||
Check(!c.Data.Rules.Contains(r) && panel.Selected == null, "Remove");
|
||||
|
||||
// Settings and buttons.
|
||||
Send(6, "settings", new byte[] { 1 });
|
||||
Send(1, "tab.settings", Click);
|
||||
Send(3, "settle", BitConverter.GetBytes(12));
|
||||
Send(3, "gap", BitConverter.GetBytes(50_000));
|
||||
Send(2, "combat", new byte[] { 1 });
|
||||
|
|
@ -1168,8 +1228,10 @@ namespace RynthSort.Tests
|
|||
Send(2, "order", new byte[] { 0 });
|
||||
Send(2, "orderkind", new byte[] { 1 });
|
||||
Check(!c.Data.Settings.OrderInPacks && c.Data.Settings.OrderKindFirst, "the order boxes");
|
||||
Send(2, "auto", new byte[] { 1 });
|
||||
Check(c.Data.Settings.Auto, "auto-sort box on");
|
||||
Send(2, "auto", new byte[] { 0 });
|
||||
Check(!c.Data.Settings.Auto, "auto-sort box");
|
||||
Check(!c.Data.Settings.Auto, "auto-sort box off");
|
||||
Send(1, "job.all", Click);
|
||||
Eq(c.Job, SortScope.All, "Sort now button");
|
||||
Send(1, "job.unpack", Click);
|
||||
|
|
|
|||
106
Tools/RynthSort.Tests/PutBackTests.cs
Normal file
106
Tools/RynthSort.Tests/PutBackTests.cs
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthSort;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// "Put back": the last sort's moves undone (items back to the packs they came from), with
|
||||
// auto-sort off first so nothing moves straight back again.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void PutBackLoop()
|
||||
{
|
||||
var w = new FakeWorld();
|
||||
w.Inv.Main.Items.Add(It(10, "Prismatic Taper", ObjectClasses.SpellComponent));
|
||||
w.Inv.Main.Items.Add(It(11, "Salvaged Iron", ObjectClasses.Salvage));
|
||||
w.Inv.Packs[0].Items.Add(It(12, "Black Opal", ObjectClasses.Gem));
|
||||
SortController c = Controller();
|
||||
c.Data.Rules = SortRules.Defaults();
|
||||
Ticks(c, w, 0, 5000);
|
||||
Eq(w.Sent.Count, 3, "the sort moved three items");
|
||||
Eq(c.PutBackCount, 3, "all three can be put back");
|
||||
Check(c.History.Any(h => h.ItemId == 12 && h.FromId == 0x40000001 && h.ToId == 0x40000003), "each with where it came from");
|
||||
|
||||
Check(c.StartPutBack(), "Put back starts");
|
||||
Check(!c.Data.Settings.Auto && c.Job == SortScope.PutBack, "auto-sort off first, the job asked for");
|
||||
Ticks(c, w, 5000, 10_000);
|
||||
Check(w.Inv.Main.Items.Any(i => i.Id == 10) && w.Inv.Main.Items.Any(i => i.Id == 11) && w.Inv.Packs[0].Items.Any(i => i.Id == 12),
|
||||
"every item is back where it was");
|
||||
Eq(w.Sent.Count, 6, "three moves back");
|
||||
Check(c.Job == null && c.PutBackCount == 0, "done, nothing left to put back");
|
||||
Eq(c.Log[0], "Put back 3 items", "the log says so");
|
||||
Check(!c.StartPutBack(), "nothing to put back: it doesn't start");
|
||||
Ticks(c, w, 10_000, 15_000);
|
||||
Eq(w.Sent.Count, 6, "and nothing moves again (auto-sort is off)");
|
||||
|
||||
// Moved since by the player: that one stays where the player put it.
|
||||
c.SetAuto(true);
|
||||
Ticks(c, w, 15_000, 20_000);
|
||||
Eq(c.PutBackCount, 3, "sorted again");
|
||||
SortItem opal = w.Inv.Packs[2].Items.First(i => i.Id == 12);
|
||||
w.Inv.Packs[2].Items.Remove(opal);
|
||||
w.Inv.Packs[1].Items.Add(opal);
|
||||
c.StartPutBack();
|
||||
Ticks(c, w, 20_000, 26_000);
|
||||
Check(w.Inv.Packs[1].Items.Any(i => i.Id == 12), "the opal the player moved stays");
|
||||
Check(w.Inv.Main.Items.Any(i => i.Id == 10) && w.Inv.Main.Items.Any(i => i.Id == 11), "the other two went back");
|
||||
Check(c.Log[0].StartsWith("Put back 2 items (1 gone", StringComparison.Ordinal), $"the log counts the one left ({c.Log[0]})");
|
||||
|
||||
// A new sort after a pause starts a new list; an item moved twice goes back to its first pack.
|
||||
var w2 = new FakeWorld();
|
||||
w2.Inv.Main.Items.Add(It(20, "Prismatic Taper", ObjectClasses.SpellComponent));
|
||||
SortController c2 = Controller();
|
||||
c2.Data.Rules = new List<SortRule> { SortRule.ForClass(ObjectClasses.SpellComponent, 1) };
|
||||
Ticks(c2, w2, 0, 3000);
|
||||
Check(c2.History.Count == 1 && c2.History[0].FromId == Me, "to pack 1 from the main pack");
|
||||
c2.Data.Rules[0].Pack = 2;
|
||||
c2.Data.Rules[0].PackId = 0x40000002;
|
||||
Ticks(c2, w2, 3000, 6000);
|
||||
Check(c2.History.Count == 1 && c2.History[0].FromId == Me && c2.History[0].ToId == 0x40000002, "moved again: still goes back to the main pack");
|
||||
w2.Inv.Main.Items.Add(It(21, "Lead Scarab", ObjectClasses.SpellComponent));
|
||||
Ticks(c2, w2, 6000 + SortController.RunGapMs + 1000, 6000 + SortController.RunGapMs + 5000);
|
||||
Check(c2.History.Count == 1 && c2.History[0].ItemId == 21, "a sort after a pause: only its moves");
|
||||
|
||||
// Stack joins aren't kept (the item is gone), and old moves fall off.
|
||||
var w3 = new FakeWorld { Can = SortAbilities.All };
|
||||
w3.Inv.Packs[0].Items.Add(It(30, "Prismatic Taper", ObjectClasses.SpellComponent, wcid: 7, stack: 10, max: 100));
|
||||
w3.Inv.Main.Items.Add(It(31, "Prismatic Taper", ObjectClasses.SpellComponent, wcid: 7, stack: 2, max: 100));
|
||||
SortController c3 = Controller();
|
||||
c3.Data.Rules = SortRules.Defaults();
|
||||
Ticks(c3, w3, 0, 3000);
|
||||
Check(w3.Sent.Count >= 1 && w3.Sent[0].MergeInto == 30, "joined the stack in pack 1");
|
||||
Eq(c3.PutBackCount, 0, "a join can't be put back");
|
||||
w3.Inv.Main.Items.Add(It(32, "Salvaged Iron", ObjectClasses.Salvage));
|
||||
Ticks(c3, w3, 3000, 6000);
|
||||
Eq(c3.PutBackCount, 1, "a plain move can");
|
||||
Ticks(c3, w3, 6000, 6000 + SortController.HistoryKeepMs + 2000);
|
||||
Eq(c3.PutBackCount, 0, "after half an hour it falls off");
|
||||
}
|
||||
|
||||
private static void PutBackPlan()
|
||||
{
|
||||
SortInventory inv = Inv(2, cap: 1, mainCap: 1);
|
||||
inv.Main.Items.Add(It(1, "Filler", ObjectClasses.Misc));
|
||||
inv.Packs[0].Items.Add(It(10, "Prismatic Taper", ObjectClasses.SpellComponent));
|
||||
inv.Packs[1].Items.Add(It(11, "Black Opal", ObjectClasses.Gem));
|
||||
var made = new List<MadeMove>
|
||||
{
|
||||
new(10, "Prismatic Taper", Me, 0x40000001, 0),
|
||||
new(11, "Black Opal", 0x4000AAAA, 0x40000002, 1),
|
||||
new(99, "Gone", Me, 0x40000001, 2),
|
||||
};
|
||||
var p = new SortPlanner();
|
||||
List<SortMove> moves = p.PlanPutBack(inv, made, 0);
|
||||
Eq(moves.Count, 0, "main pack full, the other's pack not carried, the third gone: nothing moves");
|
||||
Check(p.View.MainFull && p.View.WaitMainFull == 1 && p.View.WaitNoPack == 1, "and the view says why");
|
||||
|
||||
inv.Main.Capacity = 5;
|
||||
moves = p.PlanPutBack(inv, made, 0);
|
||||
Check(moves.Count == 1 && moves[0].Item.Id == 10 && moves[0].DestIndex == 0 && moves[0].MergeInto == 0 && moves[0].FromIndex == 1,
|
||||
"room now: the taper goes back as a stack of its own");
|
||||
Check(p.PlanUnpack(inv, null, 0).All(m => m.FromIndex > 0), "unpack moves say which pack they came from");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,8 @@ namespace RynthSort.Tests
|
|||
("on quiet", SortVerb.On, true, null), ("OFF Quiet", SortVerb.Off, true, null),
|
||||
("now", SortVerb.Now, false, null), ("tidy", SortVerb.Now, false, null), ("clean", SortVerb.Clean, false, null),
|
||||
("unpack", SortVerb.Unpack, false, null), ("unpack 2", SortVerb.Unpack, false, 2), ("unpack x", SortVerb.Unpack, false, null),
|
||||
("unpack 0", SortVerb.Unpack, false, null), ("status", SortVerb.Status, false, null), ("help", SortVerb.Help, false, null),
|
||||
("unpack 0", SortVerb.Unpack, false, null), ("back", SortVerb.Back, false, null), ("undo", SortVerb.Back, false, null), ("add 3", SortVerb.Add, false, 3), ("add", SortVerb.Add, false, null), ("add x", SortVerb.Add, false, null),
|
||||
("status", SortVerb.Status, false, null), ("help", SortVerb.Help, false, null),
|
||||
("?", SortVerb.Help, false, null), ("sortt", SortVerb.Unknown, false, null),
|
||||
};
|
||||
var seen = new HashSet<SortVerb>();
|
||||
|
|
@ -35,6 +36,8 @@ namespace RynthSort.Tests
|
|||
Check(SortCommand.Started(SortVerb.Clean).StartsWith("Cleaning", StringComparison.Ordinal), "clean");
|
||||
Check(SortCommand.Unpacking(3).StartsWith("Emptying pack 3", StringComparison.Ordinal), "unpack 3");
|
||||
Check(SortCommand.Unpacking(null).StartsWith("Emptying your side packs", StringComparison.Ordinal), "unpack");
|
||||
Check(SortCommand.PuttingBack(3).StartsWith("Putting back the 3 items", StringComparison.Ordinal) && SortCommand.PuttingBack(1).Contains("1 item the"), "back");
|
||||
Check(SortCommand.PuttingBack(0).StartsWith("Nothing to put back", StringComparison.Ordinal), "back with nothing to do");
|
||||
string unknown = SortCommand.Unknown("sortt");
|
||||
Check(unknown.StartsWith("Unknown '/rsort sortt'.", StringComparison.Ordinal) && unknown.Contains(SortCommand.Usage), "an unknown word: named, with the usage");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,9 +37,26 @@
|
|||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthSort\**\*.cs" Exclude="..\..\Plugins\RynthCore.Plugin.RynthSort\obj\**;..\..\Plugins\RynthCore.Plugin.RynthSort\bin\**" Link="RynthSort\%(RecursiveDir)%(Filename)%(Extension)" />
|
||||
<Compile Include="..\..\Plugins\Shared\RynthAiActivityApi.cs" Link="Shared\RynthAiActivityApi.cs" />
|
||||
<Compile Include="..\..\Plugins\Shared\RynthAiStatusApi.cs" Link="Shared\RynthAiStatusApi.cs" />
|
||||
<Compile Include="..\..\Plugins\Shared\RynthAiHubApi.cs" Link="Shared\RynthAiHubApi.cs" />
|
||||
<Compile Include="..\..\Plugins\Shared\RynthInstallPaths.cs" Link="Shared\RynthInstallPaths.cs" />
|
||||
<Compile Include="..\..\Plugins\Shared\CommandReply.cs" Link="Shared\CommandReply.cs" />
|
||||
<Compile Include="..\..\..\RynthCore\src\RynthCore.Engine\UI\ScriptWindows\DisplayListParser.cs" Link="Engine\DisplayListParser.cs" />
|
||||
<!-- The window drawn with ImGui (Window/*.cs) compiles here too; nothing native is called. -->
|
||||
<Compile Include="..\..\Plugins\Shared\ImGuiNativeBinding.cs" Link="Shared\ImGuiNativeBinding.cs" />
|
||||
<Compile Include="..\..\Plugins\Shared\SafeImGui.cs" Link="Shared\SafeImGui.cs" />
|
||||
<Compile Include="..\..\Plugins\Shared\RynthUi\RynthUi.cs" Link="Shared\RynthUi\RynthUi.cs" />
|
||||
<Compile Include="..\..\Plugins\Shared\RynthUi\RynthIcons.cs" Link="Shared\RynthUi\RynthIcons.cs" />
|
||||
<Compile Include="$(EngineParser)" Link="Engine\DisplayListParser.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--
|
||||
The engine parser the window's lists are checked against: the sibling RynthCore checkout's (op
|
||||
level 2, the released engine). To check the op level 3 lists (tables, fonts) against an engine
|
||||
that has them, point it at that engine's parser:
|
||||
dotnet run -c Release -p:EngineParser=<path>\DisplayListParser.cs
|
||||
(in that engine's src\RynthCore.Engine\UI\ScriptWindows\).
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<EngineParser Condition="'$(EngineParser)' == ''">..\..\..\RynthCore\src\RynthCore.Engine\UI\ScriptWindows\DisplayListParser.cs</EngineParser>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
227
Tools/RynthSort.Tests/ScreenTests.cs
Normal file
227
Tools/RynthSort.Tests/ScreenTests.cs
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthSort.Screen;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// The window drawn with ImGui (2026-11-26, the approved design for #rynth-issues "The bag sort
|
||||
// feature is lacking in UX"): its view-model (Screen/ScreenBuilder.cs), the rule changes it
|
||||
// makes (Screen/RuleEdits.cs), and what the controller does for it (an item sent to a pack,
|
||||
// the activity feed with times, settling items, items left alone and let go one at a time).
|
||||
internal static partial class Program
|
||||
{
|
||||
private static SortController ScreenController(SortInventory inv, bool auto = false)
|
||||
{
|
||||
var w = new FakeWorld { Inv = inv };
|
||||
SortController c = Controller(auto);
|
||||
c.WallClock = () => new DateTime(2026, 11, 26, 14, 5, 0);
|
||||
c.Tick(w, 0); // one read: the controller's last inventory and the planner's view
|
||||
return c;
|
||||
}
|
||||
|
||||
private static ScreenModel Screen(SortController c, bool layouts = false, ScreenSession? session = null) =>
|
||||
ScreenBuilder.Build(c, new ScreenInputs { Character = "Someone", Server = "Testworld", WantLayouts = layouts, Session = session, CanAddSelected = true });
|
||||
|
||||
private static void ScreenFeedAndSettling()
|
||||
{
|
||||
var w = new FakeWorld();
|
||||
SortController c = Controller(auto: false, settleSec: 30);
|
||||
int minute = 0;
|
||||
c.WallClock = () => new DateTime(2026, 11, 26, 23, minute, 0);
|
||||
c.Data.Rules = SortRules.Defaults();
|
||||
c.SetAuto(true);
|
||||
Check(c.Feed.Count == 1 && c.Feed[0].Text == "Auto-sort on" && c.Feed[0].Time == "23:00", "auto-sort on is in the feed, with the time");
|
||||
Eq(c.Log.Count, 0, "but not in the log /rsort status reads");
|
||||
c.SetAuto(true);
|
||||
Eq(c.Feed.Count, 1, "turning it on again adds nothing");
|
||||
minute = 7;
|
||||
w.Inv.Main.Items.Add(It(10, "Black Opal", ObjectClasses.Gem));
|
||||
Ticks(c, w, 0, 2000);
|
||||
Check(c.Planner.View.Settling.Contains(10) && c.Planner.View.WaitSettle == 1, "a new item settling is named in the view");
|
||||
ScreenModel m = Screen(c);
|
||||
Check(m.TilesById[10].Settling, "and its tile shows the ring");
|
||||
Check(m.Status.Tone == PillTone.Waiting && m.Status.Line.StartsWith("1 new item settling", StringComparison.Ordinal), $"the status says so ({m.Status.Line})");
|
||||
Ticks(c, w, 2000, 33_000);
|
||||
Check(w.Inv.Packs[2].Items.Any(i => i.Id == 10) && !c.Planner.View.Settling.Contains(10), "settled and moved");
|
||||
Check(c.Feed[0].ItemId == 10 && c.Feed[0].Time == "23:07", "the move is in the feed with its item and time");
|
||||
for (int i = 0; i < SortController.FeedMax + 5; i++) c.NoteFeed("line " + i);
|
||||
Eq(c.Feed.Count, SortController.FeedMax, "the feed keeps the last few");
|
||||
Eq(c.Feed[0].Text, "line " + (SortController.FeedMax + 4), "newest first");
|
||||
}
|
||||
|
||||
private static void ScreenModelPacks()
|
||||
{
|
||||
SortInventory inv = DesignPacks();
|
||||
SortController c = ScreenController(inv);
|
||||
c.Data.Rules = StarterLayouts.Fit(StarterLayouts.Everyday, inv).Rules;
|
||||
c.Data.Rules.Add(new SortRule { Pack = 3, PackId = inv.Packs[2].Id });
|
||||
c.Data.Rules[^1].AddName("Black Opal");
|
||||
c.Touch.Hold(inv.Main.Items[0].Id, c.Clock, TouchKind.Selected); // the Black Opal, selected in the game
|
||||
ScreenModel m = Screen(c);
|
||||
|
||||
Check(m.Ready && m.Who == "Someone · Testworld", "ready, and whose packs");
|
||||
Eq(m.Main.Count, "9 / 102", "main pack count");
|
||||
Check(m.Main.Wells == 9 && !m.Main.NearlyFull, "three rows of wells in all");
|
||||
Eq(m.Packs.Length, 4, "four side packs");
|
||||
PackModel sack = m.Packs[0], hide = m.Packs[3], satchel = m.Packs[2];
|
||||
Check(sack.Name == "Sack" && sack.Badge == "1" && sack.Where == "Top of your pack column", "the top pack");
|
||||
Check(m.Packs[1].Where == "Pack 2 from the top" && hide.Where == "Bottom of your pack column", "where the others sit");
|
||||
Eq(sack.Count, "3/24", "a pack's count");
|
||||
Check(sack.Ghosts.Length == 1 && sack.Incoming == "+1 coming", "the taper is coming to the Sack");
|
||||
Check(satchel.Ghosts.Length == 2 && satchel.Incoming == "+2 coming", "the mana stone and the key to the Satchel (the opal is left alone)");
|
||||
Check(hide.Incoming == "+1 coming" && hide.Chips.Select(x => x.Label).SequenceEqual(new[] { "Food", "Healing kits", "Lockpicks" }), "the Hide Sack's kinds, A-Z, and the kit coming");
|
||||
ChipModel name = satchel.Chips.Single(x => x.IsName);
|
||||
Check(name.Label == "named \"Black Opal\"" && name.Name == "Black Opal" && name.Pack == 3, "a name rule is its own chip");
|
||||
Check(satchel.Chips.Where(x => !x.IsName).Select(x => x.Label).SequenceEqual(new[] { "Gems", "Keys", "Mana stones" }), "the Satchel's kinds");
|
||||
|
||||
TileModel opal = m.TilesById[inv.Main.Items[0].Id];
|
||||
Check(opal.Held && opal.HeldWhy == "You selected it just now" && !opal.Outgoing, "the opal is left alone, so not in the moves");
|
||||
Check(opal.Rule == TileRule.Pack && opal.RulePack == 3 && opal.ByName && opal.RuleText == "named \"Black Opal\"", "and it goes by its name rule");
|
||||
TileModel taper = m.TilesById[inv.Main.Items[1].Id];
|
||||
Check(taper.Qty == "320" && taper.Outgoing && !taper.Moving && taper.KindLabel == "Spell components", "a stack's count; outgoing but nothing runs, so no lift");
|
||||
Eq(m.TilesById[inv.Main.Items[8].Id].Qty, "2.4k", "thousands");
|
||||
TileModel coat = m.TilesById[inv.Main.Items[6].Id];
|
||||
Check(coat.Rule == TileRule.None && !coat.Outgoing, "the coat has no rule: it stays");
|
||||
|
||||
Eq(m.MovesCount, 5, "taper, stone, steel, kit and key would move");
|
||||
RowModel first = m.Moves[0];
|
||||
Check(first.Name == "Prismatic Taper" && first.Sub == "Rule: Spell components" && first.Right == "Sack", $"a move row ({first.Name}, {first.Sub}, {first.Right})");
|
||||
Check(m.MovesHint.StartsWith("Nothing moves until", StringComparison.Ordinal), "auto-sort off: the hint");
|
||||
Check(m.Held.Length == 1 && m.Held[0].Sub == "You selected it just now · would go to Satchel", $"left alone, and where it would go ({m.Held[0].Sub})");
|
||||
Check(m.Status.Tone == PillTone.Off && m.Status.Pill == "Off" && m.Status.Line == "Nothing moves by itself. A sort would move 5 items. 1 left alone.", $"status ({m.Status.Line})");
|
||||
Check(m.HoldNote == "3 min" && m.Feed.Length == 0 && m.Orphans.Length == 0 && !m.NoRules, "the rest");
|
||||
Check(m.KindChoices.Single(k => k.Cls == ObjectClasses.Gem).InPack == 3 && m.KindChoices.Single(k => k.Cls == ObjectClasses.Scroll).InPack == 0,
|
||||
"the picker knows which pack has a kind");
|
||||
|
||||
// Why it is where it is.
|
||||
string Why(TileModel t) => string.Concat(ScreenText.Why(t, m).Select(r => r.Text));
|
||||
Eq(Why(opal), "Goes to Satchel by the rule named \"Black Opal\", once it's no longer left alone.", "why: held, would go");
|
||||
Eq(Why(coat), "No rule names it, so it stays in the main pack.", "why: no rule");
|
||||
TileModel garnet = m.Packs[2].Tiles.Single(t => t.Name == "Black Garnet");
|
||||
Eq(Why(garnet), "In its pack: Satchel, by the rule Gems.", "why: in its pack");
|
||||
Check(ScreenText.Why(garnet, m).Count(r => r.Bold) == 2, "the pack and the rule in bold");
|
||||
Eq(ScreenText.KindAndPlace(garnet, m), "Gems · in Satchel", "kind and place");
|
||||
Check(ScreenText.Matches(garnet, "garn") && !ScreenText.Matches(garnet, "opal") && !ScreenText.Matches(garnet, ""), "find an item: any case; empty finds nothing");
|
||||
|
||||
// Busy: the moves lift; tidy: the success pill; a pack nearly full turns amber.
|
||||
c.SetAuto(true);
|
||||
c.StartJob(SortScope.All);
|
||||
m = Screen(c);
|
||||
Check(m.Busy && m.Status.Tone == PillTone.Moving && m.TilesById[taper.Id].Moving, "a sort running: the taper lifts");
|
||||
var tidy = Inv(1);
|
||||
tidy.PackOrderKnown = true;
|
||||
tidy.Packs[0].Items.Add(It(1, "Fire Opal", ObjectClasses.Gem));
|
||||
for (uint i = 0; i < 21; i++) tidy.Packs[0].Items.Add(It(10 + i, "Black Garnet", ObjectClasses.Gem));
|
||||
SortController ct = ScreenController(tidy, auto: true);
|
||||
ct.Data.Rules = new List<SortRule> { SortRule.ForClass(ObjectClasses.Gem, 1) };
|
||||
ct.Tick(new FakeWorld { Inv = tidy }, 2000);
|
||||
ScreenModel mt = Screen(ct);
|
||||
Check(mt.Status.Tone == PillTone.Tidy && mt.Status.Pill == "All tidy" && mt.MovesCount == 0, $"all tidy ({mt.Status.Line})");
|
||||
Check(mt.Packs[0].NearlyFull && mt.Packs[0].Where == "Your only side pack", "22 of 24: amber");
|
||||
}
|
||||
|
||||
private static void ScreenModelOrphansAndLayouts()
|
||||
{
|
||||
SortInventory inv = DesignPacks();
|
||||
SortController c = ScreenController(inv);
|
||||
c.Data.Rules = new List<SortRule> { SortRule.ForClass(ObjectClasses.Scroll, 7) };
|
||||
ScreenModel m = Screen(c);
|
||||
Check(m.Orphans.Length == 1 && m.Orphans[0].Label == "Scrolls" && m.Orphans[0].Pack == 0, "a rule for a pack not carried");
|
||||
Check(m.KindChoices.Single(k => k.Cls == ObjectClasses.Scroll).InPack == -1, "the picker says its pack isn't carried");
|
||||
Eq(m.Layouts.Length, 0, "no layouts unless the popup is open");
|
||||
|
||||
m = Screen(c, layouts: true);
|
||||
Eq(m.Layouts.Length, StarterLayouts.All.Length, "every layout");
|
||||
LayoutCard every = m.Layouts[0];
|
||||
Check(every.Key == "everyday" && every.Bars.Length == 4 && every.Bars[3].Length == 3 && every.Bars[3][0] == Kinds.Kits, "the Hide Sack's bar: kits, lockpicks, food");
|
||||
Eq(every.Meta, "6 would move", "what Everyday would move (the opal too: nothing is held here)");
|
||||
Check(every.Rows[3].PackName == "Hide Sack" && every.Rows[3].Chips.Length == 3, "the preview rows");
|
||||
Check(every.Left.StartsWith("Stay in the main pack: ", StringComparison.Ordinal) && every.Left.Contains("trade notes") && every.Left.Contains("armor"),
|
||||
$"what stays in the main pack ({every.Left})");
|
||||
Check(every.Replaces.Length > 0, "it replaces the rules there are");
|
||||
LayoutCard basics = m.Layouts.Single(l => l.Key == "basics");
|
||||
Check(basics.Bars[3].Length == 0 && basics.Rows[3].Chips.Length == 0, "Just the basics leaves the Hide Sack free");
|
||||
|
||||
var none = ScreenBuilder.Build(c, new ScreenInputs());
|
||||
Check(!none.Ready && none.NotReady.StartsWith("Log in", StringComparison.Ordinal), "nobody logged in");
|
||||
Eq(ScreenBuilder.MainWells(0, 102), 18, "an empty main pack: three rows");
|
||||
Eq(ScreenBuilder.MainWells(20, 102), 4, "a row past the last item");
|
||||
Eq(ScreenBuilder.MainWells(101, 102), 1, "never past the capacity");
|
||||
Check(Kinds.Label(ObjectClasses.ManaStone) == "Mana stones" && Kinds.Label(ObjectClasses.MeleeWeapon) == "Melee weapons", "sentence-case kinds");
|
||||
Check(Kinds.Initials("Amuli Shadow Coat") == "AC" && Kinds.Qty(1) == "" && Kinds.Qty(12000) == "12k", "initials and counts");
|
||||
}
|
||||
|
||||
private static void ScreenRuleEdits()
|
||||
{
|
||||
SortInventory inv = DesignPacks();
|
||||
SortController c = ScreenController(inv);
|
||||
List<SortRule> rules = c.Data.Rules;
|
||||
rules.Clear();
|
||||
rules.AddRange(StarterLayouts.Fit(StarterLayouts.Everyday, inv).Rules);
|
||||
SortView view = SortPreview.Build(inv, rules, default, null).View;
|
||||
|
||||
// "All gems" dropped on the Hide Sack: gems leave the Satchel.
|
||||
EditResult r = RuleEdits.SendKind(rules, view, 4, ObjectClasses.Gem);
|
||||
Check(r.Changed && r.Text == "All gems now go to Hide Sack (taken from Satchel). Nothing has moved yet.", $"kind: {r.Text}");
|
||||
Check(rules.Count(x => x.HasClass(ObjectClasses.Gem)) == 1 && Views.SortPanelProxy.Shown(view, rules.First(x => x.HasClass(ObjectClasses.Gem))) == 4, "one pack has gems now");
|
||||
Check(RuleEdits.SendKind(rules, view, 4, ObjectClasses.Gem).Text == "Gems already go to Hide Sack.", "again: nothing changes");
|
||||
Check(!RuleEdits.SendKind(rules, view, 9, ObjectClasses.Gem).Changed, "a pack not carried");
|
||||
|
||||
// A kind sent to a pack with no rules: a new rule there.
|
||||
var empty = new List<SortRule>();
|
||||
RuleEdits.SendKind(empty, view, 2, ObjectClasses.Salvage);
|
||||
Check(empty.Count == 1 && empty[0].PackId == inv.Packs[1].Id && empty[0].HasClass(ObjectClasses.Salvage), "a new rule tied to the pack");
|
||||
|
||||
// "Only "Black Opal"" on the Backpack: a name rule; it leaves the Satchel's rules and beats the gems kind.
|
||||
rules.Add(new SortRule { Pack = 3, PackId = inv.Packs[2].Id });
|
||||
rules[^1].AddName("Black Opal");
|
||||
SortItem opal = inv.Main.Items[0];
|
||||
r = RuleEdits.SendName(rules, view, 2, opal);
|
||||
Check(r.Changed && r.Text == "\"Black Opal\" now goes to Backpack. Nothing has moved yet.", $"name: {r.Text}");
|
||||
Check(rules.Count(x => x.HasName("Black Opal")) == 1, "the name is in one pack's rules only (the Satchel's emptied rule went)");
|
||||
Eq(Views.SortPanelProxy.Shown(view, SortRules.RuleFor(rules, opal)!), 2, "the name beats the kind: the opal goes to the Backpack");
|
||||
Check(!RuleEdits.SendName(rules, view, 2, opal).Changed, "again: nothing changes");
|
||||
|
||||
// A chip's x.
|
||||
SortRule gemRule = rules.First(x => x.HasClass(ObjectClasses.Gem));
|
||||
bool alone = gemRule.Classes.Count == 1 && gemRule.Names.Count == 0;
|
||||
r = RuleEdits.RemoveEntry(rules, view, gemRule.Uid, false, ObjectClasses.Gem, "");
|
||||
Check(r.Changed && r.Text == "Gems no longer go to Hide Sack.", $"x: {r.Text}");
|
||||
Check(!rules.Any(x => x.HasClass(ObjectClasses.Gem)) && (!alone || !rules.Contains(gemRule)), "gone, and an emptied rule with it");
|
||||
Check(!RuleEdits.RemoveEntry(rules, view, 123456, false, 1, "").Changed, "a rule that's gone");
|
||||
SortRule off = SortRule.ForClass(ObjectClasses.Scroll, 1);
|
||||
off.On = false;
|
||||
rules.Add(off);
|
||||
Check(RuleEdits.TurnOn(rules, off.Uid).Changed && off.On && !RuleEdits.TurnOn(rules, off.Uid).Changed, "a faded chip turns its rule on");
|
||||
|
||||
// Toasts and the one Undo.
|
||||
var session = new ScreenSession();
|
||||
int before = rules.Count;
|
||||
string snapshot = string.Join("|", rules.Select(SortRules.Describe));
|
||||
Check(session.Edit(rules, l => RuleEdits.SendKind(l, view, 1, ObjectClasses.Plant), 1000), "a change");
|
||||
Check(session.Toast != null && session.Toast.CanUndo && session.Toast.UntilMs == 1000 + ScreenSession.ToastMs, "a toast with Undo");
|
||||
int seq = session.Toast!.Seq;
|
||||
Check(!session.Edit(rules, l => RuleEdits.SendKind(l, view, 1, ObjectClasses.Plant), 2000), "no change");
|
||||
Check(session.Toast != null && !session.Toast.CanUndo && session.Toast.Seq > seq && session.CanUndo, "says why, no Undo button, the Undo kept");
|
||||
Check(session.Undo(rules, 3000) && rules.Count == before && string.Join("|", rules.Select(SortRules.Describe)) == snapshot, "Undo puts the rules back");
|
||||
Check(!session.Undo(rules, 3000) && session.Toast!.Text == "Rules put back as they were.", "once");
|
||||
session.Expire(3000 + ScreenSession.ToastMs);
|
||||
Check(session.Toast == null, "the toast goes after its time");
|
||||
|
||||
r = RuleEdits.UseLayout(rules, inv, StarterLayouts.Basics);
|
||||
Check(r.Changed && rules.Count == 3 && r.Text.StartsWith("Rules set from Just the basics", StringComparison.Ordinal), "a layout replaces the rules");
|
||||
Check(!RuleEdits.UseLayout(rules, null, StarterLayouts.Basics).Changed && !RuleEdits.UseLayout(rules, Inv(0), StarterLayouts.Basics).Changed, "no packs read, or none carried");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace RynthSort.Tests.Views
|
||||
{
|
||||
internal static class SortPanelProxy
|
||||
{
|
||||
public static int Shown(RynthCore.Plugin.RynthSort.Sorting.SortView v, RynthCore.Plugin.RynthSort.Sorting.SortRule r) =>
|
||||
RynthCore.Plugin.RynthSort.Views.SortPanel.ShownPack(v, r);
|
||||
}
|
||||
}
|
||||
132
Tools/RynthSort.Tests/SendTests.cs
Normal file
132
Tools/RynthSort.Tests/SendTests.cs
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// What the controller does for the window drawn with ImGui (2026-11-26, the approved design for
|
||||
// #rynth-issues "The bag sort feature is lacking in UX"): a layout gives a pack the kind it
|
||||
// already holds before kinds no pack holds; one item left alone or let go; an item sent to a
|
||||
// pack from the window without a rule ("Just move it", "Send to"), then left alone.
|
||||
internal static partial class Program
|
||||
{
|
||||
/// <summary>The design's sample character: four packs, the main pack full of loot.</summary>
|
||||
private static SortInventory DesignPacks()
|
||||
{
|
||||
SortInventory inv = Inv(4);
|
||||
string[] names = { "Sack", "Backpack", "Satchel", "Hide Sack" };
|
||||
for (int i = 0; i < 4; i++) inv.Packs[i].Name = names[i];
|
||||
inv.PackOrderKnown = true;
|
||||
inv.OrderSource = PackOrderSource.Known;
|
||||
uint id = 100;
|
||||
void Main(string n, int cls, int stack = 1) => inv.Main.Items.Add(It(id++, n, cls, stack: stack, max: stack > 1 ? 5000 : 1));
|
||||
void In(int pack, string n, int cls, int stack = 1) => inv.Packs[pack].Items.Add(It(id++, n, cls, stack: stack, max: stack > 1 ? 5000 : 1));
|
||||
Main("Black Opal", ObjectClasses.Gem);
|
||||
Main("Prismatic Taper", ObjectClasses.SpellComponent, 320);
|
||||
Main("Mana Stone", ObjectClasses.ManaStone);
|
||||
Main("Salvaged Steel", ObjectClasses.Salvage);
|
||||
Main("Treated Healing Kit", ObjectClasses.HealingKit);
|
||||
Main("Trade Note (250,000)", ObjectClasses.TradeNote, 4);
|
||||
Main("Amuli Shadow Coat", ObjectClasses.Armor);
|
||||
Main("Legendary Key", ObjectClasses.Key);
|
||||
Main("Pyreal", ObjectClasses.Money, 2400);
|
||||
In(0, "Lead Scarab", ObjectClasses.SpellComponent, 40);
|
||||
In(0, "Hyssop", ObjectClasses.SpellComponent, 75);
|
||||
In(0, "Powdered Agate", ObjectClasses.SpellComponent, 60);
|
||||
In(1, "Salvaged Iron", ObjectClasses.Salvage);
|
||||
In(1, "Salvaged Granite", ObjectClasses.Salvage);
|
||||
In(2, "Fire Opal", ObjectClasses.Gem);
|
||||
In(2, "Black Garnet", ObjectClasses.Gem);
|
||||
In(3, "Health Elixir", ObjectClasses.Food, 6);
|
||||
In(3, "Peppermint Stick", ObjectClasses.Food, 20);
|
||||
In(3, "Intricate Lockpick", ObjectClasses.Lockpick);
|
||||
return inv;
|
||||
}
|
||||
|
||||
private static void LayoutHeldKindsFirst()
|
||||
{
|
||||
// The design's Everyday: the Hide Sack already holds kits, lockpicks and food, so it keeps them.
|
||||
SortInventory inv = DesignPacks();
|
||||
LayoutPlan plan = StarterLayouts.Fit(StarterLayouts.Everyday, inv);
|
||||
Eq(string.Join(",", plan.Placed.Select(x => x.Group.Key + x.Pack)), "components1,salvage2,gems3,supplies4",
|
||||
"each pack keeps the kind it holds; the Hide Sack gets kits, lockpicks and food");
|
||||
Eq(string.Join(",", plan.Left.Select(g => g.Key)), "notes,scrolls", "trade notes and scrolls (held by no pack) stay in the main pack");
|
||||
Eq(plan.AlreadyThere, 10, "the ten items in the side packs are already where their kind goes");
|
||||
|
||||
// A kind no pack holds still gets the roomiest pack left, most wanted first.
|
||||
SortInventory two = Inv(3);
|
||||
two.Packs[2].Items.Add(It(1, "Health Elixir", ObjectClasses.Food));
|
||||
LayoutPlan p2 = StarterLayouts.Fit(StarterLayouts.Everyday, two);
|
||||
Eq(string.Join(",", p2.Placed.Select(x => x.Group.Key + x.Pack)), "components1,gems2,supplies3",
|
||||
"the held kind (supplies, fifth in the list) wins its pack before salvage (third, held by none)");
|
||||
Eq(string.Join(",", p2.Left.Select(g => g.Key)), "salvage,notes,scrolls", "salvage waits for a pack");
|
||||
Check(StarterLayouts.Everyday.Blurb.Length <= 120, "the Everyday line still fits");
|
||||
}
|
||||
|
||||
private static void HoldOneItem()
|
||||
{
|
||||
var t = new TouchWatch();
|
||||
t.Hold(7, 1000, TouchKind.Chosen);
|
||||
Check(t.IsHeld(7, 2000, 60_000), "asked to leave it: held");
|
||||
Check(t.TryGetHeld(7, 2000, 60_000, out _, out TouchKind k) && k == TouchKind.Chosen && TouchWatch.Words(k) == "you asked to leave it", "and says why");
|
||||
Check(!t.IsHeld(7, 2000, 0), "the hold setting at 0 holds nothing");
|
||||
Check(t.Release(7) && !t.IsHeld(7, 2000, 60_000), "Let RynthSort move it: no longer held");
|
||||
Check(!t.Release(7), "releasing again does nothing");
|
||||
t.Hold(0, 1000, TouchKind.Sent);
|
||||
Eq(t.HeldCount(1000, 60_000), 0, "no item, no hold");
|
||||
}
|
||||
|
||||
private static void SendFromWindow()
|
||||
{
|
||||
var w = new FakeWorld();
|
||||
w.Inv.Main.Items.Add(It(10, "Black Opal", ObjectClasses.Gem));
|
||||
SortController c = Controller(auto: true);
|
||||
c.Data.Rules = SortRules.Defaults(); // gems go to pack 3
|
||||
c.WallClock = () => new DateTime(2026, 11, 26, 9, 30, 0);
|
||||
Check(c.StartSend(10, 0x40000001), "Just move it: to pack 1, no rule");
|
||||
Check(c.Send != null && c.IsHeld(10), "left alone from now, so auto-sort doesn't take it meanwhile");
|
||||
Ticks(c, w, 16, 3000);
|
||||
Check(w.Inv.Packs[0].Items.Any(i => i.Id == 10), "it went to pack 1");
|
||||
Check(w.Sent.Count == 1 && w.Sent[0].MergeInto == 0, "one plain move, and auto-sort didn't move it on to pack 3");
|
||||
Check(c.IsHeld(10) && c.Touch.TryGetHeld(10, c.Clock, c.HoldMs, out _, out TouchKind k) && k == TouchKind.Sent, "held as sent there");
|
||||
Eq(c.PutBackCount, 0, "not a sort: Put back leaves it");
|
||||
Check(c.Feed.Count > 0 && c.Feed[0].ItemId == 10 && c.Feed[0].Time == "09:30" && c.Feed[0].Text.Contains("you sent it"), $"the feed says so, with the time ({c.Feed[0].Text})");
|
||||
Check(c.Send == null && !c.HasMoveOut, "done");
|
||||
|
||||
// Waits while the way isn't clear, and is dropped after the wait.
|
||||
w.Gate = new GateInputs { Looting = true };
|
||||
c.StartSend(10, Me);
|
||||
Ticks(c, w, 3000, 5000);
|
||||
Check(w.Inv.Packs[0].Items.Any(i => i.Id == 10) && c.Paused && c.Send != null, "looting: it waits");
|
||||
w.Gate = default;
|
||||
Ticks(c, w, 5000, 8000);
|
||||
Check(w.Inv.Main.Items.Any(i => i.Id == 10), "the way clear: back to the main pack");
|
||||
|
||||
c.StartSend(10, 0x40000002);
|
||||
w.Gate = new GateInputs { Looting = true };
|
||||
Ticks(c, w, 8000, 8000 + SortController.SendWaitMs + 1000);
|
||||
Check(c.Send == null && w.Inv.Main.Items.Any(i => i.Id == 10), "too long: dropped, the item stays");
|
||||
Check(c.Log[0].StartsWith("A move you asked for was dropped", StringComparison.Ordinal), "and the log says so");
|
||||
|
||||
// An item that isn't in the packs, a pack that isn't carried, a full pack.
|
||||
w.Gate = default;
|
||||
long t0 = 8000 + SortController.SendWaitMs + 2000;
|
||||
c.StartSend(999, 0x40000001);
|
||||
Ticks(c, w, t0, t0 + 2000);
|
||||
Check(c.Log[0].Contains("isn't in your packs"), "an item gone: dropped");
|
||||
c.StartSend(10, 0x4000FFFF);
|
||||
Ticks(c, w, t0 + 2000, t0 + 4000);
|
||||
Check(c.Log[0].Contains("that pack isn't carried"), "a pack not carried: not moved");
|
||||
Check(!c.StartSend(0, 0x40000001) && !c.StartSend(10, 0), "no item or no pack: nothing starts");
|
||||
|
||||
var full = new FakeWorld { Inv = Inv(1, cap: 1) };
|
||||
full.Inv.Packs[0].Items.Add(It(1, "Filler", ObjectClasses.Misc));
|
||||
full.Inv.Main.Items.Add(It(2, "Black Opal", ObjectClasses.Gem));
|
||||
SortController cf = Controller(auto: false);
|
||||
cf.Tick(full, 0);
|
||||
cf.StartSend(2, 0x40000001);
|
||||
Ticks(cf, full, 16, 1000);
|
||||
Check(full.Sent.Count == 0 && cf.Log[0].Contains("is full"), "a full pack: not moved, and why");
|
||||
}
|
||||
}
|
||||
}
|
||||
62
Tools/RynthSort.Tests/WindowTests.cs
Normal file
62
Tools/RynthSort.Tests/WindowTests.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using RynthCore.Plugin.RynthSort;
|
||||
using RynthCore.Plugin.RynthSort.Screen;
|
||||
using RynthCore.Plugin.RynthSort.Sorting;
|
||||
|
||||
namespace RynthSort.Tests
|
||||
{
|
||||
// The window drawn with ImGui (2026-11-26): what the engine is told about it (the sections
|
||||
// manifest), and the pop-in of tiles that just arrived in another pack. Nothing native runs here.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void WindowManifest()
|
||||
{
|
||||
using JsonDocument doc = JsonDocument.Parse(RynthSortPlugin.Manifest);
|
||||
JsonElement root = doc.RootElement;
|
||||
Eq(root.GetProperty("version").GetInt32(), 1, "manifest version");
|
||||
JsonElement[] windows = root.GetProperty("windows").EnumerateArray().ToArray();
|
||||
Eq(windows.Length, 1, "one window");
|
||||
JsonElement w = windows[0];
|
||||
Check(w.GetProperty("title").GetString() == "RynthSort" && w.GetProperty("surface").GetString() == RynthSortPlugin.WindowSurface,
|
||||
"the RynthSort title (the old script window's, which it replaces) and its surface");
|
||||
Check(w.GetProperty("chrome").GetString() == "none" && w.GetProperty("scale").GetString() == "draw" && w.GetProperty("edgeToEdge").GetBoolean(),
|
||||
"frameless, drawn at its own size (Ctrl+wheel), edge to edge");
|
||||
Check(!w.TryGetProperty("fitHeight", out _), "players size it: not fitted to its content");
|
||||
Check(!w.GetProperty("bar").GetBoolean(), "no bar button (the Inventory's Sort button and /rsort open it, as before)");
|
||||
Check(w.GetProperty("minWidth").GetInt32() <= 360 && w.GetProperty("width").GetInt32() >= 1000, "it can be narrow (one column) and starts wide (three)");
|
||||
Check(w.GetProperty("icon").GetString()!.Length == 1, "one glyph for an icon");
|
||||
Eq(new RynthSortPlugin().SectionsJson(), "{\"version\":1}", "an engine without frameless windows is told of none (the script window stays)");
|
||||
}
|
||||
|
||||
private static void WindowArrivals()
|
||||
{
|
||||
SortInventory inv = DesignPacks();
|
||||
SortController c = ScreenController(inv);
|
||||
var a = new Arrivals();
|
||||
ScreenModel m1 = Screen(c);
|
||||
a.Update(m1, 10.0);
|
||||
uint taper = inv.Main.Items[1].Id;
|
||||
Eq(a.Progress(taper, 10.0), 1f, "the first view pops nothing in");
|
||||
|
||||
// The taper moves to the Sack: in the next view it has just arrived.
|
||||
SortItem item = inv.Main.Items[1];
|
||||
inv.Main.Items.Remove(item);
|
||||
inv.Packs[0].Items.Add(item);
|
||||
ScreenModel m2 = Screen(c);
|
||||
a.Update(m2, 20.0);
|
||||
Eq(a.Progress(taper, 20.0), 0f, "it arrived just now");
|
||||
Check(a.Progress(taper, 20.3) > 0.4f && a.Progress(taper, 20.3) < 0.6f, "half way through the pop-in");
|
||||
Eq(a.Progress(taper, 21.0), 1f, "and done after it");
|
||||
Eq(a.Progress(inv.Main.Items[0].Id, 20.0), 1f, "an item that stayed doesn't pop");
|
||||
a.Update(m2, 30.0);
|
||||
Eq(a.Progress(taper, 30.0), 1f, "the same view again changes nothing");
|
||||
|
||||
// Another character's view starts fresh.
|
||||
var other = new ScreenModel { Ready = true, Who = "Someone else", Version = m2.Version + 1000 };
|
||||
other.TilesById[taper] = new TileModel { Id = taper, Where = 3 };
|
||||
a.Update(other, 40.0);
|
||||
Eq(a.Progress(taper, 40.0), 1f, "another character: nothing pops");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue