using System.Text; namespace OECS.PlayTest; /// /// Builds a sectioned play log with header, sections, and final snapshot, /// then saves it to a .playlog file. /// public class PlayLog { public string Header { get; set; } = ""; public string FinalSnapshot { get; set; } = ""; private readonly List<(string Title, List Lines)> _sections = new(); /// /// Adds a section with the given title and lines. /// public void AddSection(string title, IEnumerable lines) { _sections.Add((title, lines.ToList())); } /// /// Builds the complete play log text. /// public string Build() { var sb = new StringBuilder(); sb.AppendLine(Header); sb.AppendLine(new string('=', Header.Length)); sb.AppendLine(); foreach (var (title, lines) in _sections) { sb.AppendLine($"--- {title} ---"); foreach (var line in lines) sb.AppendLine($" {line}"); sb.AppendLine(); } sb.AppendLine("--- Final State ---"); sb.AppendLine(FinalSnapshot); return sb.ToString(); } /// /// Saves the play log to AppContext.BaseDirectory/playlogs/ /// and returns the full path. /// public string SaveTo(string filename) { var dir = Path.Combine(AppContext.BaseDirectory, "playlogs"); Directory.CreateDirectory(dir); var path = Path.Combine(dir, filename); File.WriteAllText(path, Build()); return path; } }