File tree Expand file tree Collapse file tree 4 files changed +28
-0
lines changed Expand file tree Collapse file tree 4 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ namespace libscratchcpp
1111
1212class IMonitorHandler ;
1313class Block ;
14+ class Script ;
1415class Sprite ;
1516class Value ;
1617class 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
Original file line number Diff line number Diff 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(). */
5466Sprite *Monitor::sprite () const
5567{
Original file line number Diff line number Diff line change 33#pragma once
44
55#include < scratchcpp/monitor.h>
6+ #include < scratchcpp/script.h>
67
78namespace 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 ;
Original file line number Diff line number Diff 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+
6474TEST (MonitorTest, Sprite)
6575{
6676 Monitor monitor (" " , " " );
You can’t perform that action at this time.
0 commit comments