summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-11-20 14:49:10 +0100
committerAki <please@ignore.pl>2022-11-20 14:49:10 +0100
commitb4b20596af5a61088d7085d562bfdaef2c093578 (patch)
treedca7cf8b48fdb2be1e50ead75552774af99b6cc2
parent6204aa1afe8d6906f31e79840f4593872bf412f4 (diff)
downloadkurator-b4b20596af5a61088d7085d562bfdaef2c093578.zip
kurator-b4b20596af5a61088d7085d562bfdaef2c093578.tar.gz
kurator-b4b20596af5a61088d7085d562bfdaef2c093578.tar.bz2
Fixed raylib overwriting formatted strings
-rw-r--r--kurator/src/Battle.cpp7
-rw-r--r--kurator/src/components.h2
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 <algorithm>
#include <cmath>
#include <memory>
+#include <string>
#include <utility>
#include <raylib.h>
@@ -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<battles::Transform>(hit.victim);
registry.emplace<Timed>(entity, 1.2);
- registry.emplace<CenteredText>(entity, text, MeasureText(text, 10), 10, RED);
+ registry.emplace<CenteredText>(entity, text, MeasureText(text.c_str(), 10), 10, RED);
registry.emplace<battles::Transform>(entity, transform.position, 0.0);
registry.emplace<PopMove>(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;