clang-format
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
@@ -31,7 +32,8 @@ void Asset::addToMap(const std::string &file_path, Type type, bool required, boo
|
|||||||
// Verificar si ya existe el archivo
|
// Verificar si ya existe el archivo
|
||||||
if (file_list_.find(filename) != file_list_.end()) {
|
if (file_list_.find(filename) != file_list_.end()) {
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Warning: Asset '%s' already exists, overwriting", filename.c_str());
|
"Warning: Asset '%s' already exists, overwriting",
|
||||||
|
filename.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
file_list_.emplace(filename, Item{std::move(full_path), type, required});
|
file_list_.emplace(filename, Item{std::move(full_path), type, required});
|
||||||
@@ -48,7 +50,8 @@ void Asset::loadFromFile(const std::string &config_file_path, const std::string
|
|||||||
std::ifstream file(config_file_path);
|
std::ifstream file(config_file_path);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Error: Cannot open config file: %s", config_file_path.c_str());
|
"Error: Cannot open config file: %s",
|
||||||
|
config_file_path.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +85,8 @@ void Asset::loadFromFile(const std::string &config_file_path, const std::string
|
|||||||
// Verificar que tenemos al menos tipo y ruta
|
// Verificar que tenemos al menos tipo y ruta
|
||||||
if (parts.size() < 2) {
|
if (parts.size() < 2) {
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Warning: Malformed line %d in config file (insufficient fields)", line_number);
|
"Warning: Malformed line %d in config file (insufficient fields)",
|
||||||
|
line_number);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,12 +114,15 @@ void Asset::loadFromFile(const std::string &config_file_path, const std::string
|
|||||||
|
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Error parsing line %d in config file: %s", line_number, e.what());
|
"Error parsing line %d in config file: %s",
|
||||||
|
line_number,
|
||||||
|
e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Loaded %d assets from config file", static_cast<int>(file_list_.size()));
|
"Loaded %d assets from config file",
|
||||||
|
static_cast<int>(file_list_.size()));
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
@@ -143,7 +150,7 @@ auto Asset::check() const -> bool {
|
|||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** CHECKING FILES");
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** CHECKING FILES");
|
||||||
|
|
||||||
// Agrupar por tipo para mostrar organizado
|
// Agrupar por tipo para mostrar organizado
|
||||||
std::unordered_map<Type, std::vector<const Item*>> by_type;
|
std::unordered_map<Type, std::vector<const Item *>> by_type;
|
||||||
|
|
||||||
for (const auto &[filename, item] : file_list_) {
|
for (const auto &[filename, item] : file_list_) {
|
||||||
if (item.required) {
|
if (item.required) {
|
||||||
@@ -157,7 +164,8 @@ auto Asset::check() const -> bool {
|
|||||||
|
|
||||||
if (by_type.find(asset_type) != by_type.end()) {
|
if (by_type.find(asset_type) != by_type.end()) {
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"\n>> %s FILES", getTypeName(asset_type).c_str());
|
"\n>> %s FILES",
|
||||||
|
getTypeName(asset_type).c_str());
|
||||||
|
|
||||||
bool type_success = true;
|
bool type_success = true;
|
||||||
for (const auto *item : by_type[asset_type]) {
|
for (const auto *item : by_type[asset_type]) {
|
||||||
@@ -191,7 +199,8 @@ auto Asset::checkFile(const std::string &path) -> bool {
|
|||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Checking file: %s [ ERROR ]", getFileName(path).c_str());
|
"Checking file: %s [ ERROR ]",
|
||||||
|
getFileName(path).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
@@ -233,16 +242,26 @@ auto Asset::parseAssetType(const std::string &type_str) -> Type {
|
|||||||
// Devuelve el nombre del tipo de recurso
|
// Devuelve el nombre del tipo de recurso
|
||||||
auto Asset::getTypeName(Type type) -> std::string {
|
auto Asset::getTypeName(Type type) -> std::string {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Type::BITMAP: return "BITMAP";
|
case Type::BITMAP:
|
||||||
case Type::MUSIC: return "MUSIC";
|
return "BITMAP";
|
||||||
case Type::SOUND: return "SOUND";
|
case Type::MUSIC:
|
||||||
case Type::FONT: return "FONT";
|
return "MUSIC";
|
||||||
case Type::LANG: return "LANG";
|
case Type::SOUND:
|
||||||
case Type::DATA: return "DATA";
|
return "SOUND";
|
||||||
case Type::DEMODATA: return "DEMODATA";
|
case Type::FONT:
|
||||||
case Type::ANIMATION: return "ANIMATION";
|
return "FONT";
|
||||||
case Type::PALETTE: return "PALETTE";
|
case Type::LANG:
|
||||||
default: return "ERROR";
|
return "LANG";
|
||||||
|
case Type::DATA:
|
||||||
|
return "DATA";
|
||||||
|
case Type::DEMODATA:
|
||||||
|
return "DEMODATA";
|
||||||
|
case Type::ANIMATION:
|
||||||
|
return "ANIMATION";
|
||||||
|
case Type::PALETTE:
|
||||||
|
return "PALETTE";
|
||||||
|
default:
|
||||||
|
return "ERROR";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
// Clase Asset: gestor optimizado de recursos (singleton)
|
// Clase Asset: gestor optimizado de recursos (singleton)
|
||||||
class Asset {
|
class Asset {
|
||||||
|
|||||||
@@ -460,26 +460,21 @@ void Player::setAnimation() {
|
|||||||
player_sprite_->setFlip(flipMode);
|
player_sprite_->setFlip(flipMode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case State::WAITING:
|
case State::WAITING:
|
||||||
player_sprite_->setCurrentAnimation("hello");
|
player_sprite_->setCurrentAnimation("hello");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::ROLLING:
|
case State::ROLLING:
|
||||||
case State::CONTINUE_TIME_OUT:
|
case State::CONTINUE_TIME_OUT:
|
||||||
player_sprite_->setCurrentAnimation("rolling");
|
player_sprite_->setCurrentAnimation("rolling");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::LYING_ON_THE_FLOOR_FOREVER:
|
case State::LYING_ON_THE_FLOOR_FOREVER:
|
||||||
case State::ENTERING_NAME:
|
case State::ENTERING_NAME:
|
||||||
case State::CONTINUE:
|
case State::CONTINUE:
|
||||||
player_sprite_->setCurrentAnimation("dead");
|
player_sprite_->setCurrentAnimation("dead");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::CELEBRATING:
|
case State::CELEBRATING:
|
||||||
player_sprite_->setCurrentAnimation("celebration");
|
player_sprite_->setCurrentAnimation("celebration");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,25 +13,33 @@
|
|||||||
// --- Implementación de las estructuras de animación ---
|
// --- Implementación de las estructuras de animación ---
|
||||||
|
|
||||||
void MenuRenderer::ResizeAnimation::start(float from_w, float from_h, float to_w, float to_h) {
|
void MenuRenderer::ResizeAnimation::start(float from_w, float from_h, float to_w, float to_h) {
|
||||||
start_width = from_w; start_height = from_h;
|
start_width = from_w;
|
||||||
target_width = to_w; target_height = to_h;
|
start_height = from_h;
|
||||||
|
target_width = to_w;
|
||||||
|
target_height = to_h;
|
||||||
elapsed = 0.0F;
|
elapsed = 0.0F;
|
||||||
active = true;
|
active = true;
|
||||||
}
|
}
|
||||||
void MenuRenderer::ResizeAnimation::stop() { active = false;
|
void MenuRenderer::ResizeAnimation::stop() {
|
||||||
|
active = false;
|
||||||
elapsed = 0.0F;
|
elapsed = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuRenderer::ShowHideAnimation::startShow(float to_w, float to_h) {
|
void MenuRenderer::ShowHideAnimation::startShow(float to_w, float to_h) {
|
||||||
type = Type::SHOWING; target_width = to_w; target_height = to_h;
|
type = Type::SHOWING;
|
||||||
|
target_width = to_w;
|
||||||
|
target_height = to_h;
|
||||||
elapsed = 0.0F;
|
elapsed = 0.0F;
|
||||||
active = true;
|
active = true;
|
||||||
}
|
}
|
||||||
void MenuRenderer::ShowHideAnimation::startHide() { type = Type::HIDING;
|
void MenuRenderer::ShowHideAnimation::startHide() {
|
||||||
|
type = Type::HIDING;
|
||||||
elapsed = 0.0F;
|
elapsed = 0.0F;
|
||||||
active = true;
|
active = true;
|
||||||
}
|
}
|
||||||
void MenuRenderer::ShowHideAnimation::stop() { type = Type::NONE; active = false;
|
void MenuRenderer::ShowHideAnimation::stop() {
|
||||||
|
type = Type::NONE;
|
||||||
|
active = false;
|
||||||
elapsed = 0.0F;
|
elapsed = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +118,7 @@ void MenuRenderer::update(const ServiceMenu *menu_state) {
|
|||||||
|
|
||||||
// --- Nuevos métodos de control ---
|
// --- Nuevos métodos de control ---
|
||||||
|
|
||||||
void MenuRenderer::show(const ServiceMenu* menu_state) {
|
void MenuRenderer::show(const ServiceMenu *menu_state) {
|
||||||
if (visible_) {
|
if (visible_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -201,7 +209,6 @@ auto MenuRenderer::calculateNewRect(const ServiceMenu *menu_state) -> SDL_FRect
|
|||||||
return new_rect;
|
return new_rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MenuRenderer::resize(const ServiceMenu *menu_state) {
|
void MenuRenderer::resize(const ServiceMenu *menu_state) {
|
||||||
SDL_FRect new_rect = calculateNewRect(menu_state);
|
SDL_FRect new_rect = calculateNewRect(menu_state);
|
||||||
|
|
||||||
@@ -286,7 +293,6 @@ void MenuRenderer::updateResizeAnimation(float delta_time) {
|
|||||||
options_y_ = rect_.y + upper_height_ + lower_padding_;
|
options_y_ = rect_.y + upper_height_ + lower_padding_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MenuRenderer::updatePosition() {
|
void MenuRenderer::updatePosition() {
|
||||||
switch (position_mode_) {
|
switch (position_mode_) {
|
||||||
case PositionMode::CENTERED:
|
case PositionMode::CENTERED:
|
||||||
|
|||||||
@@ -88,7 +88,9 @@ class MenuRenderer {
|
|||||||
} resize_animation_;
|
} resize_animation_;
|
||||||
|
|
||||||
struct ShowHideAnimation {
|
struct ShowHideAnimation {
|
||||||
enum class Type { NONE, SHOWING, HIDING };
|
enum class Type { NONE,
|
||||||
|
SHOWING,
|
||||||
|
HIDING };
|
||||||
Type type = Type::NONE;
|
Type type = Type::NONE;
|
||||||
bool active = false;
|
bool active = false;
|
||||||
float target_width, target_height;
|
float target_width, target_height;
|
||||||
|
|||||||
@@ -26,13 +26,11 @@ void WindowMessage::render() {
|
|||||||
SDL_Renderer* renderer = Screen::get()->getRenderer();
|
SDL_Renderer* renderer = Screen::get()->getRenderer();
|
||||||
|
|
||||||
// Dibujar fondo con transparencia
|
// Dibujar fondo con transparencia
|
||||||
SDL_SetRenderDrawColor(renderer, config_.bg_color.r, config_.bg_color.g,
|
SDL_SetRenderDrawColor(renderer, config_.bg_color.r, config_.bg_color.g, config_.bg_color.b, config_.bg_color.a);
|
||||||
config_.bg_color.b, config_.bg_color.a);
|
|
||||||
SDL_RenderFillRect(renderer, &rect_);
|
SDL_RenderFillRect(renderer, &rect_);
|
||||||
|
|
||||||
// Dibujar borde
|
// Dibujar borde
|
||||||
SDL_SetRenderDrawColor(renderer, config_.border_color.r, config_.border_color.g,
|
SDL_SetRenderDrawColor(renderer, config_.border_color.r, config_.border_color.g, config_.border_color.b, config_.border_color.a);
|
||||||
config_.border_color.b, config_.border_color.a);
|
|
||||||
SDL_RenderRect(renderer, &rect_);
|
SDL_RenderRect(renderer, &rect_);
|
||||||
|
|
||||||
// Solo mostrar contenido si no estamos en animación de show/hide
|
// Solo mostrar contenido si no estamos en animación de show/hide
|
||||||
@@ -54,8 +52,7 @@ void WindowMessage::render() {
|
|||||||
|
|
||||||
// Línea separadora debajo del título (solo si hay título visible)
|
// Línea separadora debajo del título (solo si hay título visible)
|
||||||
if (!visible_title.empty()) {
|
if (!visible_title.empty()) {
|
||||||
SDL_SetRenderDrawColor(renderer, config_.border_color.r, config_.border_color.g,
|
SDL_SetRenderDrawColor(renderer, config_.border_color.r, config_.border_color.g, config_.border_color.b, config_.border_color.a);
|
||||||
config_.border_color.b, config_.border_color.a);
|
|
||||||
SDL_RenderLine(renderer,
|
SDL_RenderLine(renderer,
|
||||||
rect_.x + config_.padding,
|
rect_.x + config_.padding,
|
||||||
current_y - config_.title_separator_spacing / 2.0F,
|
current_y - config_.title_separator_spacing / 2.0F,
|
||||||
@@ -191,16 +188,14 @@ void WindowMessage::autoSize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WindowMessage::updateStyles() {
|
void WindowMessage::updateStyles() {
|
||||||
title_style_ = Text::Style(Text::CENTER | Text::COLOR, config_.title_color,
|
title_style_ = Text::Style(Text::CENTER | Text::COLOR, config_.title_color, config_.title_color, 0, -2);
|
||||||
config_.title_color, 0, -2);
|
text_style_ = Text::Style(Text::CENTER | Text::COLOR, config_.text_color, config_.text_color, 0, -2);
|
||||||
text_style_ = Text::Style(Text::CENTER | Text::COLOR, config_.text_color,
|
|
||||||
config_.text_color, 0, -2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowMessage::updatePosition() {
|
void WindowMessage::updatePosition() {
|
||||||
switch (position_mode_) {
|
switch (position_mode_) {
|
||||||
case PositionMode::CENTERED:
|
case PositionMode::CENTERED:
|
||||||
rect_.x = anchor_.x- rect_.w / 2.0F;
|
rect_.x = anchor_.x - rect_.w / 2.0F;
|
||||||
rect_.y = anchor_.y - rect_.h / 2.0F;
|
rect_.y = anchor_.y - rect_.h / 2.0F;
|
||||||
break;
|
break;
|
||||||
case PositionMode::FIXED:
|
case PositionMode::FIXED:
|
||||||
|
|||||||
@@ -83,15 +83,24 @@ class WindowMessage {
|
|||||||
// Configuración de colores
|
// Configuración de colores
|
||||||
void setBackgroundColor(const Color& color) { config_.bg_color = color; }
|
void setBackgroundColor(const Color& color) { config_.bg_color = color; }
|
||||||
void setBorderColor(const Color& color) { config_.border_color = color; }
|
void setBorderColor(const Color& color) { config_.border_color = color; }
|
||||||
void setTitleColor(const Color& color) { config_.title_color = color; updateStyles(); }
|
void setTitleColor(const Color& color) {
|
||||||
void setTextColor(const Color& color) { config_.text_color = color; updateStyles(); }
|
config_.title_color = color;
|
||||||
|
updateStyles();
|
||||||
|
}
|
||||||
|
void setTextColor(const Color& color) {
|
||||||
|
config_.text_color = color;
|
||||||
|
updateStyles();
|
||||||
|
}
|
||||||
|
|
||||||
// Configuración de espaciado
|
// Configuración de espaciado
|
||||||
void setPadding(float padding) { config_.padding = padding; }
|
void setPadding(float padding) { config_.padding = padding; }
|
||||||
void setLineSpacing(float spacing) { config_.line_spacing = spacing; }
|
void setLineSpacing(float spacing) { config_.line_spacing = spacing; }
|
||||||
|
|
||||||
// Configuración avanzada
|
// Configuración avanzada
|
||||||
void setConfig(const Config& config) { config_ = config; updateStyles(); }
|
void setConfig(const Config& config) {
|
||||||
|
config_ = config;
|
||||||
|
updateStyles();
|
||||||
|
}
|
||||||
[[nodiscard]] auto getConfig() const -> const Config& { return config_; }
|
[[nodiscard]] auto getConfig() const -> const Config& { return config_; }
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
@@ -148,7 +157,9 @@ class WindowMessage {
|
|||||||
|
|
||||||
// Animación de mostrar/ocultar
|
// Animación de mostrar/ocultar
|
||||||
struct ShowHideAnimation {
|
struct ShowHideAnimation {
|
||||||
enum class Type { NONE, SHOWING, HIDING };
|
enum class Type { NONE,
|
||||||
|
SHOWING,
|
||||||
|
HIDING };
|
||||||
|
|
||||||
Type type = Type::NONE;
|
Type type = Type::NONE;
|
||||||
bool active = false;
|
bool active = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user