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(); return asset->check();
} }
// Carga los recursos necesarios // Carga el fichero de configuración
bool Director::loadMedia(Uint8 section) bool Director::loadConfig()
{ {
// Indicador de éxito en la carga // Indicador de éxito en la carga
bool success = true; 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: printf("Warning: Unable to open %s file\n", filename.c_str());
{
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);
// Abre el fichero con la configuracion de las opciones para leer en binario // Crea el fichero para escribir
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b"); file = SDL_RWFromFile(p.c_str(), "w+b");
if (file != NULL)
// El fichero no existe
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 // Inicializa los datos
file = SDL_RWFromFile(p.c_str(), "w+b"); options.fullScreenMode = 0;
if (file != NULL) SDL_RWwrite(file, &options.fullScreenMode, sizeof(options.fullScreenMode), 1);
{
printf("New file (%s) created!\n", filename.c_str());
// Inicializa los datos options.windowSize = 3;
options.fullScreenMode = 0; SDL_RWwrite(file, &options.windowSize, sizeof(options.windowSize), 1);
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);
// Cierra el fichero // Cierra el fichero
SDL_RWclose(file); SDL_RWclose(file);
} }
printf("\n"); else
{
printf("Error: Unable to create file %s\n", filename.c_str());
success = false;
}
} }
break; // El fichero existe
else
case GAME_SECTION_TITLE:
{ {
} // Carga los datos
break; 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: // Cierra el fichero
{ SDL_RWclose(file);
}
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;
} }
printf("\n");
return success; return success;
} }

View File

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