Skip to content

Commit 5afc759

Browse files
committed
Use clone root sprite as the data source for blocks and assets
1 parent 41f8b49 commit 5afc759

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

include/scratchcpp/sprite.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class LIBSCRATCHCPP_EXPORT Sprite : public Target
5959
void setRotationStyle(const std::string &newRotationStyle);
6060
void setRotationStyle(const char *newRotationStyle);
6161

62+
protected:
63+
Target *dataSource() const override;
64+
6265
private:
6366
spimpl::unique_impl_ptr<SpritePrivate> impl;
6467
};

src/scratch/sprite.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,8 @@ void Sprite::setRotationStyle(const char *newRotationStyle)
255255
{
256256
setRotationStyle(std::string(newRotationStyle));
257257
}
258+
259+
Target *Sprite::dataSource() const
260+
{
261+
return impl->cloneRoot;
262+
}

test/scratch_classes/sprite_test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <scratchcpp/sprite.h>
22
#include <scratchcpp/variable.h>
33
#include <scratchcpp/list.h>
4+
#include <scratchcpp/costume.h>
45
#include <enginemock.h>
56

67
#include "../common.h"
@@ -32,6 +33,8 @@ TEST(SpriteTest, Clone)
3233
auto var2 = std::make_shared<Variable>("b", "var2", "world");
3334
sprite.addVariable(var1);
3435
sprite.addVariable(var2);
36+
auto c1 = std::make_shared<Costume>("costume1", "", "svg");
37+
sprite.addCostume(c1);
3538

3639
auto list1 = std::make_shared<List>("c", "list1");
3740
list1->push_back("item1");
@@ -173,6 +176,11 @@ TEST(SpriteTest, Clone)
173176
ASSERT_TRUE(clone3->allChildren().empty());
174177

175178
ASSERT_TRUE(clone4->allChildren().empty());
179+
180+
ASSERT_EQ(clone2->costumes(), sprite.costumes());
181+
auto c2 = std::make_shared<Costume>("costume2", "", "png");
182+
clone2->addCostume(c2);
183+
ASSERT_EQ(clone2->costumes(), sprite.costumes());
176184
}
177185

178186
TEST(SpriteTest, X)

0 commit comments

Comments
 (0)