Skip to content

Commit 963a0bd

Browse files
committed
Add blockSection setter to monitor
1 parent 22502ac commit 963a0bd

File tree

6 files changed

+50
-0
lines changed

6 files changed

+50
-0
lines changed

include/scratchcpp/monitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class LIBSCRATCHCPP_EXPORT Monitor : public Entity
4949
void setScript(std::shared_ptr<Script> script);
5050

5151
std::shared_ptr<IBlockSection> blockSection() const;
52+
void setBlockSection(std::shared_ptr<IBlockSection> blockSection);
5253

5354
Sprite *sprite() const;
5455
void setSprite(Sprite *sprite);

src/scratch/monitor.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ std::shared_ptr<IBlockSection> Monitor::blockSection() const
8686
return impl->blockSection;
8787
}
8888

89+
/*! Sets the block section of this monitor. */
90+
void Monitor::setBlockSection(std::shared_ptr<IBlockSection> blockSection)
91+
{
92+
impl->blockSection = blockSection;
93+
}
94+
8995
/*! Convenience method which calls block()->target(). */
9096
Sprite *Monitor::sprite() const
9197
{

test/scratch_classes/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ gtest_discover_tests(comment_test)
222222
add_executable(
223223
monitor_test
224224
monitor_test.cpp
225+
testsection.cpp
226+
testsection.h
225227
)
226228

227229
target_link_libraries(

test/scratch_classes/monitor_test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <randomgeneratormock.h>
1010

1111
#include "../common.h"
12+
#include "testsection.h"
1213

1314
using namespace libscratchcpp;
1415

@@ -84,6 +85,16 @@ TEST(MonitorTest, Script)
8485
ASSERT_EQ(monitor.script(), script);
8586
}
8687

88+
TEST(MonitorTest, BlockSection)
89+
{
90+
Monitor monitor("", "");
91+
ASSERT_EQ(monitor.blockSection(), nullptr);
92+
93+
auto section = std::make_shared<TestSection>();
94+
monitor.setBlockSection(section);
95+
ASSERT_EQ(monitor.blockSection(), section);
96+
}
97+
8798
TEST(MonitorTest, Sprite)
8899
{
89100
Monitor monitor("", "");
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <scratchcpp/iengine.h>
2+
3+
#include "testsection.h"
4+
5+
using namespace libscratchcpp;
6+
7+
std::string TestSection::name() const
8+
{
9+
return "Test";
10+
}
11+
12+
void TestSection::registerBlocks(IEngine *engine)
13+
{
14+
}

test/scratch_classes/testsection.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include <scratchcpp/iblocksection.h>
4+
5+
namespace libscratchcpp
6+
{
7+
8+
class TestSection : public IBlockSection
9+
{
10+
public:
11+
std::string name() const override;
12+
13+
void registerBlocks(IEngine *engine) override;
14+
};
15+
16+
} // namespace libscratchcpp

0 commit comments

Comments
 (0)