using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
namespace Luneraria.Core.Tests
{
///
/// Visual evidence for U1: the map with lanes and buildings, the Godot reference positions of
/// every unit of a golden snapshot as filled dots (Blau blue, Rot red, grotto violet) and the
/// C# positions of the same snapshot as white rings. Identical positions show as ringed dots.
/// Usage: Luneraria.Core.Tests.dll --image <scenario> <label> <out.png>
///
public static class ReplayImage
{
const int Size = 1100;
public static int Write(string golden, string scenarioId, string label, string outPath)
{
var spec = MiniJson.Obj(MiniJson.Parse(File.ReadAllText(Path.Combine(golden, "scenarios.json"))));
var scenario = MiniJson.Arr(spec["scenarios"]).Select(MiniJson.Obj).First(s => MiniJson.Str(s["id"]) == scenarioId);
var replay = new GoldenReplay();
foreach (object op in MiniJson.Arr(scenario["ops"]))
replay.Apply(MiniJson.Obj(op));
var reference = MiniJson.Obj(MiniJson.Obj(MiniJson.Obj(MiniJson.Parse(File.ReadAllText(Path.Combine(golden, "golden.json"))))["scenarios"])[scenarioId]);
var expected = MiniJson.Arr(reference["snapshots"]).Select(MiniJson.Obj).First(s => MiniJson.Str(s["label"]) == label);
var actual = replay.Snapshots.Select(o => (OrderedMap)o).First(s => MiniJson.Str(s["label"]) == label);
var pixels = new byte[Size * Size * 3];
Fill(pixels, 12, 16, 20);
LuneMap map = replay.State.Map;
foreach (LanePath path in map.LanePaths.Values)
{
for (int i = 1; i < path.Points.Length; i++)
Line(pixels, path.Points[i - 1], path.Points[i], 110, 100, 80);
}
foreach (BuildingDef building in map.Buildings)
Square(pixels, building.Position, building.Tier == "core" ? 9 : 6, building.Team == 0 ? (byte)70 : (byte)200, 90, building.Team == 0 ? (byte)200 : (byte)70);
int same = 0;
int total = 0;
List