From d7bd5a8ab1a115e27b7b840d58abcdb7e4aee51d Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 9 Aug 2022 17:12:40 +0200 Subject: [PATCH] Modificado loadMedia por loadConfig --- source/director.cpp | 120 +++++++++++++------------------------------- source/director.h | 4 +- 2 files changed, 37 insertions(+), 87 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 727832b..ae6bc96 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -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; } diff --git a/source/director.h b/source/director.h index 093ec5b..ff99f84 100644 --- a/source/director.h +++ b/source/director.h @@ -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);