From 1e19ceb97bc616e7311c5836613ed45576411578 Mon Sep 17 00:00:00 2001 From: Alexey 'Cluster' Avdyukhin Date: Fri, 28 Oct 2022 20:27:19 +0400 Subject: Error checks. --- NesTiler/Config.cs | 12 ++++++++---- NesTiler/Program.cs | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/NesTiler/Config.cs b/NesTiler/Config.cs index d039e68..927bf76 100644 --- a/NesTiler/Config.cs +++ b/NesTiler/Config.cs @@ -34,7 +34,7 @@ namespace com.clusterrr.Famicom.NesTiler public int PatternTableStartOffsetShared { get; private set; } = 0; public Dictionary PatternTableStartOffsets { get; private set; } = new Dictionary(); public Dictionary PattributeTableYOffsets { get; private set; } = new Dictionary(); - public bool quiet { get; private set; } = false; + public bool Quiet { get; private set; } = false; // Filenames public Dictionary OutPreview { get; private set; } = new Dictionary(); @@ -250,7 +250,7 @@ namespace com.clusterrr.Famicom.NesTiler break; case ArgQuiet.S: case ArgQuiet.L: - config.quiet = true; + config.Quiet = true; break; default: throw new ArgumentException($"Unknown argument.", args[i]); @@ -262,10 +262,14 @@ namespace com.clusterrr.Famicom.NesTiler { case TilesMode.Sprites8x8: case TilesMode.Sprites8x16: - if (!config.BgColor.HasValue) throw new InvalidDataException("You must specify background color for sprites."); + if (!config.BgColor.HasValue) throw new InvalidDataException("You must specify background color for sprites mode."); break; } - // TODO: more input checks + // Check output files + foreach (var c in new Dictionary[] { config.OutPreview, config.OutPatternTable, config.OutNameTable, config.OutAttributeTable }) + foreach (var f in c) + if (!config.ImageFiles.ContainsKey(f.Key)) + throw new ArgumentException($"Can't write {f.Value} - there is no input image with index {f.Key}."); return config; } diff --git a/NesTiler/Program.cs b/NesTiler/Program.cs index c23d5ab..90c729f 100644 --- a/NesTiler/Program.cs +++ b/NesTiler/Program.cs @@ -56,7 +56,7 @@ namespace com.clusterrr.Famicom.NesTiler var c = Config.Parse(args); Trace.Listeners.Clear(); - if (!c.quiet) + if (!c.Quiet) { PrintAppInfo(); Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); @@ -227,7 +227,7 @@ namespace com.clusterrr.Famicom.NesTiler candidates[i]); } // Select background color which uses minimum palettes - // TODO: less palettes != best solution? Take in account tile count. + // TODO: less palettes != best solution? Take tile count into account. var kvAllLossless = calcResults.Where(kv => kv.Value.LossyInfo == null).OrderBy(kv => kv.Value.Palettes.Length); if (kvAllLossless.Any()) { -- cgit v1.2.3