using System;
using System.Collections;
using System.Linq;
using Luneraria.Core;
using Luneraria.View;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
namespace Luneraria.UI.Tests
{
///
/// S3 in the real scene: camp guardians on the lanes in a camp round, the team panel's ward
/// and camp rows, a ward that brings the enemy army of its lane into the planning preview,
/// and the fog of war that hides enemy figures nobody of the own team sees. S3Bilder
/// (explicit) captures them at 1920×1080; LUNE_EVIDENCE names the folder below
/// docs/port/screenshots (default s3/spiel).
///
public sealed class S3RulesViewsTests
{
static void Send(HudSession s, Command command)
{
CommandResult result = s.Match.Submit(HudSession.Human, command);
Assert.IsTrue(result.Ok, command.Type + ": " + result.Message);
s.Game.RebuildPreview();
s.Sync();
}
static IEnumerator WaitReady(HudSession s)
{
float waited = 0f;
while (s.Hud.ReadyBlocked() && waited < 5f)
{
waited += Time.unscaledDeltaTime;
yield return null;
}
}
static LuneUnitView[] Views(HudSession s)
{
return UnityEngine.Object.FindObjectsByType(FindObjectsInactive.Include, FindObjectsSortMode.None);
}
[UnityTest, Timeout(600000)]
public IEnumerator S3Hud()
{
var s = new HudSession();
yield return s.Open(1920, 1080, seed: 4, startRound: 3, extraGold: 1000, extended: true);
Assert.IsTrue(s.Match.CampRound(3), "round 3 is a camp round");
StringAssert.Contains("diese Runde", s.Hud.Team.CampState.text, "the team panel announces the guardians");
Assert.IsTrue(HudSession.Visible(s.Hud.Lanes["mid"].CampMark), "the lane shows the camp mark");
yield return s.Starter();
s.Leave();
s.Game.Key(KeyCode.Space);
yield return HudSession.Frames(3);
Assert.AreEqual(3, s.Match.Combat.Units.Count(u => u.Kind == "camp"), "three guardians in combat");
yield return HudSession.Frames(2);
Assert.IsTrue(Views(s).Any(v => v.Unit != null && v.Unit.Kind == "camp" && v.gameObject.activeSelf), "guardians have visible figures");
Assert.IsTrue(s.Game.View.Hidden.Count > 0, "the fog hides Rot's distant units at the start");
LuneUnitView hiddenView = Views(s).First(v => v.Unit != null && s.Game.View.Hidden.Contains(v.Unit.Id));
Assert.IsFalse(hiddenView.gameObject.activeSelf, "a hidden enemy has no visible figure");
Assert.AreEqual(1, hiddenView.Unit.Team, "only enemies are hidden");
yield return s.FinishCombat();
yield return WaitReady(s);
Assert.IsTrue(s.Match.Players.Skip(3).Any(p => p.Roster.Count > 0), "Rot has a committed army now");
int enemiesBefore = s.Game.View.Preview.Units.Count(u => u.Team == 1);
Assert.AreEqual(0, enemiesBefore, "without scouting the preview shows no enemy");
Send(s, Command.Ward("mid"));
yield return HudSession.Frames(2);
Assert.IsTrue(s.Hud.Team.WardButtons["mid"].On, "the mid ward button shows the ward");
Assert.IsTrue(s.Game.View.Preview.Units.Any(u => u.Team == 1 && u.Lane == "mid"), "the ward shows Rot's mid army in the preview");
Assert.IsFalse(s.Game.View.Preview.Units.Any(u => u.Team == 1 && u.Lane == "top"), "top stays unscouted");
s.Close();
}
[UnityTest, Timeout(600000), Explicit("Bildwerkzeug: nur gezielt per -testFilter")]
public IEnumerator S3Bilder()
{
string evidence = Environment.GetEnvironmentVariable("LUNE_EVIDENCE");
string folder = "docs/port/screenshots/" + (string.IsNullOrEmpty(evidence) ? "s3/spiel" : evidence) + "/";
var s = new HudSession();
yield return s.Open(1920, 1080, seed: 4, startRound: 3, extraGold: 1000, extended: true);
yield return s.Starter();
s.Leave();
yield return new WaitForSecondsRealtime(.4f);
yield return s.Shot(folder + "01-planung-lager-angekuendigt.png");
s.Game.Key(KeyCode.Space);
yield return HudSession.Frames(2);
yield return s.Fight(7.0);
s.Driver.Paused = true;
LuneUnit camp = s.Match.Combat.Units.Where(u => u.Kind == "camp" && u.Lane == "mid").First();
s.Rig.LookAt(camp.Position, 14f, true);
yield return new WaitForSecondsRealtime(.5f);
yield return s.Shot(folder + "02-kampf-um-das-mondlager.png");
s.Rig.LookAt(camp.Position, 40f, true);
yield return new WaitForSecondsRealtime(.5f);
yield return s.Shot(folder + "03-nebel-im-kampf.png");
s.Driver.Paused = false;
yield return s.FinishCombat();
yield return WaitReady(s);
Send(s, Command.Ward("mid"));
LuneUnit enemy = s.Game.View.Preview.Units.FirstOrDefault(u => u.Team == 1 && u.Lane == "mid");
if (enemy != null)
s.Rig.LookAt(enemy.Position, 18f, true);
yield return new WaitForSecondsRealtime(.6f);
yield return s.Shot(folder + "04-spaeher-zeigt-gegnerische-aufstellung.png");
s.Hover(s.Hud.Team.WardButtons["mid"]);
yield return new WaitForSecondsRealtime(.3f);
yield return s.Shot(folder + "05-spaeher-tooltip.png");
s.Close();
}
}
}