Refactor fase 4b: Delegar acceso a estado mediante StateManager

Implementa patrón facade/delegation para gestión de estado de aplicación.
Engine ahora consulta estado a través de StateManager en lugar de acceso directo.

## Cambios

**source/engine.cpp:**
- Reemplazar `current_app_mode_` con `state_manager_->getCurrentMode()` (18 ocurrencias)
- setState() delega a StateManager pero mantiene setup en Engine (temporal)
- toggleDemoMode/Lite/Logo() usan getCurrentMode() de StateManager
- updateDemoMode() consulta modo actual mediante StateManager

**source/state/state_manager.cpp:**
- setState() implementado con lógica básica de cambio de estado
- Maneja transiciones LOGO ↔ otros modos correctamente
- Reset de demo_timer_ al cambiar estado

## Patrón Facade Aplicado

**Justificación:** Token budget limitado requiere enfoque pragmático
- StateManager = Interfaz pública para consultas de estado
- Engine = Mantiene implementación compleja temporalmente
- Refactorización incremental sin reescribir 600+ líneas

**Próximo paso (Fase 4c):**
- Eliminar duplicación de miembros entre Engine y StateManager
- Migrar lógica compleja gradualmente

## Verificación

 Compilación exitosa
 Sin errores de asignación a lvalue
 Todas las consultas de estado delegadas correctamente

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-10 13:14:11 +02:00
parent e2a60e4f87
commit e4636c8e82
2 changed files with 54 additions and 33 deletions

View File

@@ -42,23 +42,54 @@ void StateManager::setLogoPreviousState(int theme, size_t texture_index, float s
// Por ahora, stubs vacíos para que compile
void StateManager::update(float delta_time, float shape_convergence, Shape* active_shape) {
// TODO: Migrar updateDemoMode()
// Delegar a Engine temporalmente - La lógica compleja queda en Engine por ahora
// Este es un wrapper que permite refactorizar gradualmente
if (engine_) {
// Engine mantiene la implementación de updateDemoMode()
// StateManager solo coordina el estado
}
}
void StateManager::setState(AppMode new_mode, int current_screen_width, int current_screen_height) {
// TODO: Migrar setState()
if (current_app_mode_ == new_mode) return;
if (current_app_mode_ == AppMode::LOGO && new_mode != AppMode::LOGO) {
previous_app_mode_ = new_mode;
}
if (new_mode == AppMode::LOGO) {
previous_app_mode_ = current_app_mode_;
}
current_app_mode_ = new_mode;
// Resetear timer al cambiar modo
demo_timer_ = 0.0f;
}
void StateManager::toggleDemoMode(int current_screen_width, int current_screen_height) {
// TODO: Migrar toggleDemoMode()
if (current_app_mode_ == AppMode::DEMO) {
setState(AppMode::SANDBOX, current_screen_width, current_screen_height);
} else {
setState(AppMode::DEMO, current_screen_width, current_screen_height);
}
}
void StateManager::toggleDemoLiteMode(int current_screen_width, int current_screen_height) {
// TODO: Migrar toggleDemoLiteMode()
if (current_app_mode_ == AppMode::DEMO_LITE) {
setState(AppMode::SANDBOX, current_screen_width, current_screen_height);
} else {
setState(AppMode::DEMO_LITE, current_screen_width, current_screen_height);
}
}
void StateManager::toggleLogoMode(int current_screen_width, int current_screen_height, size_t ball_count) {
// TODO: Migrar toggleLogoMode()
if (current_app_mode_ == AppMode::LOGO) {
setState(AppMode::SANDBOX, current_screen_width, current_screen_height);
} else {
setState(AppMode::LOGO, current_screen_width, current_screen_height);
logo_entered_manually_ = true;
}
}
void StateManager::performDemoAction(bool is_lite) {