afegit mode autoplay en debug
This commit is contained in:
@@ -230,6 +230,8 @@ void Director::loadDebugConfig() {
|
||||
out << "initial_stage: 0\n";
|
||||
out << "show_render_info: true\n";
|
||||
out << "resource_loading: preload\n";
|
||||
out << "autoplay: false\n";
|
||||
out << "invincibility: false\n";
|
||||
out.close();
|
||||
}
|
||||
// Usar defaults de DebugConfig
|
||||
@@ -263,6 +265,16 @@ void Director::loadDebugConfig() {
|
||||
debug_config.resource_loading = yaml["resource_loading"].get_value<std::string>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (yaml.contains("autoplay")) {
|
||||
try {
|
||||
debug_config.autoplay = yaml["autoplay"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (yaml.contains("invincibility")) {
|
||||
try {
|
||||
debug_config.invincibility = yaml["invincibility"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
}
|
||||
} catch (...) {
|
||||
std::cout << "Error parsing debug.yaml, using defaults" << '\n';
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ class Director {
|
||||
int initial_stage = 0;
|
||||
bool show_render_info = true;
|
||||
std::string resource_loading;
|
||||
bool autoplay = false;
|
||||
bool invincibility = false;
|
||||
|
||||
DebugConfig()
|
||||
: initial_section("game"),
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#ifdef _DEBUG
|
||||
#include <iostream> // Para basic_ostream, basic_ostream::operator<<, operator<<, cout
|
||||
|
||||
#include "core/system/director.hpp" // Para Director::debug_config
|
||||
#include "game/ui/notifier.hpp" // Para Notifier
|
||||
#endif
|
||||
|
||||
@@ -805,6 +806,12 @@ void Game::handlePlayerCollision(std::shared_ptr<Player>& player, std::shared_pt
|
||||
return; // Si no está jugando o tiene inmunidad, no hace nada
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (Director::debug_config.invincibility) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Si tiene cafes
|
||||
if (player->hasExtraHit()) {
|
||||
// Lo pierde
|
||||
@@ -1255,7 +1262,17 @@ void Game::checkInput() {
|
||||
// Comprueba las entradas si no está el menú de servicio activo
|
||||
if (!ServiceMenu::get()->isEnabled()) {
|
||||
checkPauseInput();
|
||||
demo_.enabled ? demoHandlePassInput() : handlePlayersInput();
|
||||
if (demo_.enabled) {
|
||||
demoHandlePassInput();
|
||||
} else {
|
||||
#ifdef _DEBUG
|
||||
if (!autoplay_) {
|
||||
handlePlayersInput();
|
||||
}
|
||||
#else
|
||||
handlePlayersInput();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Mueve los jugadores en el modo demo
|
||||
@@ -1263,6 +1280,12 @@ void Game::checkInput() {
|
||||
demoHandleInput();
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (autoplay_) {
|
||||
autoplayHandleInput();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Verifica los inputs globales.
|
||||
GlobalInputs::check();
|
||||
}
|
||||
@@ -1568,6 +1591,29 @@ void Game::initDemo(Player::Id player_id) {
|
||||
demo_.recording = false;
|
||||
#endif
|
||||
demo_.index = 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
autoplay_ = Director::debug_config.autoplay && !demo_.enabled;
|
||||
if (autoplay_) {
|
||||
auto const NUM_DEMOS = Asset::get()->getListByType(Asset::Type::DEMODATA).size();
|
||||
for (size_t num_demo = 0; num_demo < NUM_DEMOS; ++num_demo) {
|
||||
autoplay_data_.emplace_back(Resource::get()->getDemoData(num_demo));
|
||||
}
|
||||
|
||||
std::vector<size_t> demo_indices(NUM_DEMOS);
|
||||
std::iota(demo_indices.begin(), demo_indices.end(), 0);
|
||||
std::random_device rd;
|
||||
std::default_random_engine rng(rd());
|
||||
std::shuffle(demo_indices.begin(), demo_indices.end(), rng);
|
||||
|
||||
for (size_t i = 0; i < players_.size(); ++i) {
|
||||
size_t demo_index = demo_indices[i % NUM_DEMOS];
|
||||
players_.at(i)->setDemoFile(demo_index);
|
||||
}
|
||||
autoplay_elapsed_s_ = 0.0F;
|
||||
autoplay_index_ = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Inicializa el marcador
|
||||
@@ -1812,6 +1858,14 @@ void Game::updateGameStatePlaying(float delta_time) {
|
||||
if (auto_pop_balloons_) {
|
||||
stage_manager_->addPower(2);
|
||||
}
|
||||
if (autoplay_) {
|
||||
autoplay_elapsed_s_ += delta_time;
|
||||
autoplay_index_ = static_cast<int>(autoplay_elapsed_s_ * 60.0F);
|
||||
if (autoplay_index_ >= TOTAL_DEMO_DATA) {
|
||||
autoplay_elapsed_s_ = 0.0F;
|
||||
autoplay_index_ = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
updatePlayers(delta_time);
|
||||
checkPlayersStatusPlaying();
|
||||
@@ -2073,6 +2127,31 @@ void Game::bringPlayerToFront(Players& elements, const std::shared_ptr<Player>&
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Alimenta input de demo a los jugadores durante el autoplay
|
||||
void Game::autoplayHandleInput() {
|
||||
for (const auto& player : players_) {
|
||||
if (player->isPlaying()) {
|
||||
const auto& demo_data = autoplay_data_.at(player->getDemoFile()).at(autoplay_index_);
|
||||
|
||||
if (demo_data.left == 1) {
|
||||
player->setInput(Input::Action::LEFT);
|
||||
} else if (demo_data.right == 1) {
|
||||
player->setInput(Input::Action::RIGHT);
|
||||
} else if (demo_data.no_input == 1) {
|
||||
player->setInput(Input::Action::NONE);
|
||||
}
|
||||
|
||||
if (demo_data.fire == 1) {
|
||||
handleFireInput(player, Bullet::Type::UP);
|
||||
} else if (demo_data.fire_left == 1) {
|
||||
handleFireInput(player, Bullet::Type::LEFT);
|
||||
} else if (demo_data.fire_right == 1) {
|
||||
handleFireInput(player, Bullet::Type::RIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los eventos en el modo DEBUG
|
||||
void Game::handleDebugEvents(const SDL_Event& event) {
|
||||
static int formation_id_ = 0;
|
||||
|
||||
@@ -198,6 +198,10 @@ class Game {
|
||||
|
||||
#ifdef _DEBUG
|
||||
bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados
|
||||
bool autoplay_ = false; // Si es true, los jugadores se mueven solos con datos de demo
|
||||
float autoplay_elapsed_s_ = 0.0F;
|
||||
int autoplay_index_ = 0;
|
||||
std::vector<DemoData> autoplay_data_;
|
||||
#endif
|
||||
|
||||
// --- Ciclo principal del juego ---
|
||||
@@ -349,5 +353,6 @@ class Game {
|
||||
// --- Depuración (solo en modo DEBUG) ---
|
||||
#ifdef _DEBUG
|
||||
void handleDebugEvents(const SDL_Event& event); // Comprueba los eventos en el modo DEBUG
|
||||
void autoplayHandleInput(); // Alimenta input de demo a los jugadores en autoplay
|
||||
#endif
|
||||
};
|
||||
Reference in New Issue
Block a user