fix: bucles cap a ranges algorithms (38 troballes)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <algorithm> // Para ranges::transform
|
||||
#include <numeric> // Para std::accumulate
|
||||
#include <cctype> // Para toupper
|
||||
#include <sstream> // Para std::istringstream
|
||||
#include <string> // Para string
|
||||
@@ -181,8 +182,8 @@ void Console::update(float delta_time) { // NOLINT(readability-function-cogniti
|
||||
|
||||
// Efecto typewriter: revelar letras una a una (solo cuando ACTIVE)
|
||||
if (status_ == Status::ACTIVE) {
|
||||
int total_chars = 0;
|
||||
for (const auto& line : msg_lines_) { total_chars += static_cast<int>(line.size()); }
|
||||
const int total_chars = std::accumulate(msg_lines_.begin(), msg_lines_.end(), 0,
|
||||
[](int acc, const auto& line) { return acc + static_cast<int>(line.size()); });
|
||||
if (typewriter_chars_ < total_chars) {
|
||||
typewriter_timer_ += delta_time;
|
||||
while (typewriter_timer_ >= TYPEWRITER_CHAR_DELAY && typewriter_chars_ < total_chars) {
|
||||
@@ -337,11 +338,9 @@ void Console::handleEvent(const SDL_Event& event) { // NOLINT(readability-funct
|
||||
const size_t SPACE_POS = upper.rfind(' ');
|
||||
if (SPACE_POS == std::string::npos) {
|
||||
// Modo comando: ciclar keywords visibles que empiecen por el prefijo
|
||||
for (const auto& kw : registry_.getVisibleKeywords()) {
|
||||
if (upper.empty() || kw.starts_with(upper)) {
|
||||
tab_matches_.emplace_back(kw);
|
||||
}
|
||||
}
|
||||
const auto KEYWORDS = registry_.getVisibleKeywords();
|
||||
std::ranges::copy_if(KEYWORDS, std::back_inserter(tab_matches_),
|
||||
[&upper](const auto& kw) { return upper.empty() || kw.starts_with(upper); });
|
||||
} else {
|
||||
const std::string BASE_CMD = upper.substr(0, SPACE_POS);
|
||||
const std::string SUB_PREFIX = upper.substr(SPACE_POS + 1);
|
||||
@@ -357,7 +356,8 @@ void Console::handleEvent(const SDL_Event& event) { // NOLINT(readability-funct
|
||||
if (tab_matches_.empty()) { break; }
|
||||
tab_index_ = (tab_index_ + 1) % static_cast<int>(tab_matches_.size());
|
||||
std::string result = tab_matches_[static_cast<size_t>(tab_index_)];
|
||||
for (char& c : result) { c = static_cast<char>(std::tolower(static_cast<unsigned char>(c))); }
|
||||
std::ranges::transform(result, result.begin(),
|
||||
[](char c) { return static_cast<char>(std::tolower(static_cast<unsigned char>(c))); });
|
||||
input_line_ = result;
|
||||
break;
|
||||
}
|
||||
@@ -403,9 +403,8 @@ void Console::processCommand() {
|
||||
|
||||
// Typewriter: instantáneo si el comando lo requiere, letra a letra si no
|
||||
if (instant) {
|
||||
int total = 0;
|
||||
for (const auto& l : msg_lines_) { total += static_cast<int>(l.size()); }
|
||||
typewriter_chars_ = total;
|
||||
typewriter_chars_ = std::accumulate(msg_lines_.begin(), msg_lines_.end(), 0,
|
||||
[](int acc, const auto& l) { return acc + static_cast<int>(l.size()); });
|
||||
} else {
|
||||
typewriter_chars_ = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user