Skip to content

Commit 60d4a7e

Browse files
committed
Implement looks_say block
1 parent 0744481 commit 60d4a7e

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/blocks/looksblocks.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Rgb LooksBlocks::color() const
3333
void LooksBlocks::registerBlocks(IEngine *engine)
3434
{
3535
engine->addCompileFunction(this, "looks_sayforsecs", &compileSayForSecs);
36+
engine->addCompileFunction(this, "looks_say", &compileSay);
3637
}
3738

3839
void LooksBlocks::onInit(IEngine *engine)
@@ -81,6 +82,14 @@ CompilerValue *LooksBlocks::compileSayForSecs(Compiler *compiler)
8182
return nullptr;
8283
}
8384

85+
CompilerValue *LooksBlocks::compileSay(Compiler *compiler)
86+
{
87+
auto message = compiler->addInput("MESSAGE");
88+
auto saveThread = compiler->addConstValue(false);
89+
compiler->addFunctionCallWithCtx("looks_say", Compiler::StaticType::Void, { Compiler::StaticType::String, Compiler::StaticType::Bool }, { message, saveThread });
90+
return nullptr;
91+
}
92+
8493
extern "C" void looks_start_stack_timer(ExecutionContext *ctx, double duration)
8594
{
8695
ctx->stackTimer()->start(duration);

src/blocks/looksblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class LooksBlocks : public IExtension
2525
private:
2626
static void compileSayOrThinkForSecs(Compiler *compiler, const std::string function);
2727
static CompilerValue *compileSayForSecs(Compiler *compiler);
28+
static CompilerValue *compileSay(Compiler *compiler);
2829
};
2930

3031
} // namespace libscratchcpp

test/blocks/looks_blocks_test.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,19 @@ TEST_F(LooksBlocksTest, SayForSecs)
162162
ASSERT_EQ(sprite->bubble()->text(), "test");
163163
ASSERT_EQ(sprite->bubble()->type(), TextBubble::Type::Say);
164164
}
165+
166+
TEST_F(LooksBlocksTest, Say)
167+
{
168+
auto sprite = std::make_shared<Sprite>();
169+
sprite->setEngine(&m_engineMock);
170+
ScriptBuilder builder(m_extension.get(), m_engine, sprite);
171+
172+
builder.addBlock("looks_say");
173+
builder.addValueInput("MESSAGE", "Hello world");
174+
175+
builder.build();
176+
builder.run();
177+
ASSERT_EQ(sprite->bubble()->text(), "Hello world");
178+
ASSERT_EQ(sprite->bubble()->type(), TextBubble::Type::Say);
179+
ASSERT_EQ(sprite->bubble()->owner(), nullptr);
180+
}

0 commit comments

Comments
 (0)