Skip to content

Commit 312220d

Browse files
committed
Implement looks_think block
1 parent ba5604c commit 312220d

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

src/blocks/looksblocks.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void LooksBlocks::registerBlocks(IEngine *engine)
3535
engine->addCompileFunction(this, "looks_sayforsecs", &compileSayForSecs);
3636
engine->addCompileFunction(this, "looks_say", &compileSay);
3737
engine->addCompileFunction(this, "looks_thinkforsecs", &compileThinkForSecs);
38+
engine->addCompileFunction(this, "looks_think", &compileThink);
3839
}
3940

4041
void LooksBlocks::onInit(IEngine *engine)
@@ -97,6 +98,14 @@ CompilerValue *LooksBlocks::compileThinkForSecs(Compiler *compiler)
9798
return nullptr;
9899
}
99100

101+
CompilerValue *LooksBlocks::compileThink(Compiler *compiler)
102+
{
103+
auto message = compiler->addInput("MESSAGE");
104+
auto saveThread = compiler->addConstValue(false);
105+
compiler->addFunctionCallWithCtx("looks_think", Compiler::StaticType::Void, { Compiler::StaticType::String, Compiler::StaticType::Bool }, { message, saveThread });
106+
return nullptr;
107+
}
108+
100109
extern "C" void looks_start_stack_timer(ExecutionContext *ctx, double duration)
101110
{
102111
ctx->stackTimer()->start(duration);

src/blocks/looksblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class LooksBlocks : public IExtension
2727
static CompilerValue *compileSayForSecs(Compiler *compiler);
2828
static CompilerValue *compileSay(Compiler *compiler);
2929
static CompilerValue *compileThinkForSecs(Compiler *compiler);
30+
static CompilerValue *compileThink(Compiler *compiler);
3031
};
3132

3233
} // namespace libscratchcpp

test/blocks/looks_blocks_test.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,28 @@ TEST_F(LooksBlocksTest, SayAndThinkForSecs)
173173
}
174174
}
175175

176-
TEST_F(LooksBlocksTest, Say)
176+
TEST_F(LooksBlocksTest, SayAndThink)
177177
{
178-
auto sprite = std::make_shared<Sprite>();
179-
sprite->setEngine(&m_engineMock);
180-
ScriptBuilder builder(m_extension.get(), m_engine, sprite);
178+
std::vector<TextBubble::Type> types = { TextBubble::Type::Say, TextBubble::Type::Think };
179+
std::vector<std::string> opcodes = { "looks_say", "looks_think" };
180+
181+
for (int i = 0; i < types.size(); i++) {
182+
TextBubble::Type type = types[i];
183+
const std::string &opcode = opcodes[i];
184+
185+
auto sprite = std::make_shared<Sprite>();
186+
sprite->setEngine(&m_engineMock);
187+
m_engine->clear();
188+
189+
ScriptBuilder builder(m_extension.get(), m_engine, sprite);
181190

182-
builder.addBlock("looks_say");
183-
builder.addValueInput("MESSAGE", "Hello world");
191+
builder.addBlock(opcode);
192+
builder.addValueInput("MESSAGE", "Hello world");
184193

185-
builder.build();
186-
builder.run();
187-
ASSERT_EQ(sprite->bubble()->text(), "Hello world");
188-
ASSERT_EQ(sprite->bubble()->type(), TextBubble::Type::Say);
189-
ASSERT_EQ(sprite->bubble()->owner(), nullptr);
194+
builder.build();
195+
builder.run();
196+
ASSERT_EQ(sprite->bubble()->text(), "Hello world");
197+
ASSERT_EQ(sprite->bubble()->type(), type);
198+
ASSERT_EQ(sprite->bubble()->owner(), nullptr);
199+
}
190200
}

0 commit comments

Comments
 (0)