From 8264895bfaf506a8d938c8e44dbf34f8cb971c5a Mon Sep 17 00:00:00 2001
From: adazem009 <68537469+adazem009@users.noreply.github.com>
Date: Sat, 27 Jan 2024 12:40:51 +0100
Subject: [PATCH 1/2] fix #437: Set locale to C in jsonValue()

---
 src/internal/reader_common.h                  |  15 ++++++++++++---
 test/load_project/load_project_test.cpp       |  18 ++++++++++++++++++
 .../437_load_double_values.sb3                | Bin 0 -> 875 bytes
 3 files changed, 30 insertions(+), 3 deletions(-)
 create mode 100644 test/regtest_projects/437_load_double_values.sb3

diff --git a/src/internal/reader_common.h b/src/internal/reader_common.h
index 7c84f1f9..09815d01 100644
--- a/src/internal/reader_common.h
+++ b/src/internal/reader_common.h
@@ -13,9 +13,18 @@ Value jsonToValue(nlohmann::json value)
 {
     if (value.is_string())
         return value.get<std::string>();
-    else if (value.is_number())
-        return std::stod(value.dump());
-    else if (value.is_boolean())
+    else if (value.is_number()) {
+        // Set locale to C to avoid conversion issues
+        std::string oldLocale = std::setlocale(LC_NUMERIC, nullptr);
+        std::setlocale(LC_NUMERIC, "C");
+
+        double converted = std::stod(value.dump());
+
+        // Restore old locale
+        std::setlocale(LC_NUMERIC, oldLocale.c_str());
+
+        return converted;
+    } else if (value.is_boolean())
         return value.get<bool>();
     else
         return value.dump();
diff --git a/test/load_project/load_project_test.cpp b/test/load_project/load_project_test.cpp
index 639e4c0d..55ffce39 100644
--- a/test/load_project/load_project_test.cpp
+++ b/test/load_project/load_project_test.cpp
@@ -709,3 +709,21 @@ TEST(LoadProjectTest, LoadNullDimensionMonitor)
     Project p(name);
     ASSERT_TRUE(p.load());
 }
+
+TEST(LoadProjectTest, LoadDoubleValue)
+{
+    // Regtest for #437
+    std::string oldLocale = std::setlocale(LC_NUMERIC, nullptr);
+    std::setlocale(LC_NUMERIC, "sk_SK.UTF-8");
+
+    std::string name = "regtest_projects/437_load_double_values.sb3";
+    Project p(name);
+    ASSERT_TRUE(p.load());
+
+    auto stage = p.engine()->stage();
+    ASSERT_TRUE(stage);
+    ASSERT_VAR(stage, "test");
+    ASSERT_EQ(GET_VAR(stage, "test")->value().toDouble(), 5.6654);
+
+    std::setlocale(LC_NUMERIC, oldLocale.c_str());
+}
diff --git a/test/regtest_projects/437_load_double_values.sb3 b/test/regtest_projects/437_load_double_values.sb3
new file mode 100644
index 0000000000000000000000000000000000000000..918a7ae1cd71f6d731fce606ffa64bb3e42bc0f9
GIT binary patch

From fad74ce4208bc53c14a2e91337b79158778b9473 Mon Sep 17 00:00:00 2001
From: adazem009 <68537469+adazem009@users.noreply.github.com>
Date: Sat, 27 Jan 2024 12:51:43 +0100
Subject: [PATCH 2/2] fix #438: Fix default sprite bounding rectangle

---
 src/scratch/sprite.cpp               |  2 +-
 test/scratch_classes/sprite_test.cpp | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/scratch/sprite.cpp b/src/scratch/sprite.cpp
index eef2ffdb..2dfe3d5f 100644
--- a/src/scratch/sprite.cpp
+++ b/src/scratch/sprite.cpp
@@ -328,7 +328,7 @@ void Sprite::setLayerOrder(int newLayerOrder)
 Rect Sprite::boundingRect() const
 {
     if (!impl->iface)
-        return Rect();
+        return Rect(impl->x, impl->y, impl->x, impl->y);
 
     return impl->iface->boundingRect();
 }
diff --git a/test/scratch_classes/sprite_test.cpp b/test/scratch_classes/sprite_test.cpp
index ac964315..3dc9cbee 100644
--- a/test/scratch_classes/sprite_test.cpp
+++ b/test/scratch_classes/sprite_test.cpp
@@ -558,6 +558,18 @@ TEST(SpriteTest, KeepInFence)
     ASSERT_EQ(std::round(fencedY * 100) / 100, 150.9);
 }
 
+TEST(SpriteTest, DefaultBoundingRect)
+{
+    Sprite sprite;
+    sprite.setX(65.5);
+    sprite.setY(-45.01);
+    Rect rect = sprite.boundingRect();
+    ASSERT_EQ(rect.left(), 65.5);
+    ASSERT_EQ(rect.top(), -45.01);
+    ASSERT_EQ(rect.right(), 65.5);
+    ASSERT_EQ(rect.bottom(), -45.01);
+}
+
 TEST(SpriteTest, GraphicsEffects)
 {
     Sprite sprite;
