Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarText.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-04-22 06:07:59 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2024-04-22 06:07:59 +1000
commitca1426eabc873f781eb0dd389d45634b7d183250 (patch)
tree15ea83658ca3824232f14fe4b32ec714e0aa05c6 /source/core/StarText.cpp
parentd5f5fb5ddf0d4a9f0b0e6ac012121926d2fcd949 (diff)
Lua chat callbacks + better font styling
golly gee whiz!! i hope i didn't fuck something up
Diffstat (limited to 'source/core/StarText.cpp')
-rw-r--r--source/core/StarText.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/source/core/StarText.cpp b/source/core/StarText.cpp
index 11fca27..86c9f25 100644
--- a/source/core/StarText.cpp
+++ b/source/core/StarText.cpp
@@ -1,9 +1,35 @@
#include "StarText.hpp"
-
+#include "StarJsonExtra.hpp"
#include <regex>
namespace Star {
+TextStyle::TextStyle(Json const& config) : TextStyle() {
+ if (config.isType(Json::Type::String))
+ font = config.toString();
+ else
+ loadJson(config);
+}
+TextStyle& TextStyle::loadJson(Json const& config) {
+ if (!config)
+ return *this;
+
+ lineSpacing = config.getFloat("lineSpacing", lineSpacing);
+ if (auto jColor = config.opt("color"))
+ color = jsonToColor(*jColor).toRgba();
+ if (auto jShadow = config.opt("shadow"))
+ shadow = jsonToColor(*jShadow).toRgba();
+ fontSize = config.getUInt("fontSize", fontSize);
+ if (auto jFont = config.optString("font"))
+ font = *jFont;
+ if (auto jDirectives = config.optString("directives"))
+ directives = *jDirectives;
+ if (auto jBackDirectives = config.optString("backDirectives"))
+ backDirectives = *jBackDirectives;
+
+ return *this;
+}
+
namespace Text {
static auto stripEscapeRegex = std::regex(strf("\\{:c}[^;]*{:c}", CmdEsc, EndEsc));
String stripEscapeCodes(String const& s) {