Lint: rename públicos al inglés + refactor cognitive-complexity + unused-includes
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>
This commit is contained in:
+89
-167
@@ -224,119 +224,71 @@ void setConfigFile(const std::string& path) { config_file_path = path; }
|
||||
|
||||
// Funciones auxiliars per load seccions del YAML
|
||||
|
||||
// Lee un campo escalar del YAML aplicando un validador; si la clau no
|
||||
// existe, deja `dest` intacto; si la conversió o la validació fallen,
|
||||
// asigna `fallback`. Estàtic per quedar dins de la unitat de traducció.
|
||||
template <typename T, typename Validator>
|
||||
static void readField(const fkyaml::node& parent, const char* key, T& dest,
|
||||
T fallback, Validator&& validate) {
|
||||
if (!parent.contains(key)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
auto val = parent[key].template get_value<T>();
|
||||
dest = validate(val) ? val : fallback;
|
||||
} catch (...) {
|
||||
dest = fallback;
|
||||
}
|
||||
}
|
||||
|
||||
// Variant sin validador: només lectura amb fallback en cas d'error.
|
||||
template <typename T>
|
||||
static void readField(const fkyaml::node& parent, const char* key, T& dest, T fallback) {
|
||||
if (!parent.contains(key)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
dest = parent[key].template get_value<T>();
|
||||
} catch (...) {
|
||||
dest = fallback;
|
||||
}
|
||||
}
|
||||
|
||||
static void loadWindowConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (yaml.contains("window")) {
|
||||
const auto& win = yaml["window"];
|
||||
if (!yaml.contains("window")) {
|
||||
return;
|
||||
}
|
||||
const auto& win = yaml["window"];
|
||||
|
||||
if (win.contains("width")) {
|
||||
try {
|
||||
auto val = win["width"].get_value<int>();
|
||||
window.width = (val >= Defaults::Window::MIN_WIDTH)
|
||||
? val
|
||||
: Defaults::Window::WIDTH;
|
||||
} catch (...) {
|
||||
window.width = Defaults::Window::WIDTH;
|
||||
}
|
||||
}
|
||||
readField(win, "width", window.width, Defaults::Window::WIDTH,
|
||||
[](int v) { return v >= Defaults::Window::MIN_WIDTH; });
|
||||
readField(win, "height", window.height, Defaults::Window::HEIGHT,
|
||||
[](int v) { return v >= Defaults::Window::MIN_HEIGHT; });
|
||||
readField(win, "fullscreen", window.fullscreen, false);
|
||||
|
||||
if (win.contains("height")) {
|
||||
try {
|
||||
auto val = win["height"].get_value<int>();
|
||||
window.height = (val >= Defaults::Window::MIN_HEIGHT)
|
||||
? val
|
||||
: Defaults::Window::HEIGHT;
|
||||
} catch (...) {
|
||||
window.height = Defaults::Window::HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
if (win.contains("fullscreen")) {
|
||||
try {
|
||||
window.fullscreen = win["fullscreen"].get_value<bool>();
|
||||
} catch (...) {
|
||||
window.fullscreen = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (win.contains("zoom_factor")) {
|
||||
try {
|
||||
auto val = win["zoom_factor"].get_value<float>();
|
||||
window.zoom_factor = (val >= Defaults::Window::MIN_ZOOM && val <= 10.0F)
|
||||
? val
|
||||
: Defaults::Window::BASE_ZOOM;
|
||||
} catch (...) {
|
||||
window.zoom_factor = Defaults::Window::BASE_ZOOM;
|
||||
}
|
||||
} else {
|
||||
// Legacy config: infer zoom from width
|
||||
window.zoom_factor = static_cast<float>(window.width) / Defaults::Window::WIDTH;
|
||||
window.zoom_factor = std::max(Defaults::Window::MIN_ZOOM, window.zoom_factor);
|
||||
}
|
||||
if (win.contains("zoom_factor")) {
|
||||
readField(win, "zoom_factor", window.zoom_factor, Defaults::Window::BASE_ZOOM,
|
||||
[](float v) { return v >= Defaults::Window::MIN_ZOOM && v <= 10.0F; });
|
||||
} else {
|
||||
// Legacy config: infer zoom from width
|
||||
window.zoom_factor = static_cast<float>(window.width) / Defaults::Window::WIDTH;
|
||||
window.zoom_factor = std::max(Defaults::Window::MIN_ZOOM, window.zoom_factor);
|
||||
}
|
||||
}
|
||||
|
||||
static void loadPhysicsConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (yaml.contains("physics")) {
|
||||
const auto& phys = yaml["physics"];
|
||||
|
||||
if (phys.contains("rotation_speed")) {
|
||||
try {
|
||||
auto val = phys["rotation_speed"].get_value<float>();
|
||||
physics.rotation_speed =
|
||||
(val > 0) ? val : Defaults::Physics::ROTATION_SPEED;
|
||||
} catch (...) {
|
||||
physics.rotation_speed = Defaults::Physics::ROTATION_SPEED;
|
||||
}
|
||||
}
|
||||
|
||||
if (phys.contains("acceleration")) {
|
||||
try {
|
||||
auto val = phys["acceleration"].get_value<float>();
|
||||
physics.acceleration =
|
||||
(val > 0) ? val : Defaults::Physics::ACCELERATION;
|
||||
} catch (...) {
|
||||
physics.acceleration = Defaults::Physics::ACCELERATION;
|
||||
}
|
||||
}
|
||||
|
||||
if (phys.contains("max_velocity")) {
|
||||
try {
|
||||
auto val = phys["max_velocity"].get_value<float>();
|
||||
physics.max_velocity =
|
||||
(val > 0) ? val : Defaults::Physics::MAX_VELOCITY;
|
||||
} catch (...) {
|
||||
physics.max_velocity = Defaults::Physics::MAX_VELOCITY;
|
||||
}
|
||||
}
|
||||
|
||||
if (phys.contains("friction")) {
|
||||
try {
|
||||
auto val = phys["friction"].get_value<float>();
|
||||
physics.friction = (val > 0) ? val : Defaults::Physics::FRICTION;
|
||||
} catch (...) {
|
||||
physics.friction = Defaults::Physics::FRICTION;
|
||||
}
|
||||
}
|
||||
|
||||
if (phys.contains("enemy_speed")) {
|
||||
try {
|
||||
auto val = phys["enemy_speed"].get_value<float>();
|
||||
physics.enemy_speed = (val > 0) ? val : Defaults::Physics::ENEMY_SPEED;
|
||||
} catch (...) {
|
||||
physics.enemy_speed = Defaults::Physics::ENEMY_SPEED;
|
||||
}
|
||||
}
|
||||
|
||||
if (phys.contains("bullet_speed")) {
|
||||
try {
|
||||
auto val = phys["bullet_speed"].get_value<float>();
|
||||
physics.bullet_speed =
|
||||
(val > 0) ? val : Defaults::Physics::BULLET_SPEED;
|
||||
} catch (...) {
|
||||
physics.bullet_speed = Defaults::Physics::BULLET_SPEED;
|
||||
}
|
||||
}
|
||||
if (!yaml.contains("physics")) {
|
||||
return;
|
||||
}
|
||||
const auto& phys = yaml["physics"];
|
||||
constexpr auto POSITIVE = [](float v) { return v > 0.0F; };
|
||||
|
||||
readField(phys, "rotation_speed", physics.rotation_speed, Defaults::Physics::ROTATION_SPEED, POSITIVE);
|
||||
readField(phys, "acceleration", physics.acceleration, Defaults::Physics::ACCELERATION, POSITIVE);
|
||||
readField(phys, "max_velocity", physics.max_velocity, Defaults::Physics::MAX_VELOCITY, POSITIVE);
|
||||
readField(phys, "friction", physics.friction, Defaults::Physics::FRICTION, POSITIVE);
|
||||
readField(phys, "enemy_speed", physics.enemy_speed, Defaults::Physics::ENEMY_SPEED, POSITIVE);
|
||||
readField(phys, "bullet_speed", physics.bullet_speed, Defaults::Physics::BULLET_SPEED, POSITIVE);
|
||||
}
|
||||
|
||||
static void loadGameplayConfigFromYaml(const fkyaml::node& yaml) {
|
||||
@@ -381,69 +333,39 @@ static void loadRenderingConfigFromYaml(const fkyaml::node& yaml) {
|
||||
}
|
||||
}
|
||||
|
||||
static void loadAudioConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (yaml.contains("audio")) {
|
||||
const auto& aud = yaml["audio"];
|
||||
|
||||
if (aud.contains("enabled")) {
|
||||
try {
|
||||
audio.enabled = aud["enabled"].get_value<bool>();
|
||||
} catch (...) {
|
||||
audio.enabled = Defaults::Audio::ENABLED;
|
||||
}
|
||||
}
|
||||
|
||||
if (aud.contains("volume")) {
|
||||
try {
|
||||
auto val = aud["volume"].get_value<float>();
|
||||
audio.volume = (val >= 0.0F && val <= 1.0F) ? val : Defaults::Audio::VOLUME;
|
||||
} catch (...) {
|
||||
audio.volume = Defaults::Audio::VOLUME;
|
||||
}
|
||||
}
|
||||
|
||||
if (aud.contains("music")) {
|
||||
const auto& mus = aud["music"];
|
||||
|
||||
if (mus.contains("enabled")) {
|
||||
try {
|
||||
audio.music.enabled = mus["enabled"].get_value<bool>();
|
||||
} catch (...) {
|
||||
audio.music.enabled = Defaults::Audio::MUSIC_ENABLED;
|
||||
}
|
||||
}
|
||||
|
||||
if (mus.contains("volume")) {
|
||||
try {
|
||||
auto val = mus["volume"].get_value<float>();
|
||||
audio.music.volume = (val >= 0.0F && val <= 1.0F) ? val : Defaults::Audio::MUSIC_VOLUME;
|
||||
} catch (...) {
|
||||
audio.music.volume = Defaults::Audio::MUSIC_VOLUME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (aud.contains("sound")) {
|
||||
const auto& snd = aud["sound"];
|
||||
|
||||
if (snd.contains("enabled")) {
|
||||
try {
|
||||
audio.sound.enabled = snd["enabled"].get_value<bool>();
|
||||
} catch (...) {
|
||||
audio.sound.enabled = Defaults::Audio::SOUND_ENABLED;
|
||||
}
|
||||
}
|
||||
|
||||
if (snd.contains("volume")) {
|
||||
try {
|
||||
auto val = snd["volume"].get_value<float>();
|
||||
audio.sound.volume = (val >= 0.0F && val <= 1.0F) ? val : Defaults::Audio::SOUND_VOLUME;
|
||||
} catch (...) {
|
||||
audio.sound.volume = Defaults::Audio::SOUND_VOLUME;
|
||||
}
|
||||
}
|
||||
}
|
||||
static void loadAudioMusicSection(const fkyaml::node& aud) {
|
||||
if (!aud.contains("music")) {
|
||||
return;
|
||||
}
|
||||
const auto& mus = aud["music"];
|
||||
constexpr auto UNIT_RANGE = [](float v) { return v >= 0.0F && v <= 1.0F; };
|
||||
|
||||
readField(mus, "enabled", audio.music.enabled, Defaults::Audio::MUSIC_ENABLED);
|
||||
readField(mus, "volume", audio.music.volume, Defaults::Audio::MUSIC_VOLUME, UNIT_RANGE);
|
||||
}
|
||||
|
||||
static void loadAudioSoundSection(const fkyaml::node& aud) {
|
||||
if (!aud.contains("sound")) {
|
||||
return;
|
||||
}
|
||||
const auto& snd = aud["sound"];
|
||||
constexpr auto UNIT_RANGE = [](float v) { return v >= 0.0F && v <= 1.0F; };
|
||||
|
||||
readField(snd, "enabled", audio.sound.enabled, Defaults::Audio::SOUND_ENABLED);
|
||||
readField(snd, "volume", audio.sound.volume, Defaults::Audio::SOUND_VOLUME, UNIT_RANGE);
|
||||
}
|
||||
|
||||
static void loadAudioConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("audio")) {
|
||||
return;
|
||||
}
|
||||
const auto& aud = yaml["audio"];
|
||||
constexpr auto UNIT_RANGE = [](float v) { return v >= 0.0F && v <= 1.0F; };
|
||||
|
||||
readField(aud, "enabled", audio.enabled, Defaults::Audio::ENABLED);
|
||||
readField(aud, "volume", audio.volume, Defaults::Audio::VOLUME, UNIT_RANGE);
|
||||
loadAudioMusicSection(aud);
|
||||
loadAudioSoundSection(aud);
|
||||
}
|
||||
|
||||
// Carregar controls del player 1 desde YAML
|
||||
|
||||
Reference in New Issue
Block a user