Refactor alot of stuff

This commit is contained in:
2026-10-29 22:54:29 +01:00
parent c23b666ee4
commit 260abc2c98
138 changed files with 2835 additions and 466 deletions
+133 -11
View File
@@ -162,6 +162,39 @@ public class CombatLayoutTests
}
}
[UnityTest]
public IEnumerator UbuntuTurnChoiceSupportsTwoAndFourCardsAndKeyboardSelection()
{
var database = AssetDatabase.LoadAssetAtPath<CardDatabase>("Assets/Data/Cards/CardDatabase.asset");
var distro = AssetDatabase.LoadAssetAtPath<DistroDefinition>("Assets/Data/Distros/Ubuntu.asset");
foreach (int version in new[] { 1, 4 })
foreach (var size in new[] { new Vector2(1280, 720), new Vector2(390, 844) })
{
Resize(size);
_combat.Python.Clear();
_combat.HandController.Clear();
Set(_combat, "_runConfig", new RunConfig(distro, Language.Python, Language.JavaScript,
distro.ExclusiveCards.Take(4).ToArray(), 17, version));
var cards = Enumerable.Range(0, 4).Select(_ => new CardInstance(database.FindById("lang_py_print"))).ToArray();
_combat.DeckController.InitializeInDrawOrder(cards);
Call(_combat, "TryApplyUbuntuAptUpdate");
Call(_view, "RefreshOverlay");
for (int frame = 0; frame < 5; frame++) yield return null;
var buttons = _root.Query<Button>().ToList().Where(b => b.name?.StartsWith("PythonChoice") == true).ToList();
Assert.That(buttons.Count, Is.EqualTo(version == 1 ? 2 : 4));
var dialog = _root.Q("PythonChoiceDialog");
AssertContainedHorizontally(dialog, _root, size.ToString());
Assert.That(dialog.worldBound.yMin, Is.GreaterThanOrEqualTo(_root.worldBound.yMin - 1));
Assert.That(dialog.worldBound.yMax, Is.LessThanOrEqualTo(_root.worldBound.yMax + 1));
var selected = buttons.Last();
selected.Focus();
using (var submit = NavigationSubmitEvent.GetPooled()) selected.SendEvent(submit);
Assert.That(_combat.Python.HasChoice, Is.False);
Assert.That(_combat.HandController.Cards, Is.EqualTo(new[] { cards[buttons.Count - 1] }));
Call(_view, "RefreshOverlay");
}
}
[UnityTest]
public IEnumerator PythonChoicesFitViewportsAndResolveThroughAKeyboardSubmit()
{
@@ -268,11 +301,13 @@ public class CombatLayoutTests
Call(_view, "RefreshHand");
for (int frame = 0; frame < 3; frame++) yield return null;
Assert.That(_root.focusController.focusedElement, Is.SameAs(faces[0]), context);
scroll.scrollOffset = new Vector2(scroll.scrollOffset.x, scroll.verticalScroller.highValue);
scroll.scrollOffset = new Vector2(scroll.scrollOffset.x, Mathf.Max(0, scroll.verticalScroller.highValue));
float rulesOffset = scroll.scrollOffset.y;
for (int frame = 0; frame < 3; frame++) yield return null;
Assert.That(rulesOffset, Is.EqualTo(scroll.verticalScroller.highValue).Within(1), context);
Assert.That(scroll.scrollOffset.y, Is.EqualTo(rulesOffset).Within(1), context + ": focus must not pin scrolling");
// Removing empty UI rows can make the card fit entirely; UI Toolkit then clamps
// the offset to zero. A shrinking scroll range is not a focus-induced reset.
float expectedOffset = Mathf.Min(rulesOffset, Mathf.Max(0, scroll.verticalScroller.highValue));
Assert.That(scroll.scrollOffset.y, Is.EqualTo(expectedOffset).Within(1), context + ": focus must not pin scrolling");
faces[0].Blur();
}
}
@@ -597,7 +632,8 @@ public class CombatLayoutTests
Assert.That(_root.Q("RoutePreview").Query<Label>().ToList().Any(l => l.text == "Elite detour"), Is.True);
var boss = canvas.Q(className: "map-boss");
using (var hover = MouseEnterEvent.GetPooled()) { hover.target = boss; boss.SendEvent(hover); }
Assert.That(_root.Q("RoutePreview").Query<Label>().ToList().Any(l => l.text == "Kernel Overseer"), Is.True);
string bossId = EncounterDirector.Plan(_run.Journey.FinalWave, WaveRoute.Repair, _run.CurrentConfig.RunSeed, _run.Journey.encounterRevision).Enemies[0];
Assert.That(_root.Q("RoutePreview").Query<Label>().ToList().Any(l => l.text == EnemyArchetypeCatalog.Get(bossId).DisplayName), Is.True);
Assert.That(_run.Journey.selectedNodeId, Is.EqualTo(selected));
using (var submit = NavigationSubmitEvent.GetPooled()) { submit.target = elite; elite.SendEvent(submit); }
Assert.That(_run.Journey.selectedRoute, Is.EqualTo(WaveRoute.Challenge));
@@ -868,27 +904,69 @@ public class CombatLayoutTests
}
}
[UnityTest]
public IEnumerator PlanningActionsAndResultsDialogFitEveryViewport()
{
var view = typeof(CombatSceneController).GetField("_turnResolution", Private).GetValue(_view);
foreach (var size in Viewports)
foreach (var textSize in new[] { UITextSize.Standard, UITextSize.Large })
{
UIPreferences.TextSize = textSize;
Resize(size);
Call(_view, "RefreshTurnPanel");
for (int frame = 0; frame < 4; frame++) yield return null;
foreach (string name in new[] { "SaveCombatButton", "OpenTurnResolution" })
{
var control = _root.Q<Button>(name);
Assert.That(control.worldBound.height, Is.GreaterThan(20), name);
AssertContainedHorizontally(control, _root, name);
Assert.That(control.worldBound.yMin, Is.GreaterThanOrEqualTo(_root.worldBound.yMin - 1), name);
Assert.That(control.worldBound.yMax, Is.LessThanOrEqualTo(_root.worldBound.yMax + 1), name);
}
view.GetType().GetMethod("Open").Invoke(view, new object[] { _root });
for (int frame = 0; frame < 4; frame++) yield return null;
var popup = _root.Q("TurnResolutionPopup");
var dialog = popup.Q("TurnResolutionDialog");
AssertContainedHorizontally(dialog, _root, $"{size}/{textSize}");
Assert.That(dialog.worldBound.yMin, Is.GreaterThanOrEqualTo(_root.worldBound.yMin - 1));
Assert.That(dialog.worldBound.yMax, Is.LessThanOrEqualTo(_root.worldBound.yMax + 1));
Assert.That(popup.Q<ScrollView>().contentViewport.worldBound.height, Is.GreaterThan(80));
var close = popup.Q<Button>("CloseTurnResolution");
using (var endTurn = KeyDownEvent.GetPooled('e', KeyCode.E, EventModifiers.None))
{ endTurn.target = close; close.SendEvent(endTurn); }
Assert.That(_combat.CurrentPhase, Is.EqualTo(TurnPhase.Execute));
using (var escape = KeyDownEvent.GetPooled('\0', KeyCode.Escape, EventModifiers.None))
{ escape.target = close; close.SendEvent(escape); }
Assert.That(_root.Q("TurnResolutionPopup"), Is.Null);
Assert.That(_root.Q("ResolutionActions"), Is.Null, "Results must not occupy the battlefield after closing.");
Assert.That(_root.focusController.focusedElement, Is.SameAs(_root.Q<Button>("OpenTurnResolution")));
}
}
[UnityTest]
public IEnumerator ExecutionPreviewWrapsAndDoesNotDisplaceDispatchControls()
{
var preview = _root.Q<Foldout>("ExecutionPreview");
var preview = _root.Q<Button>("OpenExecutionPreview");
var view = typeof(CombatSceneController).GetField("_executionPreview", Private).GetValue(_view);
view.GetType().GetMethod("Refresh").Invoke(view, new object[] { _combat });
foreach (var size in Viewports)
foreach (var textSize in new[] { UITextSize.Standard, UITextSize.Large })
{
UIPreferences.TextSize = textSize;
preview.value = false;
Resize(size);
Call(_view, "RefreshTurnPanel");
for (int frame = 0; frame < 3; frame++) yield return null;
preview.value = true;
var before = _root.Q<ScrollView>(className: "combat-workspace").worldBound;
using (var submit = NavigationSubmitEvent.GetPooled()) { submit.target = preview; preview.SendEvent(submit); }
for (int frame = 0; frame < 5; frame++) yield return null;
var popup = _root.Q("ExecutionPreviewPopup");
var scroll = popup == null ? preview.Q<ScrollView>() : popup.Q<ScrollView>();
Assert.That(popup, Is.Not.Null, "Preview must always open as a dialog.");
var scroll = popup.Q<ScrollView>();
Assert.That(popup.Query(className: "execution-step").ToList().Count, Is.EqualTo(6));
var workspace = _root.Q<ScrollView>(className: "combat-workspace");
var visiblePreview = popup == null ? (VisualElement)preview : popup.Q("ExecutionPreviewDialog");
var availableArea = popup == null ? workspace.contentViewport : _root;
Assert.That(workspace.worldBound, Is.EqualTo(before), "Opening the preview must not shift the battlefield.");
var visiblePreview = popup.Q("ExecutionPreviewDialog");
var availableArea = _root;
Assert.That(visiblePreview.worldBound.yMin, Is.GreaterThanOrEqualTo(availableArea.worldBound.yMin - 1));
Assert.That(visiblePreview.worldBound.yMax, Is.LessThanOrEqualTo(availableArea.worldBound.yMax + 1));
foreach (var label in scroll.Query<Label>(className: "terminal-body").ToList())
@@ -904,7 +982,8 @@ public class CombatLayoutTests
using (var escape = KeyDownEvent.GetPooled('\0', KeyCode.Escape, EventModifiers.None))
{ escape.target = close; close.SendEvent(escape); }
Assert.That(_root.Q("ExecutionPreviewPopup"), Is.Null);
Assert.That(preview.value, Is.False);
Assert.That(_root.Q("ExecutionPreviewSteps"), Is.Null);
Assert.That(_root.focusController.focusedElement, Is.SameAs(preview));
}
}
}
@@ -1159,6 +1238,47 @@ public class CombatLayoutTests
Assert.That(chip.tooltip, Does.Contain("Haskell captured: x1.75"));
}
[UnityTest]
public IEnumerator MintPackageStatusAndNotificationsStayInsideCompactRows()
{
var packages = AssetDatabase.LoadAssetAtPath<PackageDatabase>("Assets/Data/Packages/PackageDatabase.asset");
var mint = AssetDatabase.LoadAssetAtPath<DistroDefinition>("Assets/Data/Distros/Mint.asset");
Set(_combat, "_runConfig", new RunConfig(mint, Language.Python, Language.JavaScript,
mint.ExclusiveCards.Take(4).ToArray(), new[] { "pkg_mint_timeshift", "pkg_mint_cinnamon", "pkg_auditd" }
.Select(id => new PackageInstance(packages.FindById(id), 5)).ToArray(), 17, 5));
var activation = _root.Q<Label>("PackageActivation");
Assert.That(activation.style.display.value, Is.EqualTo(DisplayStyle.None));
foreach (var size in Viewports)
foreach (var textSize in new[] { UITextSize.Standard, UITextSize.Large })
{
UIPreferences.TextSize = textSize;
Resize(size);
Call(_view, "RefreshPackageReadiness");
for (int frame = 0; frame < 5; frame++) yield return null;
string context = $"{size}/{textSize}";
var strip = _root.Q("PackageReadiness");
Assert.That(_root.Q(className: "player-panel").Contains(strip), Is.True, "Packages belong with the host.");
foreach (var chip in strip.Query(className: "package-readiness-chip").ToList())
{
AssertContainedHorizontally(chip, strip, context);
Assert.That(chip.worldBound.height, Is.LessThan(70), context);
foreach (var label in chip.Query<Label>().ToList())
{
AssertContainedHorizontally(label, chip, context);
Assert.That(label.worldBound.yMin, Is.GreaterThanOrEqualTo(chip.worldBound.yMin), context);
Assert.That(label.worldBound.yMax, Is.LessThanOrEqualTo(chip.worldBound.yMax), context);
}
Assert.That(chip.tooltip, Does.Contain(chip.Q<Label>(className: "package-readiness-state").text));
}
Call(_view, "HandlePackageActivated", new PackageActivation("pkg_mint_timeshift", "Timeshift", "Full recovery notification with enough detail to overflow a narrow screen if it wraps"));
Call(_view, "HandlePackageActivated", new PackageActivation("pkg_mint_cinnamon", "Cinnamon", "JavaScript damage increased for this round"));
for (int frame = 0; frame < 3; frame++) yield return null;
AssertContainedHorizontally(activation, strip.parent, context);
Assert.That(activation.worldBound.height, Is.LessThan(30), context);
Assert.That(activation.tooltip, Is.EqualTo(activation.text));
}
}
[UnityTest]
public IEnumerator LivePreviewsAndPackageReadinessWrapAndRetainKeyboardFocus()
{
@@ -1194,6 +1314,8 @@ public class CombatLayoutTests
ccache.Focus();
Call(_view, "RefreshPackageReadiness");
Assert.That(_root.focusController.focusedElement, Is.SameAs(ccache), context);
Call(_view, "RefreshPlayer");
Assert.That(_root.Q("PackageReadiness"), Is.SameAs(strip), "Refreshing host stats must retain installed packages.");
foreach (var face in _root.Query(className: "hand-card").ToList())
{
var preview = face.Q<Label>(className: "software-live-preview");