Skip to content

Commit 4622550

Browse files
committed
Add getter and setter for monitors to IEngine
1 parent 745cc76 commit 4622550

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

include/scratchcpp/iengine.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class List;
2323
class Script;
2424
class ITimer;
2525
class KeyEvent;
26+
class Monitor;
2627

2728
/*!
2829
* \brief The IEngine interface provides an API for running Scratch projects.
@@ -300,6 +301,12 @@ class LIBSCRATCHCPP_EXPORT IEngine
300301
/*! Returns the Stage. */
301302
virtual Stage *stage() const = 0;
302303

304+
/*! Returns the list of monitors. */
305+
virtual const std::vector<std::shared_ptr<Monitor>> &monitors() const = 0;
306+
307+
/*! Sets the list of monitors. */
308+
virtual void setMonitors(const std::vector<std::shared_ptr<Monitor>> &newMonitors) = 0;
309+
303310
/*! Returns the list of extension names. */
304311
virtual const std::vector<std::string> &extensions() const = 0;
305312

src/engine/internal/engine.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,16 @@ Stage *Engine::stage() const
965965
return dynamic_cast<Stage *>((*it).get());
966966
}
967967

968+
const std::vector<std::shared_ptr<Monitor>> &Engine::monitors() const
969+
{
970+
return m_monitors;
971+
}
972+
973+
void Engine::setMonitors(const std::vector<std::shared_ptr<Monitor>> &newMonitors)
974+
{
975+
m_monitors = newMonitors;
976+
}
977+
968978
const std::vector<std::string> &Engine::extensions() const
969979
{
970980
return m_extensions;

src/engine/internal/engine.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ class Engine : public IEngine
131131

132132
Stage *stage() const override;
133133

134+
const std::vector<std::shared_ptr<Monitor>> &monitors() const override;
135+
void setMonitors(const std::vector<std::shared_ptr<Monitor>> &newMonitors) override;
136+
134137
const std::vector<std::string> &extensions() const override;
135138
void setExtensions(const std::vector<std::string> &newExtensions) override;
136139

@@ -197,6 +200,7 @@ class Engine : public IEngine
197200
std::vector<std::shared_ptr<Target>> m_targets;
198201
std::vector<std::shared_ptr<Broadcast>> m_broadcasts;
199202
std::unordered_map<Broadcast *, std::vector<Script *>> m_broadcastMap;
203+
std::vector<std::shared_ptr<Monitor>> m_monitors;
200204
std::vector<std::string> m_extensions;
201205
std::vector<Target *> m_executableTargets; // sorted by layer (reverse order of execution)
202206
std::vector<std::shared_ptr<VirtualMachine>> m_threads;

test/engine/engine_test.cpp

Lines changed: 14 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/keyevent.h>
9+
#include <scratchcpp/monitor.h>
910
#include <scratch/sound_p.h>
1011
#include <timermock.h>
1112
#include <clockmock.h>
@@ -1127,6 +1128,19 @@ TEST(EngineTest, Stage)
11271128
ASSERT_EQ(engine.stage(), nullptr);
11281129
}
11291130

1131+
TEST(EngineTest, Monitors)
1132+
{
1133+
Engine engine;
1134+
ASSERT_TRUE(engine.monitors().empty());
1135+
1136+
auto m1 = std::make_shared<Monitor>("", "");
1137+
auto m2 = std::make_shared<Monitor>("", "");
1138+
auto m3 = std::make_shared<Monitor>("", "");
1139+
1140+
engine.setMonitors({ m1, m2, m3 });
1141+
ASSERT_EQ(engine.monitors(), std::vector<std::shared_ptr<Monitor>>({ m1, m2, m3 }));
1142+
}
1143+
11301144
TEST(EngineTest, Clones)
11311145
{
11321146
Project p("clones.sb3");

test/mocks/enginemock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ class EngineMock : public IEngine
112112

113113
MOCK_METHOD(Stage *, stage, (), (const, override));
114114

115+
MOCK_METHOD(const std::vector<std::shared_ptr<Monitor>> &, monitors, (), (const, override));
116+
MOCK_METHOD(void, setMonitors, (const std::vector<std::shared_ptr<Monitor>> &), (override));
117+
115118
MOCK_METHOD(std::vector<std::string> &, extensions, (), (const, override));
116119
MOCK_METHOD(void, setExtensions, (const std::vector<std::string> &), (override));
117120

0 commit comments

Comments
 (0)