Skip to content

Commit bb87835

Browse files
committed
Implement looks_hide block
1 parent 71e29fe commit bb87835

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
@@ -37,6 +37,7 @@ void LooksBlocks::registerBlocks(IEngine *engine)
3737
engine->addCompileFunction(this, "looks_thinkforsecs", &compileThinkForSecs);
3838
engine->addCompileFunction(this, "looks_think", &compileThink);
3939
engine->addCompileFunction(this, "looks_show", &compileShow);
40+
engine->addCompileFunction(this, "looks_hide", &compileHide);
4041
}
4142

4243
void LooksBlocks::onInit(IEngine *engine)
@@ -115,6 +116,14 @@ CompilerValue *LooksBlocks::compileShow(Compiler *compiler)
115116
return nullptr;
116117
}
117118

119+
CompilerValue *LooksBlocks::compileHide(Compiler *compiler)
120+
{
121+
if (!compiler->target()->isStage())
122+
compiler->addTargetFunctionCall("looks_hide");
123+
124+
return nullptr;
125+
}
126+
118127
extern "C" void looks_start_stack_timer(ExecutionContext *ctx, double duration)
119128
{
120129
ctx->stackTimer()->start(duration);
@@ -163,3 +172,8 @@ extern "C" void looks_show(Sprite *sprite)
163172
{
164173
sprite->setVisible(true);
165174
}
175+
176+
extern "C" void looks_hide(Sprite *sprite)
177+
{
178+
sprite->setVisible(false);
179+
}

src/blocks/looksblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class LooksBlocks : public IExtension
2929
static CompilerValue *compileThinkForSecs(Compiler *compiler);
3030
static CompilerValue *compileThink(Compiler *compiler);
3131
static CompilerValue *compileShow(Compiler *compiler);
32+
static CompilerValue *compileHide(Compiler *compiler);
3233
};
3334

3435
} // namespace libscratchcpp

test/blocks/looks_blocks_test.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,34 @@ TEST_F(LooksBlocksTest, Show)
229229
builder.run();
230230
}
231231
}
232+
233+
TEST_F(LooksBlocksTest, Hide)
234+
{
235+
{
236+
auto sprite = std::make_shared<Sprite>();
237+
ScriptBuilder builder(m_extension.get(), m_engine, sprite);
238+
239+
builder.addBlock("looks_hide");
240+
builder.build();
241+
242+
sprite->setVisible(true);
243+
244+
builder.run();
245+
ASSERT_FALSE(sprite->visible());
246+
247+
builder.run();
248+
ASSERT_FALSE(sprite->visible());
249+
}
250+
251+
m_engine->clear();
252+
253+
{
254+
auto stage = std::make_shared<Stage>();
255+
ScriptBuilder builder(m_extension.get(), m_engine, stage);
256+
257+
builder.addBlock("looks_hide");
258+
259+
builder.build();
260+
builder.run();
261+
}
262+
}

0 commit comments

Comments
 (0)