From 27bcc0d40a08a0bbdf7514217166fd4d4c2b7729 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 27 Jan 2022 10:58:40 -0800 Subject: [PATCH] Better helper method organization --- CHANGELIST.md | 1 + MPF.Library/InfoTool.cs | 116 ++++++++++++++++++++++++---------------- 2 files changed, 70 insertions(+), 47 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 22f037c9..96bf200e 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -55,6 +55,7 @@ - Add support for all ISO region codes - Ensure ordering in output site tags - Make site code formatting helper method +- Better helper method organization ### 2.2 (2021-12-30) - Fix Saturn header finding diff --git a/MPF.Library/InfoTool.cs b/MPF.Library/InfoTool.cs index bd092b8f..5101d7a0 100644 --- a/MPF.Library/InfoTool.cs +++ b/MPF.Library/InfoTool.cs @@ -1060,28 +1060,6 @@ namespace MPF.Library AddIfExists(output, key, string.Join(", ", value.Select(o => o.ToString())), indent); } - /// - /// Format a single site tag to string - /// - /// KeyValuePair representing the site tag and value - /// String-formatted tag and value - private static string FormatSiteTag(KeyValuePair kvp) - { - bool isMultiLine = IsMultiLine(kvp.Key); - string line = $"{kvp.Key.ShortName()}{(isMultiLine ? "\n" : " ")}"; - - // Special case for boolean fields - if (kvp.Key == SiteCode.PostgapType || kvp.Key == SiteCode.VCD) - { - if (kvp.Value != true.ToString()) - return string.Empty; - - return line.Trim(); - } - - return $"{line}{kvp.Value}{(isMultiLine ? "\n" : string.Empty)}"; - } - #endregion #region Normalization @@ -1700,31 +1678,6 @@ namespace MPF.Library } } - /// - /// Check if a site code is multi-line or not - /// - /// SiteCode to check - /// True if the code field is multiline by default, false otherwise - /// TODO: This should move to Extensions at some point - private static bool IsMultiLine(SiteCode? siteCode) - { - switch (siteCode) - { - case SiteCode.Extras: - case SiteCode.GameFootage: - case SiteCode.NetYarozeGames: - case SiteCode.Patches: - case SiteCode.PlayableDemos: - case SiteCode.RollingDemos: - case SiteCode.Savegames: - case SiteCode.TechDemos: - case SiteCode.Videos: - return true; - default: - return false; - } - } - /// /// Process a text block and replace with internal identifiers /// @@ -1854,5 +1807,74 @@ namespace MPF.Library } #endregion + + #region Helpers + + /// + /// Format a single site tag to string + /// + /// KeyValuePair representing the site tag and value + /// String-formatted tag and value + private static string FormatSiteTag(KeyValuePair kvp) + { + bool isMultiLine = IsMultiLine(kvp.Key); + string line = $"{kvp.Key.ShortName()}{(isMultiLine ? "\n" : " ")}"; + + // Special case for boolean fields + if (IsBoolean(kvp.Key)) + { + if (kvp.Value != true.ToString()) + return string.Empty; + + return line.Trim(); + } + + return $"{line}{kvp.Value}{(isMultiLine ? "\n" : string.Empty)}"; + } + + /// + /// Check if a site code is boolean or not + /// + /// SiteCode to check + /// True if the code field is a flag with no value, false otherwise + /// TODO: This should move to Extensions at some point + private static bool IsBoolean(SiteCode? siteCode) + { + switch (siteCode) + { + case SiteCode.PostgapType: + case SiteCode.VCD: + return true; + default: + return false; + } + } + + /// + /// Check if a site code is multi-line or not + /// + /// SiteCode to check + /// True if the code field is multiline by default, false otherwise + /// TODO: This should move to Extensions at some point + private static bool IsMultiLine(SiteCode? siteCode) + { + switch (siteCode) + { + case SiteCode.Extras: + case SiteCode.GameFootage: + case SiteCode.NetYarozeGames: + case SiteCode.Patches: + case SiteCode.PlayableDemos: + case SiteCode.RollingDemos: + case SiteCode.Savegames: + case SiteCode.TechDemos: + case SiteCode.Videos: + return true; + default: + return false; + } + } + + #endregion } }