rngine 0.11.5 → 0.11.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rngine",
3
- "version": "0.11.5",
3
+ "version": "0.11.6",
4
4
  "description": "React Native 2D game engine powered by Nitro Modules",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -173,7 +173,7 @@ void GameRenderer::render(const Screen &screen,
173
173
  canvas->clipRect(gameBounds);
174
174
 
175
175
  if (screen.color.has_value()) {
176
- canvas->clear(ColorUtils::parseHexColor(screen.color.value()));
176
+ canvas->clear(ColorUtils::parseString(screen.color.value()));
177
177
  }
178
178
 
179
179
  if (screen.asset.has_value() && screen.asset.value() != 0) {
@@ -201,7 +201,7 @@ void GameRenderer::render(const Screen &screen,
201
201
  SkPaint paint;
202
202
  paint.setAntiAlias(true);
203
203
  paint.setStyle(SkPaint::kFill_Style);
204
- paint.setColor(ColorUtils::parseHexColor(entity.color.value()));
204
+ paint.setColor(ColorUtils::parseString(entity.color.value()));
205
205
 
206
206
  std::visit(
207
207
  [&](const auto &shape) {
@@ -1,33 +1,14 @@
1
1
  #include "ColorUtils.hpp"
2
+ #include <react/renderer/css/CSSColor.h>
3
+ #include <react/renderer/css/CSSValueParser.h>
2
4
 
3
5
  namespace margelo::nitro::rngine::ColorUtils {
4
- uint32_t parseHexColor(const std::string &color) {
5
- const std::string &c = color;
6
- if (!c.empty() && c[0] == '#') {
7
- std::string hex = c.substr(1);
8
-
9
- if (hex.size() == 3 || hex.size() == 4) {
10
- std::string expanded;
11
- expanded.reserve(hex.size() * 2);
12
- for (char ch : hex) {
13
- expanded += ch;
14
- expanded += ch;
15
- }
16
- hex = std::move(expanded);
17
- }
18
-
19
- if (hex.size() == 6) {
20
- return 0xFF000000 | std::stoul(hex, nullptr, 16);
21
- } else if (hex.size() == 8) {
22
- uint32_t rgba = std::stoul(hex, nullptr, 16);
23
- uint32_t r = (rgba >> 24) & 0xFF;
24
- uint32_t g = (rgba >> 16) & 0xFF;
25
- uint32_t b = (rgba >> 8) & 0xFF;
26
- uint32_t a = rgba & 0xFF;
27
- return (a << 24) | (r << 16) | (g << 8) | b;
28
- }
6
+ uint32_t parseString(const std::string &s) {
7
+ auto v = facebook::react::parseCSSProperty<facebook::react::CSSColor>(s);
8
+ if (auto *c = std::get_if<facebook::react::CSSColor>(&v)) {
9
+ return (uint32_t(c->a) << 24) | (uint32_t(c->r) << 16) |
10
+ (uint32_t(c->g) << 8) | c->b; // 0xAARRGGBB
29
11
  }
30
-
31
12
  return 0x00000000;
32
13
  }
33
14
  } // namespace margelo::nitro::rngine::ColorUtils
@@ -3,5 +3,5 @@
3
3
  #include <string>
4
4
 
5
5
  namespace margelo::nitro::rngine::ColorUtils {
6
- uint32_t parseHexColor(const std::string &color);
6
+ uint32_t parseString(const std::string &color);
7
7
  } // namespace margelo::nitro::rngine::ColorUtils