A tool to index convert files into 4bpp indexed graphics with palettes to be used with embedded development kits.

Program.cs 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using CommandLine;
  7. using CSharpx;
  8. namespace agbidx
  9. {
  10. [Verb("pokemon", HelpText = "Parse a combination of Pokémon front- and backsprite, and output two files respectively.")]
  11. class PokespriteOptions {
  12. [Option('i', "input-files", Required = true, HelpText = "Input images to be processed")]
  13. public IEnumerable<string> Input {get;set;}
  14. [Option('o', "output-directory", Default = ".", Required = false, HelpText = "Output directory for the processed images, defaults to current directory")]
  15. public string OutputDirectory{get;set;}
  16. [Option('v', "verbose", Default = false, Required = false, HelpText = "Show Verbose information")]
  17. public bool Verbose{get;set;}
  18. [Option('r', "recursive", Default = false, Required = false, HelpText = "Recursively scan directories for images, by default only one level is scanned, if an input argument is a directory")]
  19. public bool Recursive{get;set;}
  20. }
  21. class Program
  22. {
  23. static async Task<int> Main(string[] args)
  24. {
  25. return await CommandLine.Parser.Default.ParseArguments<PokespriteOptions>(args)
  26. .MapResult(
  27. async (PokespriteOptions opts) => await RunPokespritesAndReturnExitCode(opts),
  28. async (IEnumerable<Error> errs) => await Task.Run<int>(() => 1));
  29. }
  30. static async Task<int> RunPokespritesAndReturnExitCode(PokespriteOptions opts)
  31. {
  32. try
  33. {
  34. if(!Directory.Exists(opts.OutputDirectory))
  35. Directory.CreateDirectory(opts.OutputDirectory);
  36. await Task.WhenAll(opts.Input.Select(s => ImageLib.BitmapProcessor.ProcessPokemonImage(opts.OutputDirectory, s, opts.Verbose, true, opts.Recursive)));
  37. return 0;
  38. }
  39. catch(Exception ex)
  40. {
  41. Console.WriteLine("An error occured: " + ex.Message);
  42. return 1;
  43. }
  44. }
  45. }
  46. }