bbbb8d47ae
Identifier-naming: rename de métodos públicos y cross-file al inglés
(camelBack), traducción de campos y locales en el proceso (TitleShip,
StageManager, SpawnController, ShipAnimator, helpers de PlayArea, etc.).
Refactor por cognitive-complexity (>25): GameScene::draw (59→3) con 9
helpers de estado, PhysicsWorld::resolveBodyCollisions (35→5) extrayendo
resolveBodyPair, Options::load{Window,Physics,Audio}ConfigFromYaml
(32/49/57→5/2/3) con templates readField, TitleScene::update (68→4) con
5 sub-pasos por estado + handleSkipInput/handleStartInput +
triggerExitForJoinedPlayers, DebrisManager::explode (39→3) con
extractSegments/spawnDebris/applyAngularVelocity/applyVisualRotation.
use-anyofallof: bucles → std::ranges::any_of/all_of en Input,
ShipAnimator y SpawnController.
readability-static-accessed-through-instance: Director::run y
VectorText::getTextWidth/Height invocados por clase.
readability-convert-member-functions-to-static: ResourcePack::decryptData.
unused-includes: eliminación de <utility>, <cstdint>, <vector>,
<iostream>, defaults.hpp y otros no usados directamente en headers y
unidades de traducción. Restablecido core/defaults.hpp en title_scene.cpp
(falsa "unused" del header).
Bug fix: eliminado isActive() duplicado en Bullet (redeclaración tras
rename de esta_activa→isActive que chocaba con el override de Entity).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
91 lines
2.5 KiB
C++
91 lines
2.5 KiB
C++
// path_utils.cpp - Implementació de utilitats de rutes
|
|
// © 2026 JailDesigner
|
|
|
|
#include "path_utils.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <filesystem>
|
|
#include <iostream>
|
|
|
|
namespace Utils {
|
|
|
|
// Variables globals per guardar argv[0]
|
|
static std::string executable_path;
|
|
static std::string executable_directory;
|
|
|
|
// Inicialitzar el sistema de rutes con argv[0]
|
|
void initializePathSystem(const char* argv0) {
|
|
if (argv0 == nullptr) {
|
|
std::cerr << "[PathUtils] ADVERTÈNCIA: argv[0] es nullptr\n";
|
|
executable_path = "";
|
|
executable_directory = ".";
|
|
return;
|
|
}
|
|
|
|
executable_path = argv0;
|
|
|
|
// Extreure el directori
|
|
std::filesystem::path path(argv0);
|
|
executable_directory = path.parent_path().string();
|
|
|
|
if (executable_directory.empty()) {
|
|
executable_directory = ".";
|
|
}
|
|
|
|
std::cout << "[PathUtils] Executable: " << executable_path << "\n";
|
|
std::cout << "[PathUtils] Directori: " << executable_directory << "\n";
|
|
}
|
|
|
|
// Obtenir el directori de l'executable
|
|
auto getExecutableDirectory() -> std::string {
|
|
if (executable_directory.empty()) {
|
|
std::cerr << "[PathUtils] ADVERTÈNCIA: Sistema de rutes no inicialitzat\n";
|
|
return ".";
|
|
}
|
|
return executable_directory;
|
|
}
|
|
|
|
// Detectar si estem dins un bundle de macOS
|
|
auto isMacOSBundle() -> bool {
|
|
#ifdef MACOS_BUNDLE
|
|
return true;
|
|
#else
|
|
// Detecció en time de execució
|
|
// Cercar ".app/Contents/MacOS" a la ruta de l'executable
|
|
std::string exe_dir = getExecutableDirectory();
|
|
return exe_dir.find(".app/Contents/MacOS") != std::string::npos;
|
|
#endif
|
|
}
|
|
|
|
// Obtenir la ruta base dels recursos
|
|
auto getResourceBasePath() -> std::string {
|
|
std::string exe_dir = getExecutableDirectory();
|
|
|
|
if (isMacOSBundle()) {
|
|
// Bundle de macOS: recursos a ../Resources desde MacOS/
|
|
std::cout << "[PathUtils] Detectat bundle de macOS\n";
|
|
return exe_dir + "/../Resources";
|
|
} // Executable normal: recursos al mismo directori
|
|
return exe_dir;
|
|
}
|
|
|
|
// Normalitzar ruta (convertir barres, etc.)
|
|
auto normalizePath(const std::string& path) -> std::string {
|
|
std::string normalized = path;
|
|
|
|
// Convertir barres invertides a normals
|
|
std::ranges::replace(normalized, '\\', '/');
|
|
|
|
// Simplificar rutes con filesystem
|
|
try {
|
|
std::filesystem::path fs_path(normalized);
|
|
normalized = fs_path.lexically_normal().string();
|
|
} catch (const std::exception& e) {
|
|
std::cerr << "[PathUtils] Error normalitzant ruta: " << e.what() << "\n";
|
|
}
|
|
|
|
return normalized;
|
|
}
|
|
|
|
} // namespace Utils
|