-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
107 lines (81 loc) · 2.89 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <commands.hpp>
#include <functional>
#include <iostream>
#include <util/misc.hpp>
// clang-format off
namespace {
void showCommands();
struct Command {
std::string_view mCommand = "";
std::vector<std::string_view> mParameters;
std::string_view mDescription = "";
std::function<void()> mFunction;
};
static std::vector<Command> gCommands = {
{ "load", { "input filename" }, "loads a MOD file", cmd::mod::loadFile },
{ "write", { "output filename" }, "writes the MOD file", cmd::mod::writeFile },
{ "close", {}, "closes the MOD file", cmd::mod::closeFile },
{ "NEW_LINE" },
{ "import_texture", {}, "swaps a texture with an external TXE file", cmd::mod::importTexture },
{ "import_ini", { "input filename" }, "imports an external ini", cmd::mod::importIni },
{ "NEW_LINE" },
{ "export_materials", { "output filename" }, " exports all materials to a file ", cmd::mod::exportMaterials },
{ "export_textures", { "output directory"}, "exports all textures to a directory", cmd::mod::exportTextures },
{ "export_ini", { "output filename" }, "exports the ini to a file", cmd::mod::exportIni },
{ "export_obj", { "output filename" }, "exports the model to an obj file [WIP]", cmd::mod::exportObj },
{ "export_dmd", { "output filename" }, "exports the model to a dmd file [WIP]", cmd::mod::exportDmd },
{ "NEW_LINE" },
{ "obj_to_dmd", { "input filename", "output filename" }, "converts an obj file to dmd [WIP]", cmd::objToDmd },
{ "NEW_LINE" },
{ "help", {}, "re-generate this command list", showCommands }
};
void showCommands()
{
std::cout << std::endl << "Commands:" << std::endl;
for (const Command& cmd : gCommands) {
if (cmd.mCommand == "NEW_LINE") {
std::cout << std::endl;
continue;
}
std::cout << " " << cmd.mCommand << " ";
for (std::size_t i = 0; i < cmd.mParameters.size(); i++) {
std::cout << "[" << cmd.mParameters[i] << "] ";
}
std::cout << "- " << cmd.mDescription << std::endl;
}
std::cout << std::endl;
}
} // namespace
// clang-format on
int main(int argc, char** argv)
{
std::atexit(util::ExitHook);
std::cout << "MODConv by Axiot, 2021 [Last updated [DD/MM/YYYY] 03/07/2024]" << std::endl;
std::cout << "Don't forget to write the file after editing it" << std::endl;
showCommands();
while (true) {
std::string input = "";
std::getline(std::cin, input);
if (!input.size()) {
break;
}
cmd::gTokeniser.read(input);
const std::string& token = cmd::gTokeniser.next();
bool foundCmd = false;
for (const Command& cmd : gCommands) {
if (cmd.mCommand == "NEW_LINE") {
continue;
}
if (cmd.mCommand == token) {
cmd.mFunction();
foundCmd = true;
break;
}
}
if (!foundCmd) {
std::cout << "Unknown command " << token << std::endl;
}
std::cout << std::endl;
}
return EXIT_SUCCESS;
}