|
5 | 5 | #include <scratchcpp/compilerconstant.h> |
6 | 6 | #include <scratchcpp/sprite.h> |
7 | 7 | #include <scratchcpp/input.h> |
| 8 | +#include <scratchcpp/field.h> |
8 | 9 | #include <scratchcpp/value.h> |
9 | 10 | #include <scratchcpp/executioncontext.h> |
10 | 11 | #include <scratchcpp/thread.h> |
@@ -52,6 +53,7 @@ void MotionBlocks::registerBlocks(IEngine *engine) |
52 | 53 | engine->addCompileFunction(this, "motion_changeyby", &compileChangeYBy); |
53 | 54 | engine->addCompileFunction(this, "motion_sety", &compileSetY); |
54 | 55 | engine->addCompileFunction(this, "motion_ifonedgebounce", &compileIfOnEdgeBounce); |
| 56 | + engine->addCompileFunction(this, "motion_setrotationstyle", &compileSetRotationStyle); |
55 | 57 | } |
56 | 58 |
|
57 | 59 | CompilerValue *MotionBlocks::compileMoveSteps(Compiler *compiler) |
@@ -299,6 +301,32 @@ CompilerValue *MotionBlocks::compileIfOnEdgeBounce(Compiler *compiler) |
299 | 301 | return nullptr; |
300 | 302 | } |
301 | 303 |
|
| 304 | +CompilerValue *MotionBlocks::compileSetRotationStyle(Compiler *compiler) |
| 305 | +{ |
| 306 | + Target *target = compiler->target(); |
| 307 | + |
| 308 | + if (target->isStage()) |
| 309 | + return nullptr; |
| 310 | + |
| 311 | + Sprite *sprite = static_cast<Sprite *>(target); |
| 312 | + Field *field = compiler->field("STYLE"); |
| 313 | + |
| 314 | + if (!field) |
| 315 | + return nullptr; |
| 316 | + |
| 317 | + std::string option = field->value().toString(); |
| 318 | + sprite->setRotationStyle(field->value().toString()); |
| 319 | + |
| 320 | + if (option == "left-right") |
| 321 | + compiler->addTargetFunctionCall("motion_set_left_right_style"); |
| 322 | + else if (option == "don't rotate") |
| 323 | + compiler->addTargetFunctionCall("motion_set_do_not_rotate_style"); |
| 324 | + else if (option == "all around") |
| 325 | + compiler->addTargetFunctionCall("motion_set_all_around_style"); |
| 326 | + |
| 327 | + return nullptr; |
| 328 | +} |
| 329 | + |
302 | 330 | extern "C" void motion_movesteps(Sprite *sprite, double steps) |
303 | 331 | { |
304 | 332 | double dir = sprite->direction(); |
@@ -667,6 +695,21 @@ extern "C" void motion_ifonedgebounce(Sprite *sprite) |
667 | 695 | sprite->setPosition(fencedX, fencedY); |
668 | 696 | } |
669 | 697 |
|
| 698 | +extern "C" void motion_set_left_right_style(Sprite *sprite) |
| 699 | +{ |
| 700 | + sprite->setRotationStyle(Sprite::RotationStyle::LeftRight); |
| 701 | +} |
| 702 | + |
| 703 | +extern "C" void motion_set_do_not_rotate_style(Sprite *sprite) |
| 704 | +{ |
| 705 | + sprite->setRotationStyle(Sprite::RotationStyle::DoNotRotate); |
| 706 | +} |
| 707 | + |
| 708 | +extern "C" void motion_set_all_around_style(Sprite *sprite) |
| 709 | +{ |
| 710 | + sprite->setRotationStyle(Sprite::RotationStyle::AllAround); |
| 711 | +} |
| 712 | + |
670 | 713 | extern "C" double motion_xposition(Sprite *sprite) |
671 | 714 | { |
672 | 715 | return sprite->x(); |
|
0 commit comments