|
34 | 34 | using namespace libscratchcpp; |
35 | 35 |
|
36 | 36 | const std::unordered_map<Engine::HatType, bool> Engine::m_hatRestartExistingThreads = { |
37 | | - { HatType::GreenFlag, true }, |
38 | | - { HatType::BroadcastReceived, true }, |
39 | | - { HatType::BackdropChanged, true }, |
40 | | - { HatType::CloneInit, false }, |
41 | | - { HatType::KeyPressed, false } |
| 37 | + { HatType::GreenFlag, true }, { HatType::BroadcastReceived, true }, { HatType::BackdropChanged, true }, |
| 38 | + { HatType::CloneInit, false }, { HatType::KeyPressed, false }, { HatType::TargetClicked, true } |
42 | 39 | }; |
43 | 40 |
|
44 | 41 | Engine::Engine() : |
@@ -686,7 +683,7 @@ void Engine::setMousePressed(bool pressed) |
686 | 683 |
|
687 | 684 | void Engine::clickTarget(Target *target) |
688 | 685 | { |
689 | | - // TODO: Implement this (#92, #93) |
| 686 | + startHats(HatType::TargetClicked, {}, target); |
690 | 687 | } |
691 | 688 |
|
692 | 689 | unsigned int Engine::stageWidth() const |
@@ -969,6 +966,11 @@ void Engine::addKeyPressScript(std::shared_ptr<Block> hatBlock, int fieldId) |
969 | 966 | addHatField(script, HatField::KeyOption, fieldId); |
970 | 967 | } |
971 | 968 |
|
| 969 | +void Engine::addTargetClickScript(std::shared_ptr<Block> hatBlock) |
| 970 | +{ |
| 971 | + addHatToMap(m_whenTargetClickedHats, m_scripts[hatBlock].get()); |
| 972 | +} |
| 973 | + |
972 | 974 | const std::vector<std::shared_ptr<Target>> &Engine::targets() const |
973 | 975 | { |
974 | 976 | return m_targets; |
@@ -1354,6 +1356,9 @@ const std::vector<Script *> &Engine::getHats(Target *target, HatType type) |
1354 | 1356 | case HatType::KeyPressed: |
1355 | 1357 | return m_whenKeyPressedHats[target]; |
1356 | 1358 |
|
| 1359 | + case HatType::TargetClicked: |
| 1360 | + return m_whenTargetClickedHats[target]; |
| 1361 | + |
1357 | 1362 | default: { |
1358 | 1363 | static const std::vector<Script *> empty = {}; |
1359 | 1364 | return empty; |
|
0 commit comments