Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

packer.cpp 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "olcPGE_Sprite.h"
  2. #include "olcPGE_ResourcePack.h"
  3. #include <iostream>
  4. #include <string>
  5. void PrintUsage() {
  6. std::cout << "Usage: packer --list PACK_FILE" << std::endl;
  7. std::cout << " packer --add PACK_FILE FILE" << std::endl;
  8. std::cout << " packer --remove PACK_FILE FILE" << std::endl;
  9. std::cout << " packer --convert PNG_FILE SPR_FILE" << std::endl;
  10. }
  11. void ListEntries(olc::ResourcePack& pack) {
  12. auto entries = pack.GetEntries();
  13. std::cout << "Total entries: " << entries.size() << std::endl;
  14. for (auto entry: entries) {
  15. std::cout << entry << std::endl;
  16. }
  17. }
  18. int main(int argc, char *argv[])
  19. {
  20. std::string packFile;
  21. std::string action;
  22. if (argc < 3) {
  23. PrintUsage();
  24. return -1;
  25. }
  26. action = argv[1];
  27. packFile = argv[2];
  28. olc::ResourcePack pack;
  29. if (action != "--convert") {
  30. pack.LoadPack(packFile);
  31. }
  32. if (action == "--list") {
  33. ListEntries(pack);
  34. } else if (action == "--add" || action == "--remove") {
  35. if (argc < 4) {
  36. PrintUsage();
  37. return -1;
  38. }
  39. for (int i = 3; i < argc; i++) {
  40. std::string fileName = argv[i];
  41. if (action == "--add") {
  42. if (!pack.AddToPack(fileName)) {
  43. std::cerr << "Could not open file " << fileName << std::endl;
  44. return -3;
  45. }
  46. std::cout << "+ " << fileName << std::endl;
  47. } else if (action == "--remove") {
  48. if (!pack.RemoveFromPack(fileName)) {
  49. std::cerr << "Could not open file " << fileName << std::endl;
  50. return -3;
  51. }
  52. std::cout << "- " << fileName << std::endl;
  53. }
  54. }
  55. std::cout << std::endl;
  56. ListEntries(pack);
  57. } else if (action == "--convert") {
  58. if (argc < 4) {
  59. PrintUsage();
  60. return -1;
  61. }
  62. olc::Sprite sprite;
  63. if (sprite.LoadFromFile(packFile) != olc::OK) {
  64. std::cerr << "Not valid PNG file " << packFile << std::endl;
  65. return -4;
  66. }
  67. std::string sprFile = argv[3];
  68. if (!sprite.SaveToPGESprFile(sprFile)) {
  69. std::cerr << "Could not save file " << sprFile << std::endl;
  70. return -3;
  71. }
  72. return 0;
  73. } else {
  74. PrintUsage();
  75. return -1;
  76. }
  77. if (!pack.SavePack(packFile)) {
  78. std::cerr << "Could not save file " << packFile << std::endl;
  79. }
  80. return 0;
  81. }