Skip to content

Commit 71e29fe

Browse files
committed
Implement looks_show block
1 parent 312220d commit 71e29fe

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/blocks/looksblocks.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void LooksBlocks::registerBlocks(IEngine *engine)
3636
engine->addCompileFunction(this, "looks_say", &compileSay);
3737
engine->addCompileFunction(this, "looks_thinkforsecs", &compileThinkForSecs);
3838
engine->addCompileFunction(this, "looks_think", &compileThink);
39+
engine->addCompileFunction(this, "looks_show", &compileShow);
3940
}
4041

4142
void LooksBlocks::onInit(IEngine *engine)
@@ -106,6 +107,14 @@ CompilerValue *LooksBlocks::compileThink(Compiler *compiler)
106107
return nullptr;
107108
}
108109

110+
CompilerValue *LooksBlocks::compileShow(Compiler *compiler)
111+
{
112+
if (!compiler->target()->isStage())
113+
compiler->addTargetFunctionCall("looks_show");
114+
115+
return nullptr;
116+
}
117+
109118
extern "C" void looks_start_stack_timer(ExecutionContext *ctx, double duration)
110119
{
111120
ctx->stackTimer()->start(duration);
@@ -149,3 +158,8 @@ extern "C" void looks_think(ExecutionContext *ctx, const StringPtr *message, boo
149158
{
150159
looks_show_bubble(ctx->thread(), TextBubble::Type::Think, message, saveThread);
151160
}
161+
162+
extern "C" void looks_show(Sprite *sprite)
163+
{
164+
sprite->setVisible(true);
165+
}

src/blocks/looksblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class LooksBlocks : public IExtension
2828
static CompilerValue *compileSay(Compiler *compiler);
2929
static CompilerValue *compileThinkForSecs(Compiler *compiler);
3030
static CompilerValue *compileThink(Compiler *compiler);
31+
static CompilerValue *compileShow(Compiler *compiler);
3132
};
3233

3334
} // namespace libscratchcpp

test/blocks/looks_blocks_test.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,34 @@ TEST_F(LooksBlocksTest, SayAndThink)
198198
ASSERT_EQ(sprite->bubble()->owner(), nullptr);
199199
}
200200
}
201+
202+
TEST_F(LooksBlocksTest, Show)
203+
{
204+
{
205+
auto sprite = std::make_shared<Sprite>();
206+
ScriptBuilder builder(m_extension.get(), m_engine, sprite);
207+
208+
builder.addBlock("looks_show");
209+
builder.build();
210+
211+
sprite->setVisible(false);
212+
213+
builder.run();
214+
ASSERT_TRUE(sprite->visible());
215+
216+
builder.run();
217+
ASSERT_TRUE(sprite->visible());
218+
}
219+
220+
m_engine->clear();
221+
222+
{
223+
auto stage = std::make_shared<Stage>();
224+
ScriptBuilder builder(m_extension.get(), m_engine, stage);
225+
226+
builder.addBlock("looks_show");
227+
228+
builder.build();
229+
builder.run();
230+
}
231+
}

0 commit comments

Comments
 (0)