|
7 | 7 | #include <scratchcpp/istacktimer.h> |
8 | 8 | #include <scratchcpp/irandomgenerator.h> |
9 | 9 | #include <scratchcpp/thread.h> |
| 10 | +#include <scratchcpp/promise.h> |
10 | 11 | #include <scratchcpp/sprite.h> |
11 | 12 | #include <scratchcpp/stage.h> |
12 | 13 | #include <scratchcpp/costume.h> |
@@ -59,6 +60,7 @@ void LooksBlocks::registerBlocks(IEngine *engine) |
59 | 60 | engine->addCompileFunction(this, "looks_goforwardbackwardlayers", &compileGoForwardBackwardLayers); |
60 | 61 | engine->addCompileFunction(this, "looks_backdropnumbername", &compileBackdropNumberName); |
61 | 62 | engine->addCompileFunction(this, "looks_costumenumbername", &compileCostumeNumberName); |
| 63 | + engine->addCompileFunction(this, "looks_switchbackdroptoandwait", &compileSwitchBackdropToAndWait); |
62 | 64 | } |
63 | 65 |
|
64 | 66 | void LooksBlocks::onInit(IEngine *engine) |
@@ -314,6 +316,21 @@ CompilerValue *LooksBlocks::compileCostumeNumberName(Compiler *compiler) |
314 | 316 | return compiler->addConstValue(Value()); |
315 | 317 | } |
316 | 318 |
|
| 319 | +CompilerValue *LooksBlocks::compileSwitchBackdropToAndWait(Compiler *compiler) |
| 320 | +{ |
| 321 | + auto backdrop = compiler->addInput("BACKDROP"); |
| 322 | + auto wait = compiler->addConstValue(true); |
| 323 | + compiler->addFunctionCallWithCtx("looks_switchbackdropto", Compiler::StaticType::Void, { Compiler::StaticType::Unknown }, { backdrop }); |
| 324 | + compiler->addFunctionCallWithCtx("looks_start_backdrop_scripts", Compiler::StaticType::Void, { Compiler::StaticType::Bool }, { wait }); |
| 325 | + |
| 326 | + auto hasBackdrops = compiler->addFunctionCallWithCtx("looks_backdrop_promise", Compiler::StaticType::Bool); |
| 327 | + compiler->beginIfStatement(hasBackdrops); |
| 328 | + compiler->createYield(); |
| 329 | + compiler->endIf(); |
| 330 | + |
| 331 | + return nullptr; |
| 332 | +} |
| 333 | + |
317 | 334 | extern "C" void looks_start_stack_timer(ExecutionContext *ctx, double duration) |
318 | 335 | { |
319 | 336 | ctx->stackTimer()->start(duration); |
@@ -557,3 +574,13 @@ extern "C" StringPtr *looks_costume_name(Target *target) |
557 | 574 | string_assign_cstring(ret, name.c_str()); |
558 | 575 | return ret; |
559 | 576 | } |
| 577 | + |
| 578 | +extern "C" bool looks_backdrop_promise(ExecutionContext *ctx) |
| 579 | +{ |
| 580 | + if (ctx->engine()->stage()->costumes().size() > 0) { |
| 581 | + ctx->setPromise(std::make_shared<Promise>()); |
| 582 | + return true; |
| 583 | + } |
| 584 | + |
| 585 | + return false; |
| 586 | +} |
0 commit comments