Afegits uns overrides pa agafar parametres per linea de comandos

This commit is contained in:
2024-10-21 17:46:05 +02:00
parent 2cb22ed013
commit 84238032e0
6 changed files with 61 additions and 22 deletions

View File

@@ -84,13 +84,22 @@ Director::Director(int argc, const char *argv[])
#ifdef ANBERNIC
const std::string paramFilePath = asset->get("param_320x240.txt");
#else
const std::string paramFilePath = param_file_argument_ == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
#endif
loadParams(paramFilePath);
// Carga el fichero de puntuaciones
auto manager = std::make_unique<ManageHiScoreTable>(&options.game.hi_score_table);
manager->loadFromFile(Asset::get()->get("score.bin"));
{
auto manager = std::make_unique<ManageHiScoreTable>(&options.game.hi_score_table);
if (overrides.clear_hi_score_table)
{
manager->clear();
}
else
{
manager->loadFromFile(Asset::get()->get("score.bin"));
}
}
// Inicializa SDL
initSDL();
@@ -513,18 +522,33 @@ void Director::loadParams(const std::string &file_path)
// Comprueba los parametros del programa
void Director::checkProgramArguments(int argc, const char *argv[])
{
const std::vector<std::string> argument_list = {"--h", "--320x240", "--clear_score"};
// Establece la ruta del programa
executable_path_ = argv[0];
// Valores por defecto
param_file_argument_.clear();
// Comprueba el resto de parámetros
for (int i = 1; i < argc; ++i)
{
if (strcmp(argv[i], "--h") == 0)
{
for (const auto &argument : argument_list)
{
std::cout << argument << std::endl;
}
// std::exit(EXIT_SUCCESS);
section::name = section::Name::QUIT;
section::options = section::Options::QUIT_FROM_EVENT;
}
if (strcmp(argv[i], "--320x240") == 0)
{
param_file_argument_ = argv[i];
overrides.param_file = argv[i];
}
if (strcmp(argv[i], "--clear_score") == 0)
{
overrides.clear_hi_score_table = true;
}
}
}