Modificado loadMedia por loadConfig

This commit is contained in:
2022-08-09 17:12:40 +02:00
parent 4d1a08a300
commit d7bd5a8ab1
2 changed files with 37 additions and 87 deletions

View File

@@ -241,108 +241,58 @@ bool Director::setFileList()
return asset->check();
}
// Carga los recursos necesarios
bool Director::loadMedia(Uint8 section)
// Carga el fichero de configuración
bool Director::loadConfig()
{
// Indicador de éxito en la carga
bool success = true;
std::string p;
const std::string p = asset->get("config-bin").c_str();
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
switch (section)
// Abre el fichero con la configuracion de las opciones para leer en binario
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
// El fichero no existe
if (file == NULL)
{
case GAME_SECTION_INIT:
{
p = asset->get("config-bin").c_str();
std::string filename = p.substr(p.find_last_of("\\/") + 1);
filename = p.substr(p.find_last_of("\\/") + 1);
printf("Warning: Unable to open %s file\n", filename.c_str());
// Abre el fichero con la configuracion de las opciones para leer en binario
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
// El fichero no existe
if (file == NULL)
// Crea el fichero para escribir
file = SDL_RWFromFile(p.c_str(), "w+b");
if (file != NULL)
{
printf("Warning: Unable to open %s file\n", filename.c_str());
printf("New file (%s) created!\n", filename.c_str());
// Crea el fichero para escribir
file = SDL_RWFromFile(p.c_str(), "w+b");
if (file != NULL)
{
printf("New file (%s) created!\n", filename.c_str());
// Inicializa los datos
options.fullScreenMode = 0;
SDL_RWwrite(file, &options.fullScreenMode, sizeof(options.fullScreenMode), 1);
// Inicializa los datos
options.fullScreenMode = 0;
SDL_RWwrite(file, &options.fullScreenMode, sizeof(options.fullScreenMode), 1);
options.windowSize = 3;
SDL_RWwrite(file, &options.windowSize, sizeof(options.windowSize), 1);
// Cierra el fichero
SDL_RWclose(file);
}
else
{
printf("Error: Unable to create file %s\n", filename.c_str());
success = false;
}
}
// El fichero existe
else
{
// Carga los datos
printf("Reading file %s\n", filename.c_str());
SDL_RWread(file, &options.fullScreenMode, sizeof(options.fullScreenMode), 1);
SDL_SetWindowFullscreen(window, options.fullScreenMode);
SDL_RWread(file, &options.windowSize, sizeof(options.windowSize), 1);
SDL_SetWindowSize(window, SCREEN_WIDTH * options.windowSize, SCREEN_HEIGHT * options.windowSize);
options.windowSize = 3;
SDL_RWwrite(file, &options.windowSize, sizeof(options.windowSize), 1);
// Cierra el fichero
SDL_RWclose(file);
}
printf("\n");
else
{
printf("Error: Unable to create file %s\n", filename.c_str());
success = false;
}
}
break;
case GAME_SECTION_TITLE:
// El fichero existe
else
{
}
break;
// Carga los datos
printf("Reading file %s\n", filename.c_str());
SDL_RWread(file, &options.fullScreenMode, sizeof(options.fullScreenMode), 1);
SDL_SetWindowFullscreen(window, options.fullScreenMode);
SDL_RWread(file, &options.windowSize, sizeof(options.windowSize), 1);
SDL_SetWindowSize(window, SCREEN_WIDTH * options.windowSize, SCREEN_HEIGHT * options.windowSize);
case GAME_SECTION_PLAYING:
{
}
break;
case GAME_SECTION_GAME_OVER_SCREEN:
{
}
break;
case GAME_SECTION_INTRO:
{
}
break;
case GAME_SECTION_DEMO:
{
}
break;
case GAME_SECTION_INSTRUCTIONS:
{
}
break;
case GAME_SECTION_LOGO:
{
}
break;
default:
{
}
break;
// Cierra el fichero
SDL_RWclose(file);
}
printf("\n");
return success;
}

View File

@@ -84,8 +84,8 @@ private:
// Crea el indice de ficheros de recursos
bool setFileList();
// Carga los recursos necesarios
bool loadMedia(Uint8 section);
// Carga el fichero de configuración
bool loadConfig();
// Descrga los recursos necesarios
bool unLoadMedia(Uint8 section);