An advanced sprite packing tool. Currently a work in progress.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows.Markup;
  4. using System.IO;
  5. using System.Reflection;
  6. namespace SpritePacker
  7. {
  8. enum ProgramMode
  9. {
  10. Normal,
  11. DisplayHelpText,
  12. DisplayVersionText
  13. };
  14. class Program
  15. {
  16. public static string Version = Utilities.GetEmbeddedResourceContent("SpritePacker.Version.txt").Trim();
  17. private static ProgramMode programMode = ProgramMode.Normal;
  18. private static string helpTextFilename = "SpritePacker.Resources.HelpText.txt";
  19. private static string versionTextFilename = "SpritePacker.Resources.VersionText.txt";
  20. private static string commitHashFilename = "SpritePacker.latest-commit-hash.txt";
  21. private static List<string> values = new List<string>();
  22. public static int Main(string[] args)
  23. {
  24. string commitHash = Utilities.GetEmbeddedResourceContent(commitHashFilename).Trim();
  25. Version += "-" + commitHash.Substring(commitHash.Length - 7);
  26. for(int i = 0; i < args.Length; i++)
  27. {
  28. switch(args[i])
  29. {
  30. case "--help":
  31. programMode = ProgramMode.DisplayHelpText;
  32. break;
  33. case "--version":
  34. programMode = ProgramMode.DisplayVersionText;
  35. break;
  36. default:
  37. if(args[i].StartsWith("-"))
  38. {
  39. Console.Error.WriteLine("Error: Unrecognised flag '{0}'.", args[i]);
  40. return 1;
  41. }
  42. values.Add(args[i]);
  43. break;
  44. }
  45. }
  46. switch(programMode)
  47. {
  48. case ProgramMode.Normal:
  49. RunNormal();
  50. break;
  51. case ProgramMode.DisplayHelpText:
  52. case ProgramMode.DisplayVersionText:
  53. string textFileName = programMode == ProgramMode.DisplayHelpText ? helpTextFilename : versionTextFilename;
  54. string helpText = Utilities.GetEmbeddedResourceContent(textFileName);
  55. Dictionary<string, string> templateValues = new Dictionary<string, string>() {
  56. { "version", Version },
  57. { "build-date", Utilities.GetProgramBuildDate().ToString("dd/MM/yyyy h:mmtt") },
  58. { "commit-hash", commitHash.Substring(commitHash.Length - 7) },
  59. { "commit-url", string.Format("https://git.starbeamrainbowlabs.com/sbrl/SpritePacker/commit/{0}", commitHash) }
  60. };
  61. foreach (KeyValuePair<string, string> replacePair in templateValues)
  62. helpText = helpText.Replace(string.Format("{{{0}}}", replacePair.Key), replacePair.Value);
  63. Console.WriteLine(helpText);
  64. break;
  65. }
  66. return 0;
  67. }
  68. public static void RunNormal()
  69. {
  70. Packer spritePacker = new Packer();
  71. foreach(string filename in values)
  72. {
  73. if (File.Exists(filename))
  74. spritePacker.Add(new Sprite(filename));
  75. else
  76. Console.Error.WriteLine("Warning: Ignoring non-existent file '{0}'.", filename);
  77. }
  78. spritePacker.Arrange();
  79. Console.WriteLine(spritePacker.ToString());
  80. }
  81. }
  82. }