File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff 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
4243void 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+
118127extern " 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+ }
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments