claude: arreglos d'estil

This commit is contained in:
2025-08-16 19:48:32 +02:00
parent 1ced698093
commit ada5025c65
62 changed files with 903 additions and 1102 deletions

View File

@@ -5,18 +5,18 @@
#include <string>
#include <utility>
// Clase dedicada para manejar el sistema de pausa
// --- Clase PauseManager: maneja el sistema de pausa del juego ---
class PauseManager {
public:
// Enum encapsulado dentro de la clase
enum class Source : uint8_t {
// --- Enums ---
enum class Source : uint8_t { // Fuentes de pausa
NONE = 0,
PLAYER = 1 << 0, // 0001
SERVICE_MENU = 1 << 1, // 0010
FOCUS_LOST = 1 << 2 // 0100
};
// Operadores para trabajar con las banderas (funciones friend)
// --- Operadores friend ---
friend auto operator|(Source a, Source b) -> Source {
return static_cast<Source>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
}
@@ -42,27 +42,12 @@ class PauseManager {
return a = a & b;
}
private:
Source flags_ = Source::NONE;
std::function<void(bool)> on_pause_changed_callback_;
[[nodiscard]] auto hasFlag(Source flag) const -> bool {
return (flags_ & flag) != Source::NONE;
}
void notifyPauseChanged() {
if (on_pause_changed_callback_) {
on_pause_changed_callback_(isPaused());
}
}
public:
// Constructor con callback opcional
explicit PauseManager(std::function<void(bool)> callback = nullptr)
// --- Constructor y destructor ---
explicit PauseManager(std::function<void(bool)> callback = nullptr) // Constructor con callback opcional
: on_pause_changed_callback_(std::move(callback)) {}
// Establece/quita una fuente de pausa específica
void setFlag(Source source, bool enable) {
// --- Métodos principales ---
void setFlag(Source source, bool enable) { // Establece/quita una fuente de pausa específica
bool was_paused = isPaused();
if (enable) {
@@ -76,33 +61,29 @@ class PauseManager {
}
}
// Métodos específicos para cada fuente
// --- Métodos específicos para cada fuente ---
void setPlayerPause(bool enable) { setFlag(Source::PLAYER, enable); }
void setServiceMenuPause(bool enable) { setFlag(Source::SERVICE_MENU, enable); }
void setFocusLossPause(bool enable) { setFlag(Source::FOCUS_LOST, enable); }
// Toggle para el jugador (más común)
void togglePlayerPause() { setPlayerPause(!isPlayerPaused()); }
void togglePlayerPause() { setPlayerPause(!isPlayerPaused()); } // Toggle para el jugador (más común)
// Getters
// --- Getters ---
[[nodiscard]] auto isPaused() const -> bool { return flags_ != Source::NONE; }
[[nodiscard]] auto isPlayerPaused() const -> bool { return hasFlag(Source::PLAYER); }
[[nodiscard]] auto isServiceMenuPaused() const -> bool { return hasFlag(Source::SERVICE_MENU); }
[[nodiscard]] auto isFocusLossPaused() const -> bool { return hasFlag(Source::FOCUS_LOST); }
// Obtiene las banderas actuales
[[nodiscard]] auto getFlags() const -> Source { return flags_; }
[[nodiscard]] auto getFlags() const -> Source { return flags_; } // Obtiene las banderas actuales
// Limpia todas las pausas (útil para reset)
void clearAll() {
// --- Métodos de utilidad ---
void clearAll() { // Limpia todas las pausas (útil para reset)
if (isPaused()) {
flags_ = Source::NONE;
notifyPauseChanged();
}
}
// Método para debug
[[nodiscard]] auto getStatusString() const -> std::string {
[[nodiscard]] auto getStatusString() const -> std::string { // Método para debug
if (flags_ == Source::NONE) {
return "Active";
}
@@ -133,9 +114,22 @@ class PauseManager {
return result;
}
// Permite cambiar el callback en runtime
void setCallback(std::function<void(bool)> callback) {
void setCallback(std::function<void(bool)> callback) { // Permite cambiar el callback en runtime
on_pause_changed_callback_ = callback;
}
private:
// --- Variables ---
Source flags_ = Source::NONE;
std::function<void(bool)> on_pause_changed_callback_;
// --- Métodos internos ---
[[nodiscard]] auto hasFlag(Source flag) const -> bool {
return (flags_ & flag) != Source::NONE;
}
void notifyPauseChanged() {
if (on_pause_changed_callback_) {
on_pause_changed_callback_(isPaused());
}
}
};