Skip to content

Commit 6c288f8

Browse files
committed
Implement event_whenflagclicked
1 parent 02f80ac commit 6c288f8

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
@@ -20,10 +20,17 @@ std::string libscratchcpp::EventBlocks::description() const
2020
void EventBlocks::registerBlocks(IEngine *engine)
2121
{
2222
engine->addCompileFunction(this, "event_whentouchingobject", &compileWhenTouchingObject);
23+
engine->addCompileFunction(this, "event_whenflagclicked", &compileWhenFlagClicked);
2324
}
2425

2526
CompilerValue *EventBlocks::compileWhenTouchingObject(Compiler *compiler)
2627
{
2728
compiler->engine()->addWhenTouchingObjectScript(compiler->block());
2829
return nullptr;
2930
}
31+
32+
CompilerValue *EventBlocks::compileWhenFlagClicked(Compiler *compiler)
33+
{
34+
compiler->engine()->addGreenFlagScript(compiler->block());
35+
return nullptr;
36+
}

src/dev/blocks/eventblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class EventBlocks : public IExtension
1717

1818
private:
1919
static CompilerValue *compileWhenTouchingObject(Compiler *compiler);
20+
static CompilerValue *compileWhenFlagClicked(Compiler *compiler);
2021
};
2122

2223
} // namespace libscratchcpp

test/dev/blocks/event_blocks_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,16 @@ TEST_F(EventBlocksTest, WhenTouchingObject)
4141
EXPECT_CALL(m_engineMock, addWhenTouchingObjectScript(block));
4242
compiler.compile(block);
4343
}
44+
45+
TEST_F(EventBlocksTest, WhenFlagClicked)
46+
{
47+
auto target = std::make_shared<Sprite>();
48+
ScriptBuilder builder(m_extension.get(), m_engine, target);
49+
50+
builder.addBlock("event_whenflagclicked");
51+
auto block = builder.currentBlock();
52+
53+
Compiler compiler(&m_engineMock, target.get());
54+
EXPECT_CALL(m_engineMock, addGreenFlagScript(block));
55+
compiler.compile(block);
56+
}

0 commit comments

Comments
 (0)