Skip to content

Commit 115bcb5

Browse files
committed
Implement event_whenstageclicked block
1 parent d6b9fe6 commit 115bcb5

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/blocks/eventblocks.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void EventBlocks::registerBlocks(IEngine *engine)
2323
// Blocks
2424
engine->addCompileFunction(this, "event_whenflagclicked", &compileWhenFlagClicked);
2525
engine->addCompileFunction(this, "event_whenthisspriteclicked", &compileWhenThisSpriteClicked);
26+
engine->addCompileFunction(this, "event_whenstageclicked", &compileWhenStageClicked);
2627
engine->addCompileFunction(this, "event_broadcast", &compileBroadcast);
2728
engine->addCompileFunction(this, "event_broadcastandwait", &compileBroadcastAndWait);
2829
engine->addCompileFunction(this, "event_whenbroadcastreceived", &compileWhenBroadcastReceived);
@@ -48,6 +49,11 @@ void EventBlocks::compileWhenThisSpriteClicked(Compiler *compiler)
4849
compiler->engine()->addTargetClickScript(compiler->block());
4950
}
5051

52+
void EventBlocks::compileWhenStageClicked(Compiler *compiler)
53+
{
54+
compiler->engine()->addTargetClickScript(compiler->block());
55+
}
56+
5157
void EventBlocks::compileBroadcast(Compiler *compiler)
5258
{
5359
auto input = compiler->input(BROADCAST_INPUT);

src/blocks/eventblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class EventBlocks : public IBlockSection
3232

3333
static void compileWhenFlagClicked(Compiler *compiler);
3434
static void compileWhenThisSpriteClicked(Compiler *compiler);
35+
static void compileWhenStageClicked(Compiler *compiler);
3536
static void compileBroadcast(Compiler *compiler);
3637
static void compileBroadcastAndWait(Compiler *compiler);
3738
static void compileWhenBroadcastReceived(Compiler *compiler);

test/blocks/event_blocks_test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ TEST_F(EventBlocksTest, RegisterBlocks)
8585
// Blocks
8686
EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "event_whenflagclicked", &EventBlocks::compileWhenFlagClicked));
8787
EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "event_whenthisspriteclicked", &EventBlocks::compileWhenThisSpriteClicked));
88+
EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "event_whenstageclicked", &EventBlocks::compileWhenStageClicked));
8889
EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "event_broadcast", &EventBlocks::compileBroadcast));
8990
EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "event_broadcastandwait", &EventBlocks::compileBroadcastAndWait));
9091
EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "event_whenbroadcastreceived", &EventBlocks::compileWhenBroadcastReceived));
@@ -142,6 +143,26 @@ TEST_F(EventBlocksTest, WhenThisSpriteClicked)
142143
ASSERT_TRUE(compiler.lists().empty());
143144
}
144145

146+
TEST_F(EventBlocksTest, WhenStageClicked)
147+
{
148+
Compiler compiler(&m_engineMock);
149+
150+
auto block = createEventBlock("a", "event_whenstageclicked");
151+
152+
compiler.init();
153+
154+
EXPECT_CALL(m_engineMock, addTargetClickScript(block));
155+
compiler.setBlock(block);
156+
EventBlocks::compileWhenStageClicked(&compiler);
157+
158+
compiler.end();
159+
160+
ASSERT_EQ(compiler.bytecode(), std::vector<unsigned int>({ vm::OP_START, vm::OP_HALT }));
161+
ASSERT_TRUE(compiler.constValues().empty());
162+
ASSERT_TRUE(compiler.variables().empty());
163+
ASSERT_TRUE(compiler.lists().empty());
164+
}
165+
145166
TEST_F(EventBlocksTest, Broadcast)
146167
{
147168
Compiler compiler(&m_engineMock);

0 commit comments

Comments
 (0)