Skip to content

Commit e95b006

Browse files
committed
Implement sound cloning
1 parent cee985b commit e95b006

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/scratch/sprite.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <scratchcpp/variable.h>
77
#include <scratchcpp/list.h>
88
#include <scratchcpp/costume.h>
9+
#include <scratchcpp/sound.h>
910
#include <scratchcpp/rect.h>
1011
#include <cassert>
1112
#include <iostream>
@@ -64,6 +65,11 @@ std::shared_ptr<Sprite> Sprite::clone()
6465
for (auto list : l)
6566
clone->addList(list->clone());
6667

68+
const auto &sounds = this->sounds();
69+
70+
for (auto sound : sounds)
71+
clone->addSound(sound->clone());
72+
6773
clone->setCostumeIndex(costumeIndex());
6874
clone->setLayerOrder(layerOrder());
6975
clone->setVolume(volume());

test/engine/engine_test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ TEST(EngineTest, StopSounds)
261261
auto player3 = std::make_shared<AudioPlayerMock>();
262262
SoundPrivate::audioOutput = &factory;
263263
EXPECT_CALL(factory, createAudioPlayer()).WillOnce(Return(player1)).WillOnce(Return(player2)).WillOnce(Return(player3));
264+
EXPECT_CALL(*player1, isLoaded).WillOnce(Return(false));
265+
EXPECT_CALL(*player2, isLoaded).WillOnce(Return(false));
266+
EXPECT_CALL(*player3, isLoaded).WillOnce(Return(false));
264267
EXPECT_CALL(*player1, load).WillOnce(Return(true));
265268
EXPECT_CALL(*player2, load).WillOnce(Return(true));
266269
EXPECT_CALL(*player3, load).WillOnce(Return(true));

test/scratch_classes/sprite_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <scratchcpp/variable.h>
44
#include <scratchcpp/list.h>
55
#include <scratchcpp/costume.h>
6+
#include <scratchcpp/sound.h>
67
#include <scratchcpp/rect.h>
78
#include <scratchcpp/project.h>
89
#include <enginemock.h>
@@ -63,6 +64,12 @@ TEST(SpriteTest, Clone)
6364
sprite.addVariable(var2);
6465
auto c1 = std::make_shared<Costume>("costume1", "", "svg");
6566
sprite.addCostume(c1);
67+
auto s1 = std::make_shared<Sound>("sound1", "a", "wav");
68+
auto s2 = std::make_shared<Sound>("sound2", "b", "wav");
69+
auto s3 = std::make_shared<Sound>("sound3", "c", "wav");
70+
sprite.addSound(s1);
71+
sprite.addSound(s2);
72+
sprite.addSound(s3);
6673

6774
auto list1 = std::make_shared<List>("c", "list1");
6875
list1->push_back("item1");
@@ -111,6 +118,14 @@ TEST(SpriteTest, Clone)
111118
ASSERT_EQ(*clone->listAt(1), std::deque<Value>({ "test" }));
112119
ASSERT_EQ(clone->listAt(1)->target(), clone);
113120

121+
ASSERT_EQ(clone->sounds().size(), 3);
122+
ASSERT_EQ(clone->soundAt(0)->id(), "a");
123+
ASSERT_EQ(clone->soundAt(0)->name(), "sound1");
124+
ASSERT_EQ(clone->soundAt(0)->dataFormat(), "wav");
125+
ASSERT_EQ(clone->soundAt(2)->id(), "c");
126+
ASSERT_EQ(clone->soundAt(2)->name(), "sound3");
127+
ASSERT_EQ(clone->soundAt(2)->dataFormat(), "wav");
128+
114129
ASSERT_EQ(clone->costumeIndex(), 1);
115130
ASSERT_EQ(clone->layerOrder(), 5);
116131
ASSERT_EQ(clone->volume(), 50);

0 commit comments

Comments
 (0)