Skip to content

Commit 441ccc6

Browse files
committed
Add broadcast property to Costume
1 parent 0838494 commit 441ccc6

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

include/scratchcpp/costume.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace libscratchcpp
1010
{
1111

12+
class Broadcast;
1213
class CostumePrivate;
1314

1415
/*! \brief The Costume class represents a Scratch costume. */
@@ -27,6 +28,8 @@ class LIBSCRATCHCPP_EXPORT Costume : public Asset
2728
int rotationCenterY() const;
2829
void setRotationCenterY(int newRotationCenterY);
2930

31+
Broadcast *broadcast();
32+
3033
private:
3134
spimpl::unique_impl_ptr<CostumePrivate> impl;
3235
};

src/scratch/costume.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ void Costume::setRotationCenterY(int newRotationCenterY)
4848
{
4949
impl->rotationCenterY = newRotationCenterY;
5050
}
51+
52+
/*!
53+
* Returns the Broadcast linked with this costume.
54+
* \note This is used by the "switch backdrop to and wait" block.
55+
*/
56+
Broadcast *Costume::broadcast()
57+
{
58+
return &impl->broadcast;
59+
}

src/scratch/costume_p.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using namespace libscratchcpp;
66

7-
CostumePrivate::CostumePrivate()
7+
CostumePrivate::CostumePrivate() :
8+
broadcast("", "")
89
{
910
}

src/scratch/costume_p.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#pragma once
44

5+
#include <scratchcpp/broadcast.h>
6+
57
namespace libscratchcpp
68
{
79

@@ -13,6 +15,7 @@ struct CostumePrivate
1315
double bitmapResolution = 1;
1416
int rotationCenterX = 0;
1517
int rotationCenterY = 0;
18+
Broadcast broadcast;
1619
};
1720

1821
} // namespace libscratchcpp

test/assets/costume_test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <scratchcpp/costume.h>
2+
#include <scratchcpp/broadcast.h>
23

34
#include "../common.h"
45

@@ -39,3 +40,13 @@ TEST(CostumeTest, RotationCenterY)
3940
costume.setRotationCenterY(180);
4041
ASSERT_EQ(costume.rotationCenterY(), 180);
4142
}
43+
44+
TEST(CostumeTest, Broadcast)
45+
{
46+
Costume costume("costume1", "a", "svg");
47+
48+
Broadcast *broadcast = costume.broadcast();
49+
ASSERT_TRUE(broadcast);
50+
ASSERT_TRUE(broadcast->id().empty());
51+
ASSERT_TRUE(broadcast->name().empty());
52+
}

0 commit comments

Comments
 (0)