feat(entities): migrar la configuració del player a data/entities/player/player.yaml

This commit is contained in:
2026-05-25 08:32:49 +02:00
parent 9f278772bb
commit 6447932212
18 changed files with 396 additions and 121 deletions
+19 -4
View File
@@ -10,10 +10,12 @@
#include <iostream>
#include "core/audio/audio.hpp"
#include "core/entities/entity_loader.hpp"
#include "core/input/input.hpp"
#include "core/locale/locale.hpp"
#include "core/system/scene_context.hpp"
#include "core/system/service_menu.hpp"
#include "game/entities/player_config.hpp"
#include "game/stage_system/stage_loader.hpp"
#include "game/systems/collision_system.hpp"
#include "game/systems/continue_system.hpp"
@@ -49,9 +51,22 @@ GameScene::GameScene(SDLManager& sdl, SceneContext& context)
auto option = context_.consumeOption();
(void)option; // Suprimir warning de variable no usada
// Inicialitzar naves con renderer (P1=ship.shp, P2=ship2.shp)
ships_[0] = Ship(sdl.getRenderer(), "ship.shp"); // Jugador 1: nave estàndar
ships_[1] = Ship(sdl.getRenderer(), "ship2.shp"); // Jugador 2: interceptor con ales
// Carregar la configuració del player des de YAML. Sense fallback: si
// falla, abortem (la nau no és construïble sense paràmetres).
auto player_yaml = Entities::EntityLoader::load("player");
if (!player_yaml) {
std::cerr << "[GameScene] FATAL: no s'ha pogut carregar data/entities/player/player.yaml\n";
std::exit(EXIT_FAILURE);
}
auto player_config = PlayerConfig::fromYaml(*player_yaml);
if (!player_config) {
std::cerr << "[GameScene] FATAL: player.yaml mal format\n";
std::exit(EXIT_FAILURE);
}
// Inicialitzar naves: P1 amb el shape del YAML, P2 amb override visual.
ships_[0] = Ship(sdl.getRenderer(), *player_config); // Jugador 1: nau estàndard
ships_[1] = Ship(sdl.getRenderer(), *player_config, "ship2.shp"); // Jugador 2: interceptor amb ales
// Inicialitzar balas con renderer
std::ranges::fill(bullets_, Bullet(sdl.getRenderer()));
@@ -944,7 +959,7 @@ void GameScene::fireBullet(uint8_t player_id) {
const int START_IDX = player_id * SLOTS_PER_PLAYER;
for (int i = START_IDX; i < START_IDX + SLOTS_PER_PLAYER; i++) {
if (!bullets_[i].isActive()) {
bullets_[i].fire(fire_position, ship_angle, player_id);
bullets_[i].fire(fire_position, ship_angle, player_id, ships_[player_id].getConfig().weapon.bullet_speed);
break;
}
}