From a0b14f507103661f13fc4450c6f47bd53750e59f Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 8 Sep 2021 13:59:39 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adida=20la=20clase=20asset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/asset.cpp | 20 ++++++++++++++++++++ source/asset.h | 42 ++++++++++++++++++++++++++++++++++++++++++ source/director.cpp | 6 ++++++ source/director.h | 3 ++- source/game.h | 1 - 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 source/asset.cpp create mode 100644 source/asset.h diff --git a/source/asset.cpp b/source/asset.cpp new file mode 100644 index 0000000..f473907 --- /dev/null +++ b/source/asset.cpp @@ -0,0 +1,20 @@ +#include "asset.h" + +// Constructor +Asset::Asset(std::string path) +{ +} + +// Destructor +Asset::~Asset() +{ +} + +// Añade un elemento a la lista +void Asset::add(std::string file, enum assetType type) +{ + item_t temp; + temp.file = file; + temp.type = type; + mFileList.push_back(temp); +} \ No newline at end of file diff --git a/source/asset.h b/source/asset.h new file mode 100644 index 0000000..187b7ef --- /dev/null +++ b/source/asset.h @@ -0,0 +1,42 @@ +#pragma once +#include "ifdefs.h" +#include +#include + +#ifndef ASSET_H +#define ASSET_H + +enum assetType {bitmap, music, sound, data, font, lang}; + +#define ASSET_TYPE_BITMAP 0 +#define ASSET_TYPE_MUSIC 1 +#define ASSET_TYPE_SOUND 2 +#define ASSET_TYPE_DATA 3 +#define ASSET_TYPE_FONT 4 +#define ASSET_TYPE_LANG 5 + +// Clase Asset +class Asset +{ +private: + // Estructura para definir un item + struct item_t + { + std::string file; + enum assetType type; + }; + + std::vector mFileList; + +public: + // Constructor + Asset(std::string path); + + // Destructor + ~Asset(); + + // Añade un elemento a la lista + void add(std::string file, enum assetType type); +}; + +#endif diff --git a/source/director.cpp b/source/director.cpp index 1154fbb..17edf17 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -13,6 +13,9 @@ Director::Director(std::string path) // Establece la lista de ficheros setFileList(); + // Crea el objeto que controla los ficheros de recursos + mAsset = new Asset(mExecutablePath); + // Si falta algún fichero no inicies el programa Uint8 section = PROG_SECTION_GAME; if (!checkFileList()) @@ -66,6 +69,9 @@ Director::~Director() delete mOptions; mOptions = nullptr; + delete mAsset; + mAsset = nullptr; + SDL_DestroyRenderer(mRenderer); SDL_DestroyWindow(mWindow); mRenderer = nullptr; diff --git a/source/director.h b/source/director.h index b9ba25b..2872fd0 100644 --- a/source/director.h +++ b/source/director.h @@ -12,6 +12,7 @@ #include "input.h" #include "fade.h" #include "game.h" +#include "asset.h" #include "lang.h" #ifndef DIRECTOR_H @@ -29,8 +30,8 @@ private: Input *mInput; // Objeto Input para gestionar las entradas Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas Game *mGame; // Objeto para la sección del juego + Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos - std::string mFileList[MAX_FILE_LIST]; // Vector con las rutas a los ficheros de recursos struct options_t *mOptions; // Variable con todas las opciones del programa std::string mExecutablePath; // Path del ejecutable diff --git a/source/game.h b/source/game.h index b86c720..d81bbe5 100644 --- a/source/game.h +++ b/source/game.h @@ -26,7 +26,6 @@ private: SDL_Renderer *mRenderer; // El renderizador de la ventana Screen *mScreen; // El objeto encargado de manejar el renderizador SDL_Event *mEventHandler; // Manejador de eventos - std::string *mFileList; // Lista de ficheros con los recursos Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas Input *mInput; // Manejador de entrada Text *mText; // Fuente para los textos del juego