Afegits uns overrides pa agafar parametres per linea de comandos
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ private:
|
||||
// Variables
|
||||
std::string executable_path_; // Path del ejecutable
|
||||
std::string system_folder_; // Carpeta del sistema donde guardar datos
|
||||
std::string param_file_argument_; // Argumento para gestionar el fichero con los parametros del programa
|
||||
|
||||
// Inicializa jail_audio
|
||||
void initJailAudio();
|
||||
|
||||
@@ -60,19 +60,19 @@ void ManageHiScoreTable::sort()
|
||||
bool ManageHiScoreTable::loadFromFile(const std::string &file_path)
|
||||
{
|
||||
clear();
|
||||
|
||||
auto success = true;
|
||||
auto file = SDL_RWFromFile(file_path.c_str(), "r+b");
|
||||
|
||||
if (file)
|
||||
{
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::cout << "Reading file: " << file_name.c_str() << std::endl;
|
||||
for (int i = 0; i < (int)table_->size(); ++i)
|
||||
std::cout << "Reading file: " << file_name << std::endl;
|
||||
|
||||
for (auto &entry : *table_)
|
||||
{
|
||||
int nameSize = 0;
|
||||
|
||||
if (SDL_RWread(file, &table_->at(i).score, sizeof(int), 1) == 0)
|
||||
if (SDL_RWread(file, &entry.score, sizeof(int), 1) == 0)
|
||||
{
|
||||
success = false;
|
||||
break;
|
||||
@@ -84,19 +84,15 @@ bool ManageHiScoreTable::loadFromFile(const std::string &file_path)
|
||||
break;
|
||||
}
|
||||
|
||||
char *name = static_cast<char *>(malloc(nameSize + 1));
|
||||
if (SDL_RWread(file, name, sizeof(char) * nameSize, 1) == 0)
|
||||
std::vector<char> nameBuffer(nameSize + 1);
|
||||
if (SDL_RWread(file, nameBuffer.data(), sizeof(char) * nameSize, 1) == 0)
|
||||
{
|
||||
success = false;
|
||||
free(name);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
name[nameSize] = 0;
|
||||
table_->at(i).name = name;
|
||||
free(name);
|
||||
}
|
||||
|
||||
nameBuffer[nameSize] = '\0';
|
||||
entry.name = std::string(nameBuffer.data());
|
||||
}
|
||||
|
||||
SDL_RWclose(file);
|
||||
|
||||
@@ -480,7 +480,10 @@ void Screen::displayInfo()
|
||||
// Resolution
|
||||
dbg_print(0, 0, info_resolution_.c_str(), 255, 255, 0);
|
||||
|
||||
dbg_print(0, 8, std::to_string(globalInputs::service_pressed_counter[0]).c_str(), 255, 255, 0);
|
||||
// Contador de service_pressed_counter
|
||||
const int counter = globalInputs::service_pressed_counter[0];
|
||||
if (counter > 0)
|
||||
dbg_print(0, 8, std::to_string(counter).c_str(), 255, 0, 255);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
struct JA_Music_t; // lines 7-7
|
||||
struct JA_Sound_t; // lines 8-8
|
||||
|
||||
// Variables
|
||||
Overrides overrides = Overrides();
|
||||
|
||||
// Colores
|
||||
const Color bg_color = {0x27, 0x27, 0x36};
|
||||
const Color no_color = {0xFF, 0xFF, 0xFF};
|
||||
|
||||
@@ -29,6 +29,20 @@ enum class GameDifficulty
|
||||
HARD = 2,
|
||||
};
|
||||
|
||||
// Variables para que los argumentos del programa tengan mas peso que los definidos en otros lugares
|
||||
struct Overrides
|
||||
{
|
||||
std::string param_file; // Fichero de parametros a utilizar
|
||||
bool clear_hi_score_table; // Reinicia la tabla de records
|
||||
bool set_v_sync; // Establece el vsync
|
||||
|
||||
// Constructor por defecto
|
||||
Overrides()
|
||||
: param_file(""), clear_hi_score_table(false), set_v_sync(false) {}
|
||||
};
|
||||
|
||||
extern Overrides overrides;
|
||||
|
||||
// Estructura para definir un circulo
|
||||
struct Circle
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user