Añadiendo la clase asset

This commit is contained in:
2022-09-26 10:17:54 +02:00
parent 25616e1e6c
commit 9e089e9092
18 changed files with 1190 additions and 622 deletions

View File

@@ -7,26 +7,26 @@
// Constructor
Director::Director(std::string path)
{
// Inicializa la ruta
setExecutablePath(path);
// Crea el objeto que controla los ficheros de recursos
mAsset = new Asset(path.substr(0, path.find_last_of("\\/")) + "../");
// Establece la lista de ficheros
setFileList();
// Si falta algún fichero no inicies el programa
Uint8 section = PROG_SECTION_LOGO;
if (!checkFileList())
if (!setFileList())
{// Si falta algún fichero no inicies el programa
section = PROG_SECTION_QUIT;
}
// Crea el objeto de idioma
mLang = new Lang(mFileList);
mLang = new Lang(mAsset);
// Crea el puntero a la estructura y carga el fichero de configuración
mOptions = new options_t;
loadConfigFile();
// Crea los objetos
mInput = new Input(mFileList[53]);
mInput = new Input(mAsset->get("controllerdb.txt"));
// Inicializa SDL
initSDL();
@@ -48,6 +48,9 @@ Director::~Director()
{
saveConfigFile();
delete mAsset;
mAsset = nullptr;
delete mInput;
mInput = nullptr;
@@ -172,10 +175,82 @@ bool Director::initSDL()
}
// Crea el indice de ficheros
void Director::setFileList()
bool Director::setFileList()
{
// Ficheros binarios
mAsset->add("data/score.bin", data, false);
mAsset->add("data/demo.bin", data);
mAsset->add("data/config.bin", data, false);
// Musicas
mAsset->add("media/music/intro.ogg", music);
mAsset->add("media/music/playing.ogg", music);
mAsset->add("media/music/title.ogg", music);
// Sonidos
mAsset->add("media/sound/balloon.wav", sound);
mAsset->add("media/sound/bubble1.wav", sound);
mAsset->add("media/sound/bubble2.wav", sound);
mAsset->add("media/sound/bubble3.wav", sound);
mAsset->add("media/sound/bubble4.wav", sound);
mAsset->add("media/sound/bullet.wav", sound);
mAsset->add("media/sound/coffeeout.wav", sound);
mAsset->add("media/sound/hiscore.wav", sound);
mAsset->add("media/sound/itemdrop.wav", sound);
mAsset->add("media/sound/itempickup.wav", sound);
mAsset->add("media/sound/menu_cancel.wav", sound);
mAsset->add("media/sound/menu_move.wav", sound);
mAsset->add("media/sound/menu_select.wav", sound);
mAsset->add("media/sound/player_collision.wav", sound);
mAsset->add("media/sound/stage_change.wav", sound);
mAsset->add("media/sound/title.wav", sound);
mAsset->add("media/sound/clock.wav", sound);
mAsset->add("media/sound/powerball.wav", sound);
// Texturas
mAsset->add("media/gfx/balloon.png", bitmap);
mAsset->add("media/gfx/bullet.png", bitmap);
mAsset->add("media/gfx/game_bg.png", bitmap);
mAsset->add("media/gfx/game_text.png", bitmap);
mAsset->add("media/gfx/intro.png", bitmap);
mAsset->add("media/gfx/items.png", bitmap);
mAsset->add("media/gfx/logo.png", bitmap);
mAsset->add("media/gfx/player1_body.png", bitmap);
mAsset->add("media/gfx/player1_death.png", bitmap);
mAsset->add("media/gfx/player1_legs.png", bitmap);
mAsset->add("media/gfx/title.png", bitmap);
mAsset->add("media/gfx/player1_head.png", bitmap);
mAsset->add("media/gfx/player2_body.png", bitmap);
mAsset->add("media/gfx/player2_death.png", bitmap);
mAsset->add("media/gfx/player2_legs.png", bitmap);
mAsset->add("media/gfx/player2_head.png", bitmap);
// Fuentes
mAsset->add("media/font/8bithud.png", font);
mAsset->add("media/font/8bithud.txt", font);
mAsset->add("media/font/nokia.png", font);
mAsset->add("media/font/nokia_big2.png", font);
mAsset->add("media/font/nokia.txt", font);
mAsset->add("media/font/nokia2.png", font);
mAsset->add("media/font/nokia2.txt", font);
mAsset->add("media/font/nokia_big2.txt", font);
mAsset->add("media/font/smb2_big.png", font);
mAsset->add("media/font/smb2_big.txt", font);
mAsset->add("media/font/smb2.png", font);
mAsset->add("media/font/smb2.txt", font);
// Textos
mAsset->add("media/lang/es_ES.txt", lang);
mAsset->add("media/lang/en_UK.txt", lang);
mAsset->add("media/lang/ba_BA.txt", lang);
// DATA
mAsset->add("data/gamecontrollerdb.txt", data);
return mAsset->check();
// Inicializa el vector
for (int i = 0; i < MAX_FILE_LIST; i++)
/*for (int i = 0; i < MAX_FILE_LIST; i++)
mFileList[i] = "";
// Ficheros binarios
@@ -247,69 +322,7 @@ void Director::setFileList()
// DATA
mFileList[53] = mExecutablePath + "/" + "../data/gamecontrollerdb.txt";
}
// Comprueba los ficheros del vector de ficheros que coinciden con una ruta dada
bool Director::checkFolder(std::string name, std::string path)
{
bool success = true;
std::string p;
std::string filename;
SDL_RWops *file;
// Comprueba los ficheros de la carpeta
printf("\n>> %s FILES\n", name.c_str());
for (int i = 3; i < MAX_FILE_LIST; i++)
{
if (mFileList[i].find(path.c_str()) != std::string::npos)
{
p = mFileList[i].c_str();
filename = p.substr(p.find_last_of("\\/") + 1);
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file != nullptr)
{
printf("Checking file %-20s [OK]\n", filename.c_str());
}
else
{
printf("Checking file %-20s [ERROR]\n", filename.c_str());
success = false;
break;
}
SDL_RWclose(file);
}
}
return success;
}
// Comprueba que todos los ficheros existen
bool Director::checkFileList()
{
bool success = true;
printf("Checking files...\n");
if (success)
success &= checkFolder("MUSIC", "/media/music/");
if (success)
success &= checkFolder("SOUND", "/media/sound/");
if (success)
success &= checkFolder("BITMAP", "/media/gfx/");
if (success)
success &= checkFolder("FONT", "/media/font/");
if (success)
success &= checkFolder("LANG", "/media/lang/");
// Resultado
if (success)
printf("\n** All files OK.\n\n");
else
printf("\n** A file is missing. Exiting.\n\n");
return success;
*/
}
// Carga el fichero de configuración
@@ -332,7 +345,7 @@ bool Director::loadConfigFile()
// Indicador de éxito en la carga
bool success = true;
const std::string p = mFileList[2];
const std::string p = mAsset->get("config.bin");
std::string filename = p.substr(p.find_last_of("\\/") + 1);
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
@@ -409,7 +422,7 @@ bool Director::loadConfigFile()
bool Director::saveConfigFile()
{
bool success = true;
const std::string p = mFileList[2];
const std::string p = mAsset->get("config.bin");
std::string filename = p.substr(p.find_last_of("\\/") + 1);
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b");
if (file != nullptr)
@@ -440,12 +453,6 @@ bool Director::saveConfigFile()
return success;
}
// Establece el valor de la variable
void Director::setExecutablePath(std::string path)
{
mExecutablePath = path.substr(0, path.find_last_of("\\/"));
}
// Obtiene el valor de la variable
Uint8 Director::getSubsection()
{
@@ -466,21 +473,21 @@ void Director::setSection(section_t section)
void Director::runLogo()
{
mLogo = new Logo(mRenderer, mScreen, mFileList);
mLogo = new Logo(mRenderer, mScreen, mAsset);
setSection(mLogo->run());
delete mLogo;
}
void Director::runIntro()
{
mIntro = new Intro(mRenderer, mScreen, mFileList, mLang);
mIntro = new Intro(mRenderer, mScreen, mAsset, mLang);
setSection(mIntro->run());
delete mIntro;
}
void Director::runTitle()
{
mTitle = new Title(mWindow, mRenderer, mScreen, mInput, mFileList, mOptions, mLang);
mTitle = new Title(mWindow, mRenderer, mScreen, mInput, mAsset, mOptions, mLang);
setSection(mTitle->run(mSection.subsection));
delete mTitle;
}
@@ -489,14 +496,14 @@ void Director::runGame()
{
if (mSection.subsection == GAME_SECTION_PLAY_1P)
{
mGame = new Game(1, 8, mRenderer, mScreen, mFileList, mLang, mInput, false, mOptions);
mGame = new Game(1, 0, mRenderer, mScreen, mAsset, mLang, mInput, false, mOptions);
}
else if (mSection.subsection == GAME_SECTION_PLAY_2P)
{
mGame = new Game(2, 0, mRenderer, mScreen, mFileList, mLang, mInput, false, mOptions);
mGame = new Game(2, 0, mRenderer, mScreen, mAsset, mLang, mInput, false, mOptions);
}
setSection(mGame->run());
delete mGame;
}