precarrega les textures del jugador amb variants de paleta
This commit is contained in:
@@ -69,7 +69,8 @@ void Resource::loadEssentialResources() {
|
||||
loadTextFilesQuiet(); // <- VERSIÓN SILENCIOSA
|
||||
loadEssentialTextures(); // Ya es silenciosa
|
||||
createText(); // Crear objetos de texto
|
||||
createTextures(); // Crear texturas generadas (game_text_xxx)
|
||||
createTextTextures(); // Crear texturas generadas (game_text_xxx)
|
||||
createPlayerTextures(); // Crea las texturas de jugadores con todas sus variantes de paleta
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Essential resources loaded");
|
||||
}
|
||||
@@ -417,13 +418,13 @@ void Resource::load() {
|
||||
loadSounds(); // Carga sonidos
|
||||
loadMusics(); // Carga músicas
|
||||
#endif
|
||||
loadTextures(); // Carga texturas
|
||||
loadTextFiles(); // Carga ficheros de texto
|
||||
loadAnimations(); // Carga animaciones
|
||||
loadDemoData(); // Carga datos de demo
|
||||
addPalettes(); // Añade paletas a las texturas
|
||||
createText(); // Crea objetos de texto
|
||||
createTextures(); // Crea texturas a partir de texto
|
||||
loadTextures(); // Carga texturas
|
||||
loadTextFiles(); // Carga ficheros de texto
|
||||
loadAnimations(); // Carga animaciones
|
||||
loadDemoData(); // Carga datos de demo
|
||||
createText(); // Crea objetos de texto
|
||||
createTextTextures(); // Crea texturas a partir de texto
|
||||
createPlayerTextures(); // Crea las texturas de jugadores con todas sus variantes de paleta
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** RESOURCES LOADED");
|
||||
|
||||
// Restablece el sincronismo vertical a su valor original
|
||||
@@ -440,20 +441,6 @@ void Resource::reload() {
|
||||
}
|
||||
}
|
||||
|
||||
// Recarga solo las texturas y paletas
|
||||
void Resource::reloadTextures() {
|
||||
if (loading_mode_ == LoadingMode::PRELOAD) {
|
||||
loadTextures();
|
||||
addPalettes();
|
||||
createTextures();
|
||||
} else {
|
||||
// En modo lazy, limpiamos las texturas cargadas para forzar recarga
|
||||
for (auto &texture : textures_) {
|
||||
texture.texture = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los sonidos del juego
|
||||
void Resource::loadSounds() {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> SOUND FILES");
|
||||
@@ -541,23 +528,61 @@ void Resource::loadDemoData() {
|
||||
}
|
||||
}
|
||||
|
||||
// Añade paletas de colores a las texturas principales
|
||||
void Resource::addPalettes() {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> PALETTES");
|
||||
// Crea las texturas de jugadores con todas sus variantes de paleta
|
||||
void Resource::createPlayerTextures() {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> CREATING PLAYER TEXTURES");
|
||||
|
||||
// Paletas para el jugador 1
|
||||
getTexture("player1.gif")->addPaletteFromPalFile(Asset::get()->get("player1_coffee1.pal"));
|
||||
getTexture("player1.gif")->addPaletteFromPalFile(Asset::get()->get("player1_coffee2.pal"));
|
||||
getTexture("player1.gif")->addPaletteFromPalFile(Asset::get()->get("player1_invencible.pal"));
|
||||
// Configuración de jugadores y sus paletas
|
||||
struct PlayerConfig {
|
||||
std::string base_texture;
|
||||
std::vector<std::string> palette_files;
|
||||
std::string name_prefix;
|
||||
};
|
||||
|
||||
// Paletas para el jugador 2
|
||||
getTexture("player2.gif")->addPaletteFromPalFile(Asset::get()->get("player2_coffee1.pal"));
|
||||
getTexture("player2.gif")->addPaletteFromPalFile(Asset::get()->get("player2_coffee2.pal"));
|
||||
getTexture("player2.gif")->addPaletteFromPalFile(Asset::get()->get("player2_invencible.pal"));
|
||||
std::vector<PlayerConfig> players = {
|
||||
{"player1.gif", {"player1_coffee1.pal", "player1_coffee2.pal", "player1_invencible.pal"}, "player1"},
|
||||
{"player2.gif", {"player2_coffee1.pal", "player2_coffee2.pal", "player2_invencible.pal"}, "player2"}};
|
||||
|
||||
for (const auto &player : players) {
|
||||
// Encontrar el archivo original de la textura
|
||||
std::string texture_file_path;
|
||||
auto texture_list = Asset::get()->getListByType(Asset::Type::BITMAP);
|
||||
for (const auto &file : texture_list) {
|
||||
if (getFileName(file) == player.base_texture) {
|
||||
texture_file_path = file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Crear variante con paleta original (pal0) - usar la textura ya cargada
|
||||
auto base_texture = getTexture(player.base_texture);
|
||||
std::string pal0_name = player.name_prefix + "_pal0";
|
||||
textures_.emplace_back(pal0_name, base_texture);
|
||||
printWithDots("Player Texture : ", pal0_name, "[ DONE ]");
|
||||
|
||||
// Crear variantes con paletas adicionales - CADA UNA DESDE EL ARCHIVO
|
||||
for (size_t i = 0; i < player.palette_files.size(); ++i) {
|
||||
// Crear textura completamente nueva desde el archivo
|
||||
auto texture_copy = std::make_shared<Texture>(Screen::get()->getRenderer(), texture_file_path);
|
||||
|
||||
// Añadir todas las paletas
|
||||
texture_copy->addPaletteFromPalFile(Asset::get()->get(player.palette_files[0]));
|
||||
texture_copy->addPaletteFromPalFile(Asset::get()->get(player.palette_files[1]));
|
||||
texture_copy->addPaletteFromPalFile(Asset::get()->get(player.palette_files[2]));
|
||||
|
||||
// Cambiar a la paleta específica (índice i+1 porque 0 es la original)
|
||||
texture_copy->setPalette(i + 1);
|
||||
|
||||
// Guardar con nombre específico
|
||||
std::string variant_name = player.name_prefix + "_pal" + std::to_string(i + 1);
|
||||
textures_.emplace_back(variant_name, texture_copy);
|
||||
printWithDots("Player Texture : ", variant_name, "[ DONE ]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Crea texturas a partir de textos para mostrar puntuaciones y mensajes
|
||||
void Resource::createTextures() {
|
||||
void Resource::createTextTextures() {
|
||||
struct NameAndText {
|
||||
std::string name;
|
||||
std::string text;
|
||||
|
||||
Reference in New Issue
Block a user