Skip to content

Commit 06718d6

Browse files
committed
Implement event_whenstageclicked
1 parent 5ad63a4 commit 06718d6

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/dev/blocks/eventblocks.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void EventBlocks::registerBlocks(IEngine *engine)
2222
engine->addCompileFunction(this, "event_whentouchingobject", &compileWhenTouchingObject);
2323
engine->addCompileFunction(this, "event_whenflagclicked", &compileWhenFlagClicked);
2424
engine->addCompileFunction(this, "event_whenthisspriteclicked", &compileWhenThisSpriteClicked);
25+
engine->addCompileFunction(this, "event_whenstageclicked", &compileWhenStageClicked);
2526
}
2627

2728
CompilerValue *EventBlocks::compileWhenTouchingObject(Compiler *compiler)
@@ -41,3 +42,9 @@ CompilerValue *EventBlocks::compileWhenThisSpriteClicked(Compiler *compiler)
4142
compiler->engine()->addTargetClickScript(compiler->block());
4243
return nullptr;
4344
}
45+
46+
CompilerValue *EventBlocks::compileWhenStageClicked(Compiler *compiler)
47+
{
48+
compiler->engine()->addTargetClickScript(compiler->block());
49+
return nullptr;
50+
}

src/dev/blocks/eventblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class EventBlocks : public IExtension
1919
static CompilerValue *compileWhenTouchingObject(Compiler *compiler);
2020
static CompilerValue *compileWhenFlagClicked(Compiler *compiler);
2121
static CompilerValue *compileWhenThisSpriteClicked(Compiler *compiler);
22+
static CompilerValue *compileWhenStageClicked(Compiler *compiler);
2223
};
2324

2425
} // namespace libscratchcpp

test/dev/blocks/event_blocks_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,16 @@ TEST_F(EventBlocksTest, WhenThisSpriteClicked)
6767
EXPECT_CALL(m_engineMock, addTargetClickScript(block));
6868
compiler.compile(block);
6969
}
70+
71+
TEST_F(EventBlocksTest, WhenStageClicked)
72+
{
73+
auto target = std::make_shared<Sprite>();
74+
ScriptBuilder builder(m_extension.get(), m_engine, target);
75+
76+
builder.addBlock("event_whenstageclicked");
77+
auto block = builder.currentBlock();
78+
79+
Compiler compiler(&m_engineMock, target.get());
80+
EXPECT_CALL(m_engineMock, addTargetClickScript(block));
81+
compiler.compile(block);
82+
}

0 commit comments

Comments
 (0)