Make some overall changes to utilities

This commit is contained in:
2026-10-26 22:09:36 +01:00
parent a4109f5be0
commit 881b61a66d
22 changed files with 376 additions and 790 deletions
+13 -5
View File
@@ -115,6 +115,7 @@ public class CampaignTests
for (int wave = 1; wave <= 12; wave++)
{
var plan = EncounterDirector.Plan(wave, WaveRoute.Repair, seed, 2);
Assert.That(plan.Title, Does.Not.Contain("/"));
Assert.That(plan.Enemies.All(id => EnemyArchetypeCatalog.Get(id).Id == id), Is.True);
Assert.That(plan.Enemies.Count(id => id == "race_condition") % 2, Is.Zero);
if (wave < 10) Assert.That(plan.Enemies, Does.Not.Contain("kernel_overseer"));
@@ -314,19 +315,26 @@ public class CampaignTests
Assert.That(_run.SelectRoute(WaveRoute.Challenge), Is.False, "No changing route during combat.");
}
[Test]
public void ChallengeChangesEncounterAndPaysOneRewardOnlyAfterClear()
[TestCase(false, 8)]
[TestCase(true, 16)]
public void ChallengeChangesEncounterAndPaysOneRewardOnlyAfterClear(bool allCardsHaveRiders, int expectedBits)
{
RepositoryAfter(1);
if (allCardsHaveRiders)
foreach (var card in _run.RunDeck) card.ApplyDrawRider(1);
int ridersBefore = _run.RunDeck.Sum(card => card.DrawRider);
_run.SelectRoute(WaveRoute.Challenge);
_run.PrepareNextEncounter(_combat.PlayerState);
Assert.That(_combat.PlayerState.CurrentUptime, Is.EqualTo(20));
Assert.That(EncounterDirector.Plan(2, _run.Journey.activeRoute).Enemies.Last(), Is.EqualTo("daemon"));
Assert.That(_run.RunDeck.Sum(card => card.DrawRider), Is.Zero);
Assert.That(_run.Bits, Is.Zero, "Selecting or entering an elite pays nothing.");
Assert.That(_run.RunDeck.Sum(card => card.DrawRider), Is.EqualTo(ridersBefore));
GameEvents.RaiseWaveCleared(new WaveClearedEvent(2));
GameEvents.RaiseWaveCleared(new WaveClearedEvent(2));
Assert.That(_run.Bits, Is.EqualTo(RunJourney.ChallengeBits));
Assert.That(_run.RunDeck.Sum(card => card.DrawRider), Is.EqualTo(1));
Assert.That(_run.Bits, Is.EqualTo(expectedBits));
Assert.That(_run.RunDeck.Sum(card => card.DrawRider), Is.EqualTo(ridersBefore + (allCardsHaveRiders ? 0 : 1)));
Assert.That(_run.Journey.lastReward, Does.Contain($"+{expectedBits} Bits"));
Assert.That(RunRouteMap.Detail(WaveRoute.Challenge), Does.Contain("+8 Bits").And.Contain("+8 more Bits"));
Assert.That(_run.CurrentWaveNumber, Is.EqualTo(3));
}
@@ -173,6 +173,52 @@ public class CombatLayoutTests
}
}
[UnityTest]
public IEnumerator HandFocusRevealsNameAndCostAndStillAllowsRulesScrolling()
{
bool testedOversizedCard = false;
foreach (var size in Viewports)
foreach (var textSize in new[] { UITextSize.Standard, UITextSize.Large })
{
UIPreferences.TextSize = textSize;
Resize(size);
Call(_view, "RefreshHand");
for (int frame = 0; frame < 5; frame++) yield return null;
var scroll = _root.Q<ScrollView>(className: "hand-scroll");
var faces = scroll.Query<Button>(className: "hand-card").ToList();
string context = $"{size}, {textSize}";
testedOversizedCard |= faces.Any(face => face.worldBound.height > scroll.contentViewport.worldBound.height);
scroll.scrollOffset = new Vector2(scroll.horizontalScroller.highValue, scroll.verticalScroller.highValue);
// Moving focus twice before layout must not restore a stale card's position.
faces[0].Focus();
faces[faces.Count - 1].Focus();
for (int frame = 0; frame < 3; frame++) yield return null;
foreach (var face in new[] { faces[faces.Count - 1], faces[0] })
{
face.Focus();
for (int frame = 0; frame < 3; frame++) yield return null;
foreach (string className in new[] { "software-name", "software-cost" })
{
var label = face.Q<Label>(className: className);
AssertContainedHorizontally(label, scroll.contentViewport, context);
Assert.That(label.worldBound.yMin, Is.GreaterThanOrEqualTo(scroll.contentViewport.worldBound.yMin - 1),
$"{context}; {className}; face={face.worldBound}; viewport={scroll.contentViewport.worldBound}; content={scroll.contentContainer.worldBound}; offset={scroll.scrollOffset}; focus={_root.focusController.focusedElement == face}");
Assert.That(label.worldBound.yMax, Is.LessThanOrEqualTo(scroll.contentViewport.worldBound.yMax + 1), context);
}
}
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);
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");
faces[0].Blur();
}
Assert.That(testedOversizedCard, Is.True, "Exercise at least one card taller than the hand viewport.");
}
[UnityTest]
public IEnumerator FirstBattleGuideAndReplayControlFitAcrossViewports()
{
@@ -315,6 +361,8 @@ public class CombatLayoutTests
for (int i = 0; i < 8; i++) yield return null;
var scroll = _root.Q<ScrollView>("RouteMapScroll");
var canvas = _root.Q("RouteCanvas");
Assert.That(_root.Q("RunMap").Query<Label>().ToList().Any(l => l.text.Contains("/")), Is.False,
"Route labels should not use decorative slash separators.");
Assert.That(scroll.worldBound.width, Is.GreaterThan(size.x * .55f));
Assert.That(scroll.worldBound.height, Is.GreaterThan(size.y * .5f));
Assert.That(canvas.Query(className: "route-map-wave").ToList().Count, Is.EqualTo(9));