Elaztek Developer Hub
Blamite Game Engine - Tool (Library)  00368.02.12.23.1347.blamite
A command-line utility that aids in the creation of Blamite Cache (.map) Files.
BitmapsCommand.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Strings/components/utils/io/io.h>
4 #include <Strings/components/utils/string/string.h>
5 #include <Strings/components/utils/converters/converters.h>
6 #include <Strings/components/logger/logger.h>
7 
8 #include <HEKGuerilla/components/tags/importers/bitmap/bitmap.h>
9 #include <HEKGuerilla/components/tags/tags.h>
10 #include <HEKGuerilla/components/settings/config/config.h>
11 
12 #include "../ToolCommand.hpp"
13 #include "../console.h"
14 
15 #ifdef TOOL_LIB_EXPORTS
16 #define TOOL_LIB_API __declspec(dllexport)
17 #else
18 #define TOOL_LIB_API __declspec(dllimport)
19 #endif
20 
22 {
23 private:
24 
25 
26 public:
27 
29  {
30  command = "bitmaps";
31  syntax = "bitmaps <directory> <output directory> [recursive]";
32  description = "scans through a given directory and imports all images as bitmap tags. resulting tags will be placed in the specified output folder. "
33  "if recursive is set to true, then all subdirectories will be scanned and imported as well. this is disabled by default. "
34  "supported formats: apng, avif, bmp, cur, gif, ico, jpeg, jpeg2k, pcx, png, qoi, svg, tga, tiff, wal, webp, xbm";
35  }
36 
37  int execute(std::vector<std::string> args)
38  {
39  Guerilla::Tags::LoadPlugins();
40 
41  bool recursive_search = false;
42  std::string input_directory = "";
43  std::string output_directory = "";
44 
45  if (args.size() == 0)
46  {
47  BlamStrings::Logger::LogEvent("no input directory path was provided, cannot compile bitmaps", BlamLogLevel::Warning);
48  return -1;
49  }
50 
51  if (args.size() == 1)
52  {
53  BlamStrings::Logger::LogEvent("no output directory path was provided, cannot compile bitmaps", BlamLogLevel::Warning);
54  return -1;
55  }
56 
57  if (args.size() > 3)
58  {
59  BlamStrings::Logger::LogEvent("too many arguments specified - skipping compilation. check your input and try again. "
60  "for additional help, use 'tool.exe help bitmaps'.", BlamLogLevel::Warning);
61  return -1;
62  }
63 
64  // Prepare arguments
65  {
66  if (args.size() == 3)
67  {
68  if (BlamStrings::Converters::StringToBool(args[2]))
69  {
70  BlamStrings::Logger::LogEvent("enabling recursive bitmap import, if you have many subdirectories this may take a long time!");
71  BlamStrings::Logger::LogEvent("TODO: FINISH RECURSIVE IMPORT!!!", WSV_WARNING);
72  recursive_search = true;
73  }
74  }
75 
76  input_directory = BlamStrings::Utils::IO::NormalizePath(args[0]);
77  output_directory = BlamStrings::Utils::IO::NormalizePath(args[1]);
78  }
79 
80  std::vector<std::string> supported_extensions =
81  {
82  "apng",
83  "avif",
84  "bmp",
85  "cur",
86  "gif",
87  "ico",
88  "jpg",
89  "jpeg",
90  "jpeg2k",
91  "pcx",
92  "png",
93  "qoi",
94  "svg",
95  "tga",
96  "tif",
97  "tiff",
98  "wal",
99  "webp",
100  "xbm"
101  };
102 
103  std::vector<std::string> file_list = std::vector<std::string>();
104 
105  if (recursive_search)
106  {
107  file_list = BlamStrings::Utils::IO::GetDeepFileList(input_directory);
108  }
109  else
110  {
111  file_list = BlamStrings::Utils::IO::GetFileList(input_directory);
112  }
113 
114  for (std::string file_path : file_list)
115  {
116  if (BlamStrings::Utils::String::EndsWithAny(file_path, supported_extensions, true))
117  {
118  if (!Guerilla::Tags::Importers::Bitmap::ImportBitmap(file_path, output_directory))
119  {
120  BlamStrings::Logger::LogEvent("failed to import bitmap '" + file_path + "'", WSV_WARNING);
121  }
122  else
123  {
124  BlamStrings::Logger::LogEvent("successfully imported bitmap '" + file_path + "' to directory '" + output_directory + "'");
125  }
126  }
127  }
128 
129  Guerilla::Tags::ReleasePlugins();
130 
131  BlamStrings::Logger::LogEvent("finished.");
132  return 0;
133  }
134 };
BitmapsCommand::execute
int execute(std::vector< std::string > args)
Definition: BitmapsCommand.hpp:37
ToolCommand::syntax
std::string syntax
Definition: ToolCommand.hpp:16
ToolCommand::command
std::string command
Definition: ToolCommand.hpp:15
BitmapsCommand
Definition: BitmapsCommand.hpp:21
BitmapsCommand::BitmapsCommand
BitmapsCommand()
Definition: BitmapsCommand.hpp:28
ToolCommand
Definition: ToolCommand.hpp:12
ToolCommand::description
std::string description
Definition: ToolCommand.hpp:17