Skip to content

Commit c8dd2f3

Browse files
committed
Implement event_whengreaterthan
1 parent 715a95e commit c8dd2f3

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/dev/blocks/eventblocks.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void EventBlocks::registerBlocks(IEngine *engine)
2828
engine->addCompileFunction(this, "event_whenstageclicked", &compileWhenStageClicked);
2929
engine->addCompileFunction(this, "event_whenbroadcastreceived", &compileWhenBroadcastReceived);
3030
engine->addCompileFunction(this, "event_whenbackdropswitchesto", &compileWhenBackdropSwitchesTo);
31+
engine->addCompileFunction(this, "event_whengreaterthan", &compileWhenGreaterThan);
3132
}
3233

3334
CompilerValue *EventBlocks::compileWhenTouchingObject(Compiler *compiler)
@@ -77,3 +78,9 @@ CompilerValue *EventBlocks::compileWhenBackdropSwitchesTo(Compiler *compiler)
7778

7879
return nullptr;
7980
}
81+
82+
CompilerValue *EventBlocks::compileWhenGreaterThan(Compiler *compiler)
83+
{
84+
compiler->engine()->addWhenGreaterThanScript(compiler->block());
85+
return nullptr;
86+
}

src/dev/blocks/eventblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class EventBlocks : public IExtension
2222
static CompilerValue *compileWhenStageClicked(Compiler *compiler);
2323
static CompilerValue *compileWhenBroadcastReceived(Compiler *compiler);
2424
static CompilerValue *compileWhenBackdropSwitchesTo(Compiler *compiler);
25+
static CompilerValue *compileWhenGreaterThan(Compiler *compiler);
2526
};
2627

2728
} // namespace libscratchcpp

test/dev/blocks/event_blocks_test.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,20 @@ TEST_F(EventBlocksTest, WhenBackdropSwitchesTo)
113113
EXPECT_CALL(m_engineMock, addBackdropChangeScript(block, block->fieldAt(0).get()));
114114
compiler.compile(block);
115115
}
116+
117+
// TODO: Add test for when greater than hat predicate
118+
119+
TEST_F(EventBlocksTest, WhenGreaterThan)
120+
{
121+
auto target = std::make_shared<Sprite>();
122+
ScriptBuilder builder(m_extension.get(), m_engine, target);
123+
124+
builder.addBlock("event_whengreaterthan");
125+
builder.addDropdownField("WHENGREATERTHANMENU", "LOUDNESS");
126+
builder.addValueInput("VALUE", 8.9);
127+
auto block = builder.currentBlock();
128+
129+
Compiler compiler(&m_engineMock, target.get());
130+
EXPECT_CALL(m_engineMock, addWhenGreaterThanScript(block));
131+
compiler.compile(block);
132+
}

0 commit comments

Comments
 (0)