canvi i reinici d'escene en la consola
This commit is contained in:
@@ -358,6 +358,8 @@ void Director::runGame() {
|
|||||||
auto Director::run() -> int {
|
auto Director::run() -> int {
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
while (SceneManager::current != SceneManager::Scene::QUIT) {
|
while (SceneManager::current != SceneManager::Scene::QUIT) {
|
||||||
|
const SceneManager::Scene ACTIVE = SceneManager::current;
|
||||||
|
|
||||||
switch (SceneManager::current) {
|
switch (SceneManager::current) {
|
||||||
case SceneManager::Scene::LOGO:
|
case SceneManager::Scene::LOGO:
|
||||||
runLogo();
|
runLogo();
|
||||||
@@ -395,9 +397,20 @@ auto Director::run() -> int {
|
|||||||
runEnding2();
|
runEnding2();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SceneManager::Scene::RESTART_CURRENT:
|
||||||
|
// La escena salió por RESTART_CURRENT → relanzar la escena guardada
|
||||||
|
SceneManager::current = SceneManager::scene_before_restart;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
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;
|
return 0;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace SceneManager {
|
|||||||
GAME_OVER, // Pantalla de game over
|
GAME_OVER, // Pantalla de game over
|
||||||
ENDING, // Final del juego (ending 1)
|
ENDING, // Final del juego (ending 1)
|
||||||
ENDING2, // Final del juego (ending 2)
|
ENDING2, // Final del juego (ending 2)
|
||||||
|
RESTART_CURRENT, // Especial: reinicia la escena que estaba corriendo
|
||||||
QUIT // Salir del programa
|
QUIT // Salir del programa
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -40,5 +41,6 @@ namespace SceneManager {
|
|||||||
inline Scene current = Scene::LOGO; // Escena actual
|
inline Scene current = Scene::LOGO; // Escena actual
|
||||||
inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual
|
inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual
|
||||||
#endif
|
#endif
|
||||||
|
inline Scene scene_before_restart = Scene::LOGO; // escena a relanzar tras RESTART_CURRENT
|
||||||
|
|
||||||
} // namespace SceneManager
|
} // namespace SceneManager
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "core/rendering/text.hpp" // Para Text
|
#include "core/rendering/text.hpp" // Para Text
|
||||||
#include "core/resources/resource_cache.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "game/options.hpp" // Para Options
|
#include "game/options.hpp" // Para Options
|
||||||
|
#include "game/scene_manager.hpp" // Para SceneManager
|
||||||
|
|
||||||
// ── Sistema de comandos ────────────────────────────────────────────────────────
|
// ── Sistema de comandos ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ static auto parseTokens(const std::string& input) -> std::vector<std::string> {
|
|||||||
static void printHelp() {
|
static void printHelp() {
|
||||||
SDL_Log("=== JDD CONSOLE COMMANDS ===");
|
SDL_Log("=== JDD CONSOLE COMMANDS ===");
|
||||||
SDL_Log(" SS [ON|OFF] Supersampling (Ctrl+F4)");
|
SDL_Log(" SS [ON|OFF] Supersampling (Ctrl+F4)");
|
||||||
SDL_Log(" POSTFX [ON|OFF|NEXT] Post-FX effects / next preset (F4/Shift+F4)");
|
SDL_Log(" POSTFX [ON|OFF|NEXT] Post-FX / next preset (F4/Shift+F4)");
|
||||||
SDL_Log(" BORDER [ON|OFF] Decorative border (B)");
|
SDL_Log(" BORDER [ON|OFF] Decorative border (B)");
|
||||||
SDL_Log(" FULLSCREEN [ON|OFF] Fullscreen mode (F3)");
|
SDL_Log(" FULLSCREEN [ON|OFF] Fullscreen mode (F3)");
|
||||||
SDL_Log(" ZOOM [UP|DOWN] Window zoom (F1/F2)");
|
SDL_Log(" ZOOM [UP|DOWN] Window zoom (F1/F2)");
|
||||||
@@ -73,6 +74,8 @@ static void printHelp() {
|
|||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
SDL_Log(" DEBUG Toggle debug overlay (F12)");
|
SDL_Log(" DEBUG Toggle debug overlay (F12)");
|
||||||
#endif
|
#endif
|
||||||
|
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");
|
SDL_Log(" HELP/? Show this help in terminal");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,6 +178,48 @@ static const std::vector<ConsoleCommand> COMMANDS = {
|
|||||||
}},
|
}},
|
||||||
#endif
|
#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
|
// HELP / ? — Muestra ayuda en la terminal del sistema
|
||||||
{.keyword = "HELP", .execute = [](const std::vector<std::string>&) -> std::string {
|
{.keyword = "HELP", .execute = [](const std::vector<std::string>&) -> std::string {
|
||||||
printHelp(); return "Help printed to terminal";
|
printHelp(); return "Help printed to terminal";
|
||||||
@@ -323,6 +368,8 @@ void Console::toggle() {
|
|||||||
case Status::ACTIVE:
|
case Status::ACTIVE:
|
||||||
status_ = Status::VANISHING;
|
status_ = Status::VANISHING;
|
||||||
msg_line_ = std::string(CONSOLE_NAME) + " " + std::string(CONSOLE_VERSION);
|
msg_line_ = std::string(CONSOLE_NAME) + " " + std::string(CONSOLE_VERSION);
|
||||||
|
history_index_ = -1;
|
||||||
|
saved_input_.clear();
|
||||||
SDL_StopTextInput(SDL_GetKeyboardFocus());
|
SDL_StopTextInput(SDL_GetKeyboardFocus());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -343,11 +390,33 @@ void Console::handleEvent(const SDL_Event& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.type == SDL_EVENT_KEY_DOWN) {
|
if (event.type == SDL_EVENT_KEY_DOWN) {
|
||||||
if (event.key.scancode == SDL_SCANCODE_BACKSPACE && !input_line_.empty()) {
|
switch (event.key.scancode) {
|
||||||
input_line_.pop_back();
|
case SDL_SCANCODE_BACKSPACE:
|
||||||
} else if (event.key.scancode == SDL_SCANCODE_RETURN ||
|
if (!input_line_.empty()) { input_line_.pop_back(); }
|
||||||
event.key.scancode == SDL_SCANCODE_KP_ENTER) {
|
break;
|
||||||
|
case SDL_SCANCODE_RETURN:
|
||||||
|
case SDL_SCANCODE_KP_ENTER:
|
||||||
processCommand();
|
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
|
// Ejecuta el comando introducido y reinicia la línea de input
|
||||||
void Console::processCommand() {
|
void Console::processCommand() {
|
||||||
if (!input_line_.empty()) {
|
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_);
|
const auto TOKENS = parseTokens(input_line_);
|
||||||
if (!TOKENS.empty()) {
|
if (!TOKENS.empty()) {
|
||||||
const std::string& cmd = TOKENS[0];
|
const std::string& cmd = TOKENS[0];
|
||||||
@@ -376,6 +453,8 @@ void Console::processCommand() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
input_line_.clear();
|
input_line_.clear();
|
||||||
|
history_index_ = -1;
|
||||||
|
saved_input_.clear();
|
||||||
cursor_timer_ = 0.0F;
|
cursor_timer_ = 0.0F;
|
||||||
cursor_visible_ = true;
|
cursor_visible_ = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
#include <deque> // Para deque (historial)
|
||||||
#include <memory> // Para shared_ptr
|
#include <memory> // Para shared_ptr
|
||||||
#include <string> // Para string
|
#include <string> // Para string
|
||||||
|
|
||||||
@@ -44,6 +45,7 @@ class Console {
|
|||||||
static constexpr std::string_view CONSOLE_NAME = "JDD Console";
|
static constexpr std::string_view CONSOLE_NAME = "JDD Console";
|
||||||
static constexpr std::string_view CONSOLE_VERSION = "v1.0";
|
static constexpr std::string_view CONSOLE_VERSION = "v1.0";
|
||||||
static constexpr int MAX_LINE_CHARS = 28;
|
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_ON_TIME = 0.5F;
|
||||||
static constexpr float CURSOR_OFF_TIME = 0.3F;
|
static constexpr float CURSOR_OFF_TIME = 0.3F;
|
||||||
|
|
||||||
@@ -74,4 +76,9 @@ class Console {
|
|||||||
std::string input_line_;
|
std::string input_line_;
|
||||||
float cursor_timer_{0.0F};
|
float cursor_timer_{0.0F};
|
||||||
bool cursor_visible_{true};
|
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