From 63bf42880e8124bc24c87a86c6761c250967384d Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 9 Aug 2022 17:16:12 +0200 Subject: [PATCH] Modificado unLoadMedia por saveConfig --- source/director.cpp | 83 ++++++++++----------------------------------- source/director.h | 4 +-- 2 files changed, 19 insertions(+), 68 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index ae6bc96..c89ed6d 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -246,7 +246,7 @@ bool Director::loadConfig() { // Indicador de éxito en la carga bool success = true; - const std::string p = asset->get("config-bin").c_str(); + const std::string p = asset->get("config.bin").c_str(); const std::string filename = p.substr(p.find_last_of("\\/") + 1); // Abre el fichero con la configuracion de las opciones para leer en binario @@ -297,80 +297,31 @@ bool Director::loadConfig() return success; } -// Descrga los recursos necesarios -bool Director::unLoadMedia(Uint8 section) +// Guarda el fichero de configuración +bool Director::saveConfig() { // Indicador de éxito en la carga bool success = true; - std::string p; + const std::string p = asset->get("config.bin"); + const std::string filename = p.substr(p.find_last_of("\\/") + 1); - switch (section) + // Abre el fichero de puntuación para escribir + SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b"); + + if (file != NULL) { - case GAME_SECTION_INIT: - { - p = asset->get("config-bin"); - std::string filename = p.substr(p.find_last_of("\\/") + 1); + // Guardamos los datos + SDL_RWwrite(file, &options.fullScreenMode, sizeof(Uint32), 1); + SDL_RWwrite(file, &options.windowSize, sizeof(Uint8), 1); - // Abre el fichero de puntuación para escribir - SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b"); + printf("Writing file %s\n", filename.c_str()); - if (file != NULL) - { - // Guardamos los datos - SDL_RWwrite(file, &options.fullScreenMode, sizeof(Uint32), 1); - SDL_RWwrite(file, &options.windowSize, sizeof(Uint8), 1); - - printf("Writing file %s\n", filename.c_str()); - - // Cerramos el fichero - SDL_RWclose(file); - } - else - { - printf("Error: Unable to save %s file! %s\n", filename.c_str(), SDL_GetError()); - } + // Cerramos el fichero + SDL_RWclose(file); } - break; - - case GAME_SECTION_TITLE: + else { - } - break; - - 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; + printf("Error: Unable to save %s file! %s\n", filename.c_str(), SDL_GetError()); } return success; diff --git a/source/director.h b/source/director.h index ff99f84..f78c1ee 100644 --- a/source/director.h +++ b/source/director.h @@ -87,8 +87,8 @@ private: // Carga el fichero de configuración bool loadConfig(); - // Descrga los recursos necesarios - bool unLoadMedia(Uint8 section); + // Guarda el fichero de configuración + bool saveConfig(); // Obtiene el valor de la variable Uint8 getGameSection();