sdl_runtime_compiler git · main
SDL3 game for running and compiling code at runtime
C++ 72.3% C 26.2%git clone https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler.gitwget https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler/archive/sdl_runtime_compiler.tar.gzAdd line linting With Claude
src/states/game_state.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/src/states/game_state.cpp b/src/states/game_state.cpp index 2c60e79..fbc5ec7 100644 --- a/src/states/game_state.cpp +++ b/src/states/game_state.cpp @@ -22,7 +22,7 @@ #include "wall/label.hpp" #include "wall/wall.hpp" - +static void lex_CarriedLine(CarriedLine& carry); GameState::GameState(size_t starting_level) @@ -217,6 +217,7 @@ GameState::on_Pick() _level_director-> record_PickedUp(base->text); base->set_Look (ConfigColor::keep, Text::Token::depth_floor); Wall::show_TokenInfo (_info, base->text); + lex_CarriedLine (_carried); carry_BeginAnim (std::move(base), true); return true; } @@ -229,6 +230,7 @@ GameState::on_Pick() _level_director->record_PickedUp(word->text); word->set_Look (ConfigColor::keep, Text::Token::depth_floor); Wall::show_TokenInfo(_info, word->text); + lex_CarriedLine (_carried); carry_BeginAnim (std::move(word), false); return true; } @@ -253,9 +255,10 @@ GameState::on_DropLast() drop.word = std::move(word); _anims_drop.push_back(std::move(drop)); - if (!_carried.empty()) + if (!_carried.empty()) { + lex_CarriedLine(_carried); Wall::show_TokenInfo(_info, _carried.last->word->text); - else + } else _level_director->show_Details(_ctx); _level_director->record_Dropped(); @@ -283,8 +286,10 @@ GameState::on_ShootOne() _projectiles_sys->launch(_projectiles, std::move(single), _ctx.camera->fwd, _ctx.camera->pos, aim); - if (!_carried.empty() && _carried.last && _carried.last->word) + if (!_carried.empty() && _carried.last && _carried.last->word) { Wall::show_TokenInfo(_info, _carried.last->word->text); + lex_CarriedLine(_carried); + } else _level_director->show_Details(_ctx); _level_director->record_Shot(); @@ -1098,6 +1103,7 @@ GameState::typing_RebuildPreview(const std::string& s) _typing_words.push_back(t.get()); _carried.push(std::move(t)); } + lex_CarriedLine(_carried); } @@ -1201,3 +1207,41 @@ GameState::on_EditorScroll(int8_t dt) if (dt > 0) _editor.scroll( ConfigWall::scroll_step); else _editor.scroll(-ConfigWall::scroll_step); } + + + + +void +lex_CarriedLine(CarriedLine& carry) +{ + std::string src; + DynArray<Text::Token::Data*> toks; + for (CarriedWordNode* n : carry.nodes()) { + if (!n->word) continue; + Text::Token::Data* t = n->word.get(); + if (!src.empty()) src += ' '; + t->byte_begin = src.size(); + src += t->text; + t->byte_end = src.size(); + toks.push_back(t); + } + if (toks.empty()) return; + + DynArray<Text::HiSpan> spans = Text::CppHighlight::classify(src); + + for (Text::Token::Data* t : toks) { + size_t best = 0; + Text::Token::Type type = Text::Token::Type::Identifier; + bool found = false; + for (const Text::HiSpan& s : spans) { + size_t lo = (t->byte_begin > s.byte_begin) ? t->byte_begin : s.byte_begin; + size_t hi = (t->byte_end < s.byte_end) ? t->byte_end : s.byte_end; + if (lo < hi && (hi - lo) > best) { best = hi - lo; type = s.type; found = true; } + } + t->set_ColorSource(Text::ColorSource::Lexed); + if (found) t->set_Context(Text::Token::get_Color(type)); + else t->clear_Context(); + } +} + +