canvi i reinici d'escene en la consola
This commit is contained in:
@@ -358,6 +358,8 @@ void Director::runGame() {
|
||||
auto Director::run() -> int {
|
||||
// Bucle principal
|
||||
while (SceneManager::current != SceneManager::Scene::QUIT) {
|
||||
const SceneManager::Scene ACTIVE = SceneManager::current;
|
||||
|
||||
switch (SceneManager::current) {
|
||||
case SceneManager::Scene::LOGO:
|
||||
runLogo();
|
||||
@@ -395,9 +397,20 @@ auto Director::run() -> int {
|
||||
runEnding2();
|
||||
break;
|
||||
|
||||
case SceneManager::Scene::RESTART_CURRENT:
|
||||
// La escena salió por RESTART_CURRENT → relanzar la escena guardada
|
||||
SceneManager::current = SceneManager::scene_before_restart;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Si la escena que acaba de correr dejó RESTART_CURRENT pendiente,
|
||||
// restaurar la escena que estaba activa para relanzarla en la próxima iteración
|
||||
if (SceneManager::current == SceneManager::Scene::RESTART_CURRENT) {
|
||||
SceneManager::current = ACTIVE;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace SceneManager {
|
||||
GAME_OVER, // Pantalla de game over
|
||||
ENDING, // Final del juego (ending 1)
|
||||
ENDING2, // Final del juego (ending 2)
|
||||
RESTART_CURRENT, // Especial: reinicia la escena que estaba corriendo
|
||||
QUIT // Salir del programa
|
||||
};
|
||||
|
||||
@@ -40,5 +41,6 @@ namespace SceneManager {
|
||||
inline Scene current = Scene::LOGO; // Escena actual
|
||||
inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual
|
||||
#endif
|
||||
inline Scene scene_before_restart = Scene::LOGO; // escena a relanzar tras RESTART_CURRENT
|
||||
|
||||
} // namespace SceneManager
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "core/rendering/text.hpp" // Para Text
|
||||
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||
#include "game/options.hpp" // Para Options
|
||||
#include "game/scene_manager.hpp" // Para SceneManager
|
||||
|
||||
// ── Sistema de comandos ────────────────────────────────────────────────────────
|
||||
|
||||
@@ -62,18 +63,20 @@ static auto parseTokens(const std::string& input) -> std::vector<std::string> {
|
||||
// Texto de ayuda común para HELP y ?
|
||||
static void printHelp() {
|
||||
SDL_Log("=== JDD CONSOLE COMMANDS ===");
|
||||
SDL_Log(" SS [ON|OFF] Supersampling (Ctrl+F4)");
|
||||
SDL_Log(" POSTFX [ON|OFF|NEXT] Post-FX effects / next preset (F4/Shift+F4)");
|
||||
SDL_Log(" BORDER [ON|OFF] Decorative border (B)");
|
||||
SDL_Log(" FULLSCREEN [ON|OFF] Fullscreen mode (F3)");
|
||||
SDL_Log(" ZOOM [UP|DOWN] Window zoom (F1/F2)");
|
||||
SDL_Log(" INTSCALE [ON|OFF] Integer scaling (F7)");
|
||||
SDL_Log(" VSYNC [ON|OFF] Vertical sync");
|
||||
SDL_Log(" PALETTE [NEXT|PREV] Color palette (F5/F6)");
|
||||
SDL_Log(" SS [ON|OFF] Supersampling (Ctrl+F4)");
|
||||
SDL_Log(" POSTFX [ON|OFF|NEXT] Post-FX / next preset (F4/Shift+F4)");
|
||||
SDL_Log(" BORDER [ON|OFF] Decorative border (B)");
|
||||
SDL_Log(" FULLSCREEN [ON|OFF] Fullscreen mode (F3)");
|
||||
SDL_Log(" ZOOM [UP|DOWN] Window zoom (F1/F2)");
|
||||
SDL_Log(" INTSCALE [ON|OFF] Integer scaling (F7)");
|
||||
SDL_Log(" VSYNC [ON|OFF] Vertical sync");
|
||||
SDL_Log(" PALETTE [NEXT|PREV] Color palette (F5/F6)");
|
||||
#ifdef _DEBUG
|
||||
SDL_Log(" DEBUG Toggle debug overlay (F12)");
|
||||
SDL_Log(" DEBUG Toggle debug overlay (F12)");
|
||||
#endif
|
||||
SDL_Log(" HELP/? Show this help in terminal");
|
||||
SDL_Log(" SCENE [LOGO|LOADING|TITLE|CREDITS|GAME|ENDING|ENDING2|RESTART]");
|
||||
SDL_Log(" EXIT / QUIT Quit application");
|
||||
SDL_Log(" HELP/? Show this help in terminal");
|
||||
}
|
||||
|
||||
// Tabla de comandos disponibles
|
||||
@@ -175,6 +178,48 @@ static const std::vector<ConsoleCommand> COMMANDS = {
|
||||
}},
|
||||
#endif
|
||||
|
||||
// SCENE [LOGO|LOADING|TITLE|CREDITS|GAME|ENDING|ENDING2|RESTART] — Cambiar o reiniciar escena
|
||||
{.keyword = "SCENE", .execute = [](const std::vector<std::string>& args) -> std::string {
|
||||
if (args.empty()) { return "Usage: SCENE [LOGO|LOADING|TITLE|CREDITS|GAME|ENDING|ENDING2|RESTART]"; }
|
||||
|
||||
// RESTART: reinicia la escena actual (funciona desde cualquier escena)
|
||||
if (args[0] == "RESTART") {
|
||||
SceneManager::scene_before_restart = SceneManager::current;
|
||||
SceneManager::current = SceneManager::Scene::RESTART_CURRENT;
|
||||
return "Restarting...";
|
||||
}
|
||||
|
||||
// Para el resto: si pedimos la escena que ya está activa → también reiniciar
|
||||
const auto GO_TO = [](SceneManager::Scene target, const std::string& label) -> std::string {
|
||||
if (SceneManager::current == target) {
|
||||
SceneManager::scene_before_restart = target;
|
||||
SceneManager::current = SceneManager::Scene::RESTART_CURRENT;
|
||||
} else {
|
||||
SceneManager::current = target;
|
||||
}
|
||||
return "Scene: " + label;
|
||||
};
|
||||
|
||||
if (args[0] == "LOGO") { return GO_TO(SceneManager::Scene::LOGO, "Logo"); }
|
||||
if (args[0] == "LOADING") { return GO_TO(SceneManager::Scene::LOADING_SCREEN, "Loading"); }
|
||||
if (args[0] == "TITLE") { return GO_TO(SceneManager::Scene::TITLE, "Title"); }
|
||||
if (args[0] == "CREDITS") { return GO_TO(SceneManager::Scene::CREDITS, "Credits"); }
|
||||
if (args[0] == "GAME") { return GO_TO(SceneManager::Scene::GAME, "Game"); }
|
||||
if (args[0] == "ENDING") { return GO_TO(SceneManager::Scene::ENDING, "Ending"); }
|
||||
if (args[0] == "ENDING2") { return GO_TO(SceneManager::Scene::ENDING2, "Ending 2"); }
|
||||
return "Unknown scene: " + args[0];
|
||||
}},
|
||||
|
||||
// EXIT / QUIT — Cerrar la aplicacion
|
||||
{.keyword = "EXIT", .execute = [](const std::vector<std::string>&) -> std::string {
|
||||
SceneManager::current = SceneManager::Scene::QUIT;
|
||||
return "Quitting...";
|
||||
}},
|
||||
{.keyword = "QUIT", .execute = [](const std::vector<std::string>&) -> std::string {
|
||||
SceneManager::current = SceneManager::Scene::QUIT;
|
||||
return "Quitting...";
|
||||
}},
|
||||
|
||||
// HELP / ? — Muestra ayuda en la terminal del sistema
|
||||
{.keyword = "HELP", .execute = [](const std::vector<std::string>&) -> std::string {
|
||||
printHelp(); return "Help printed to terminal";
|
||||
@@ -321,8 +366,10 @@ void Console::toggle() {
|
||||
SDL_StartTextInput(SDL_GetKeyboardFocus());
|
||||
break;
|
||||
case Status::ACTIVE:
|
||||
status_ = Status::VANISHING;
|
||||
msg_line_ = std::string(CONSOLE_NAME) + " " + std::string(CONSOLE_VERSION);
|
||||
status_ = Status::VANISHING;
|
||||
msg_line_ = std::string(CONSOLE_NAME) + " " + std::string(CONSOLE_VERSION);
|
||||
history_index_ = -1;
|
||||
saved_input_.clear();
|
||||
SDL_StopTextInput(SDL_GetKeyboardFocus());
|
||||
break;
|
||||
default:
|
||||
@@ -343,11 +390,33 @@ void Console::handleEvent(const SDL_Event& event) {
|
||||
}
|
||||
|
||||
if (event.type == SDL_EVENT_KEY_DOWN) {
|
||||
if (event.key.scancode == SDL_SCANCODE_BACKSPACE && !input_line_.empty()) {
|
||||
input_line_.pop_back();
|
||||
} else if (event.key.scancode == SDL_SCANCODE_RETURN ||
|
||||
event.key.scancode == SDL_SCANCODE_KP_ENTER) {
|
||||
processCommand();
|
||||
switch (event.key.scancode) {
|
||||
case SDL_SCANCODE_BACKSPACE:
|
||||
if (!input_line_.empty()) { input_line_.pop_back(); }
|
||||
break;
|
||||
case SDL_SCANCODE_RETURN:
|
||||
case SDL_SCANCODE_KP_ENTER:
|
||||
processCommand();
|
||||
break;
|
||||
case SDL_SCANCODE_UP:
|
||||
// Navegar hacia atrás en el historial
|
||||
if (history_index_ < static_cast<int>(history_.size()) - 1) {
|
||||
if (history_index_ == -1) { saved_input_ = input_line_; }
|
||||
++history_index_;
|
||||
input_line_ = history_[static_cast<size_t>(history_index_)];
|
||||
}
|
||||
break;
|
||||
case SDL_SCANCODE_DOWN:
|
||||
// Navegar hacia el presente en el historial
|
||||
if (history_index_ >= 0) {
|
||||
--history_index_;
|
||||
input_line_ = (history_index_ == -1)
|
||||
? saved_input_
|
||||
: history_[static_cast<size_t>(history_index_)];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,6 +424,14 @@ void Console::handleEvent(const SDL_Event& event) {
|
||||
// Ejecuta el comando introducido y reinicia la línea de input
|
||||
void Console::processCommand() {
|
||||
if (!input_line_.empty()) {
|
||||
// Añadir al historial (sin duplicados consecutivos)
|
||||
if (history_.empty() || history_.front() != input_line_) {
|
||||
history_.push_front(input_line_);
|
||||
if (static_cast<int>(history_.size()) > MAX_HISTORY_SIZE) {
|
||||
history_.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
const auto TOKENS = parseTokens(input_line_);
|
||||
if (!TOKENS.empty()) {
|
||||
const std::string& cmd = TOKENS[0];
|
||||
@@ -376,6 +453,8 @@ void Console::processCommand() {
|
||||
}
|
||||
}
|
||||
input_line_.clear();
|
||||
history_index_ = -1;
|
||||
saved_input_.clear();
|
||||
cursor_timer_ = 0.0F;
|
||||
cursor_visible_ = true;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <deque> // Para deque (historial)
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
|
||||
@@ -43,9 +44,10 @@ class Console {
|
||||
// Constantes de consola
|
||||
static constexpr std::string_view CONSOLE_NAME = "JDD Console";
|
||||
static constexpr std::string_view CONSOLE_VERSION = "v1.0";
|
||||
static constexpr int MAX_LINE_CHARS = 28;
|
||||
static constexpr float CURSOR_ON_TIME = 0.5F;
|
||||
static constexpr float CURSOR_OFF_TIME = 0.3F;
|
||||
static constexpr int MAX_LINE_CHARS = 28;
|
||||
static constexpr int MAX_HISTORY_SIZE = 20;
|
||||
static constexpr float CURSOR_ON_TIME = 0.5F;
|
||||
static constexpr float CURSOR_OFF_TIME = 0.3F;
|
||||
|
||||
// [SINGLETON]
|
||||
static Console* console;
|
||||
@@ -74,4 +76,9 @@ class Console {
|
||||
std::string input_line_;
|
||||
float cursor_timer_{0.0F};
|
||||
bool cursor_visible_{true};
|
||||
|
||||
// Historial de comandos (navegable con flechas arriba/abajo)
|
||||
std::deque<std::string> history_;
|
||||
int history_index_{-1}; // -1 = en la entrada actual (presente)
|
||||
std::string saved_input_; // guarda input_line_ al empezar a navegar
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user