From 0642f64103ff19dfbce2ae02d1779eb574884770 Mon Sep 17 00:00:00 2001 From: Darkmajia Date: Wed, 4 Dec 2024 11:55:47 +0000 Subject: [PATCH] multiple changelogs --- Content.Client/Changelog/ChangelogManager.cs | 42 +++++++++++-------- Content.Client/Changelog/ChangelogTab.xaml.cs | 7 ++-- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/Content.Client/Changelog/ChangelogManager.cs b/Content.Client/Changelog/ChangelogManager.cs index 4383f4661795..5427b17fa484 100644 --- a/Content.Client/Changelog/ChangelogManager.cs +++ b/Content.Client/Changelog/ChangelogManager.cs @@ -23,8 +23,8 @@ public sealed partial class ChangelogManager : IPostInjectInit private ISawmill _sawmill = default!; public bool NewChangelogEntries { get; private set; } - public int LastReadId { get; private set; } - public int MaxId { get; private set; } + public Dictionary LastReadId { get; private set; } = new Dictionary(); + public Dictionary MaxId { get; private set; } = new Dictionary(); public event Action? NewChangelogEntriesChanged; @@ -36,14 +36,18 @@ public sealed partial class ChangelogManager : IPostInjectInit /// is NOT cleared /// since that's used in the changelog menu to show the "since you last read" bar. /// - public void SaveNewReadId() + public async void SaveNewReadId() { NewChangelogEntries = false; NewChangelogEntriesChanged?.Invoke(); - using var sw = _resource.UserData.OpenWriteText(new ($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}")); + var changelogs = await LoadChangelog(); - sw.Write(MaxId.ToString()); + foreach (var changelog in changelogs) + { + using var sw = _resource.UserData.OpenWriteText(new($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}_{changelog.Name}")); + sw.Write(MaxId[changelog.Name].ToString()); + } } public async void Initialize() @@ -67,26 +71,30 @@ private void UpdateChangelogs(List changelogs) return; } - var changelog = changelogs[0]; if (mainChangelogs.Length > 1) - { _sawmill.Error($"More than one file found in Resource/Changelog with name {MainChangelogName}"); - } - if (changelog.Entries.Count == 0) - { + if (changelogs[0].Entries.Count == 0) return; - } - MaxId = changelog.Entries.Max(c => c.Id); + NewChangelogEntries = false; - var path = new ResPath($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}"); - if (_resource.UserData.TryReadAllText(path, out var lastReadIdText)) + foreach (var changelog in changelogs) { - LastReadId = int.Parse(lastReadIdText); - } + var name = changelog.Name; - NewChangelogEntries = LastReadId < MaxId; + MaxId.Add(name, changelog.Entries.Max(c => c.Id)); + LastReadId.Add(name, 0); + + var path = new ResPath($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}_{name}"); + if (_resource.UserData.TryReadAllText(path, out var lastReadIdText)) + { + LastReadId[name] = int.Parse(lastReadIdText); + } + + if (!changelog.AdminOnly) + NewChangelogEntries = NewChangelogEntries || LastReadId[name] < MaxId[name]; + } NewChangelogEntriesChanged?.Invoke(); } diff --git a/Content.Client/Changelog/ChangelogTab.xaml.cs b/Content.Client/Changelog/ChangelogTab.xaml.cs index ca86f8a6b2e4..bdf2ac79bb5f 100644 --- a/Content.Client/Changelog/ChangelogTab.xaml.cs +++ b/Content.Client/Changelog/ChangelogTab.xaml.cs @@ -30,19 +30,20 @@ public ChangelogTab() public void PopulateChangelog(ChangelogManager.Changelog changelog) { + var name = changelog.Name; + var byDay = changelog.Entries .GroupBy(e => e.Time.ToLocalTime().Date) .OrderByDescending(c => c.Key); - var hasRead = changelog.Name != MainChangelogName || - _changelog.MaxId <= _changelog.LastReadId; + var hasRead = _changelog.MaxId[name] <= _changelog.LastReadId[name]; foreach (var dayEntries in byDay) { var day = dayEntries.Key; var groupedEntries = dayEntries - .GroupBy(c => (c.Author, Read: c.Id <= _changelog.LastReadId)) + .GroupBy(c => (c.Author, Read: c.Id <= _changelog.LastReadId[name])) .OrderBy(c => c.Key.Read) .ThenBy(c => c.Key.Author);