Skip to content

Commit 491dfff

Browse files
committed
Add script property to Monitor
1 parent 7f5ef8c commit 491dfff

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

include/scratchcpp/monitor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace libscratchcpp
1111

1212
class IMonitorHandler;
1313
class Block;
14+
class Script;
1415
class Sprite;
1516
class Value;
1617
class Rect;
@@ -40,6 +41,9 @@ class LIBSCRATCHCPP_EXPORT Monitor : public Entity
4041

4142
std::shared_ptr<Block> block() const;
4243

44+
std::shared_ptr<Script> script() const;
45+
void setScript(std::shared_ptr<Script> script);
46+
4347
Sprite *sprite() const;
4448
void setSprite(Sprite *sprite);
4549

src/scratch/monitor.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ std::shared_ptr<Block> Monitor::block() const
5050
return impl->block;
5151
}
5252

53+
/*! Returns the script which holds information about the monitor's compiled block. */
54+
std::shared_ptr<Script> Monitor::script() const
55+
{
56+
return impl->script;
57+
}
58+
59+
/*! Sets the script which holds information about the monitor's compiled block. */
60+
void Monitor::setScript(std::shared_ptr<Script> script)
61+
{
62+
impl->script = script;
63+
}
64+
5365
/*! Convenience method which calls block()->target(). */
5466
Sprite *Monitor::sprite() const
5567
{

src/scratch/monitor_p.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma once
44

55
#include <scratchcpp/monitor.h>
6+
#include <scratchcpp/script.h>
67

78
namespace libscratchcpp
89
{
@@ -17,6 +18,7 @@ struct MonitorPrivate
1718

1819
IMonitorHandler *iface = nullptr;
1920
Monitor::Mode mode = Monitor::Mode::Default;
21+
std::shared_ptr<Script> script;
2022
std::shared_ptr<Block> block; // Compiler needs shared_ptr
2123
unsigned int width = 0;
2224
unsigned int height = 0;

test/scratch_classes/monitor_test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ TEST(MonitorTest, Mode)
6161
ASSERT_EQ(monitor.mode(), Monitor::Mode::Default);
6262
}
6363

64+
TEST(MonitorTest, Script)
65+
{
66+
Monitor monitor("", "");
67+
ASSERT_EQ(monitor.script(), nullptr);
68+
69+
auto script = std::make_shared<Script>(nullptr, nullptr, nullptr);
70+
monitor.setScript(script);
71+
ASSERT_EQ(monitor.script(), script);
72+
}
73+
6474
TEST(MonitorTest, Sprite)
6575
{
6676
Monitor monitor("", "");

0 commit comments

Comments
 (0)