From 4337328709136c4d8e8e1693d66e5b3912fe778e Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 29 Feb 2020 13:48:23 -0600 Subject: [PATCH] simplify more --- BizHawk.Client.Common/cheats/IDecodeResult.cs | 8 ++++++++ BizHawk.Client.Common/cheats/NesGameGenieDecoder.cs | 2 +- BizHawk.Client.EmuHawk/tools/GameShark.cs | 7 +------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/BizHawk.Client.Common/cheats/IDecodeResult.cs b/BizHawk.Client.Common/cheats/IDecodeResult.cs index ee195b4202..e4c5250513 100644 --- a/BizHawk.Client.Common/cheats/IDecodeResult.cs +++ b/BizHawk.Client.Common/cheats/IDecodeResult.cs @@ -12,6 +12,7 @@ namespace BizHawk.Client.Common.cheats int? Compare { get; } WatchSize Size { get; } bool IsValid { get; } + string Error { get; } } public class DecodeResult : IDecodeResult @@ -21,15 +22,22 @@ namespace BizHawk.Client.Common.cheats public int? Compare { get; internal set; } public WatchSize Size { get; internal set; } public bool IsValid => true; + public string Error => ""; } public class InvalidResult : IDecodeResult { + public InvalidResult(string error) + { + Error = error; + } + public int Address => int.MaxValue; public int Value => int.MaxValue; public int? Compare => null; public WatchSize Size => WatchSize.Separator; public bool IsValid => false; + public string Error { get; } } public static class DecodeResultExtensions diff --git a/BizHawk.Client.Common/cheats/NesGameGenieDecoder.cs b/BizHawk.Client.Common/cheats/NesGameGenieDecoder.cs index e65686ed08..106540b08a 100644 --- a/BizHawk.Client.Common/cheats/NesGameGenieDecoder.cs +++ b/BizHawk.Client.Common/cheats/NesGameGenieDecoder.cs @@ -34,7 +34,7 @@ namespace BizHawk.Client.Common.cheats if (code.Length != 6 && code.Length != 8) { - return new InvalidResult(); + return new InvalidResult("Game Genie codes need to be six or eight characters in length."); } var result = new DecodeResult { Size = WatchSize.Byte }; diff --git a/BizHawk.Client.EmuHawk/tools/GameShark.cs b/BizHawk.Client.EmuHawk/tools/GameShark.cs index c835b4c193..e93295e88b 100644 --- a/BizHawk.Client.EmuHawk/tools/GameShark.cs +++ b/BizHawk.Client.EmuHawk/tools/GameShark.cs @@ -279,11 +279,6 @@ namespace BizHawk.Client.EmuHawk private void Nes(string code) { - if (code.Length != 6 && code.Length != 8) - { - InputError("Game Genie codes need to be six or eight characters in length."); - } - var description = Description(code); var result = NesGameGenieDecoder.Decode(code); if (result.IsValid) @@ -292,7 +287,7 @@ namespace BizHawk.Client.EmuHawk } else { - InputError("Invalid Game Genie code"); + InputError(result.Error); } }