From b4b20596af5a61088d7085d562bfdaef2c093578 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 20 Nov 2022 14:49:10 +0100 Subject: Fixed raylib overwriting formatted strings --- kurator/src/Battle.cpp | 7 ++++--- kurator/src/components.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 9a92180..cb97ce7 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -86,7 +87,7 @@ Battle::draw() const for (const auto& [entity, text, transform] : pops.each()) { const int x = width/2 + transform.position.x*scale - text.width/2; const int y = height/2 + transform.position.y*scale - text.font_size/2; - DrawText(text.text, x, y, text.font_size, text.color); + DrawText(text.text.c_str(), x, y, text.font_size, text.color); } } @@ -98,10 +99,10 @@ Battle::receive(const battles::Hit& hit) if (!registry.valid(hit.victim)) return; const auto entity = registry.create(); - const auto text = TextFormat("%.1f", hit.damage); + const std::string text = TextFormat("%.1f", hit.damage); const auto& transform = registry.get(hit.victim); registry.emplace(entity, 1.2); - registry.emplace(entity, text, MeasureText(text, 10), 10, RED); + registry.emplace(entity, text, MeasureText(text.c_str(), 10), 10, RED); registry.emplace(entity, transform.position, 0.0); registry.emplace(entity, battles::Point{0.0, -0.6}, 0.998); } diff --git a/kurator/src/components.h b/kurator/src/components.h index 7d54ea5..6e03412 100644 --- a/kurator/src/components.h +++ b/kurator/src/components.h @@ -19,7 +19,7 @@ struct Timed struct CenteredText { - const char* text; + std::string text; int width; int font_size; Color color; -- cgit v1.1