Skip to content

Commit 5ad63a4

Browse files
committed
Implement event_whenthisspriteclicked
1 parent 6c288f8 commit 5ad63a4

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
@@ -21,6 +21,7 @@ void EventBlocks::registerBlocks(IEngine *engine)
2121
{
2222
engine->addCompileFunction(this, "event_whentouchingobject", &compileWhenTouchingObject);
2323
engine->addCompileFunction(this, "event_whenflagclicked", &compileWhenFlagClicked);
24+
engine->addCompileFunction(this, "event_whenthisspriteclicked", &compileWhenThisSpriteClicked);
2425
}
2526

2627
CompilerValue *EventBlocks::compileWhenTouchingObject(Compiler *compiler)
@@ -34,3 +35,9 @@ CompilerValue *EventBlocks::compileWhenFlagClicked(Compiler *compiler)
3435
compiler->engine()->addGreenFlagScript(compiler->block());
3536
return nullptr;
3637
}
38+
39+
CompilerValue *EventBlocks::compileWhenThisSpriteClicked(Compiler *compiler)
40+
{
41+
compiler->engine()->addTargetClickScript(compiler->block());
42+
return nullptr;
43+
}

src/dev/blocks/eventblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class EventBlocks : public IExtension
1818
private:
1919
static CompilerValue *compileWhenTouchingObject(Compiler *compiler);
2020
static CompilerValue *compileWhenFlagClicked(Compiler *compiler);
21+
static CompilerValue *compileWhenThisSpriteClicked(Compiler *compiler);
2122
};
2223

2324
} // namespace libscratchcpp

test/dev/blocks/event_blocks_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,16 @@ TEST_F(EventBlocksTest, WhenFlagClicked)
5454
EXPECT_CALL(m_engineMock, addGreenFlagScript(block));
5555
compiler.compile(block);
5656
}
57+
58+
TEST_F(EventBlocksTest, WhenThisSpriteClicked)
59+
{
60+
auto target = std::make_shared<Sprite>();
61+
ScriptBuilder builder(m_extension.get(), m_engine, target);
62+
63+
builder.addBlock("event_whenthisspriteclicked");
64+
auto block = builder.currentBlock();
65+
66+
Compiler compiler(&m_engineMock, target.get());
67+
EXPECT_CALL(m_engineMock, addTargetClickScript(block));
68+
compiler.compile(block);
69+
}

0 commit comments

Comments
 (0)