using System.IO; using System.Text.Json; using AcDream.App.UI.Layout; namespace AcDream.App.Tests.UI.Layout; /// /// Loads the committed vitals ElementInfo fixture and builds the widget tree — /// no dats required. The fixture was generated from layout 0x2100006C /// via the real portal.dat and serialized with . /// public static class FixtureLoader { private static readonly JsonSerializerOptions _opts = new() { IncludeFields = true, }; /// /// Deserializes the committed vitals_2100006C.json fixture (copied to /// the test output directory via the csproj CopyToOutputDirectory item) /// into an tree, then builds and returns the /// using a null-returning sprite resolver and no /// dat font — sufficient for conformance checks on tree structure and slice ids. /// public static ImportedLayout LoadVitals() { var fixturePath = Path.Combine(AppContext.BaseDirectory, "UI", "Layout", "fixtures", "vitals_2100006C.json"); if (!File.Exists(fixturePath)) throw new FileNotFoundException($"Vitals fixture not found at: {fixturePath}"); var bytes = File.ReadAllBytes(fixturePath); // Strip UTF-8 BOM (EF BB BF) if present so JsonSerializer.Deserialize(ReadOnlySpan) // does not reject the first byte. ReadOnlySpan span = bytes; if (span.Length >= 3 && span[0] == 0xEF && span[1] == 0xBB && span[2] == 0xBF) span = span[3..]; var root = JsonSerializer.Deserialize(span, _opts) ?? throw new InvalidOperationException($"fixture deserialized to null: {fixturePath}"); return LayoutImporter.Build(root, _ => (0u, 0, 0), null); } }