From 4da9e954df3846d01aa0536f4e8143466a1d62f3 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 11 Feb 2022 00:49:49 -0500 Subject: use Array.Empty to avoid unneeded array allocations --- src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI.Web/Framework/LogParsing/Models') diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs b/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs index 87b20eb0..693a16ec 100644 --- a/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs +++ b/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs @@ -42,7 +42,7 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models public DateTimeOffset Timestamp { get; set; } /// Metadata about installed mods and content packs. - public LogModInfo[] Mods { get; set; } = new LogModInfo[0]; + public LogModInfo[] Mods { get; set; } = Array.Empty(); /// The log messages. public LogMessage[] Messages { get; set; } -- cgit From b0cc403098161ad82b858008e2523e1d2496fc41 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 12 Feb 2022 12:07:13 -0500 Subject: add data-* attributes to log parser for external tools --- docs/release-notes.md | 1 + .../Framework/LogParsing/Models/LogModInfo.cs | 3 ++ src/SMAPI.Web/ViewModels/LogParserModel.cs | 2 +- src/SMAPI.Web/Views/LogParser/Index.cshtml | 53 ++++++++++++++-------- 4 files changed, 38 insertions(+), 21 deletions(-) (limited to 'src/SMAPI.Web/Framework/LogParsing/Models') diff --git a/docs/release-notes.md b/docs/release-notes.md index 18187e49..5e004227 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -13,6 +13,7 @@ * Fixed `player_add` with Journal Scraps and Secret Notes. * For the web UI: + * Added `data-*` attributes to log parser page for external tools. * Fixed JSON validator warning for update keys without a subkey. ## 3.13.4 diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs b/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs index 067e4df4..92bfe5c7 100644 --- a/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs +++ b/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs @@ -35,5 +35,8 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models /// Whether the mod has an update available. public bool HasUpdate => this.UpdateVersion != null && this.Version != this.UpdateVersion; + + /// Whether the mod is a content pack for another mod. + public bool IsContentPack => !string.IsNullOrWhiteSpace(this.ContentPackFor); } } diff --git a/src/SMAPI.Web/ViewModels/LogParserModel.cs b/src/SMAPI.Web/ViewModels/LogParserModel.cs index bea79eae..0b6d7722 100644 --- a/src/SMAPI.Web/ViewModels/LogParserModel.cs +++ b/src/SMAPI.Web/ViewModels/LogParserModel.cs @@ -83,7 +83,7 @@ namespace StardewModdingAPI.Web.ViewModels // group by mod return mods - .Where(mod => mod.ContentPackFor != null) + .Where(mod => mod.IsContentPack) .GroupBy(mod => mod.ContentPackFor) .ToDictionary(group => group.Key, group => group.ToArray()); } diff --git a/src/SMAPI.Web/Views/LogParser/Index.cshtml b/src/SMAPI.Web/Views/LogParser/Index.cshtml index 993e7244..b54867b1 100644 --- a/src/SMAPI.Web/Views/LogParser/Index.cshtml +++ b/src/SMAPI.Web/Views/LogParser/Index.cshtml @@ -7,6 +7,9 @@ @{ ViewData["Title"] = "SMAPI log parser"; + + ParsedLog log = Model!.ParsedLog; + IDictionary contentPacks = Model.GetContentPacksByMod(); IDictionary defaultFilters = Enum .GetValues(typeof(LogLevel)) @@ -15,7 +18,7 @@ string curPageUrl = this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID }, absoluteUrl: true); - ISet screenIds = new HashSet(Model.ParsedLog?.Messages?.Select(p => p.ScreenId) ?? Array.Empty()); + ISet screenIds = new HashSet(log?.Messages?.Select(p => p.ScreenId) ?? Array.Empty()); } @section Head { @@ -35,9 +38,9 @@ } @@ -217,12 +213,12 @@ else if (log?.IsValid == true) Consider updating these mods to fix problems: - @foreach (LogModInfo mod in log.Mods.Where(mod => (mod.HasUpdate && !mod.IsContentPack) || (contentPacks.TryGetValue(mod.Name, out LogModInfo[] contentPackList) && contentPackList.Any(pack => pack.HasUpdate)))) + @foreach (LogModInfo mod in log.Mods.Where(mod => (mod.HasUpdate && !mod.IsContentPack) || (contentPacks.TryGetValue(mod.Name, out LogModInfo[]? contentPackList) && contentPackList.Any(pack => pack.HasUpdate)))) { -- cgit
@mod.Name - @if (contentPacks != null && contentPacks.TryGetValue(mod.Name, out LogModInfo[] contentPackList)) + @if (contentPacks != null && contentPacks.TryGetValue(mod.Name, out LogModInfo[]? contentPackList)) {
@foreach (LogModInfo contentPack in contentPackList.Where(pack => pack.HasUpdate)) @@ -305,8 +301,7 @@ else if (log?.IsValid == true) @foreach (var mod in log.Mods.Where(p => p.Loaded && !p.IsContentPack)) { - LogModInfo[]? contentPackList; - if (contentPacks == null || !contentPacks.TryGetValue(mod.Name, out contentPackList)) + if (contentPacks == null || !contentPacks.TryGetValue(mod.Name, out LogModInfo[]? contentPackList)) contentPackList = null;