33#pragma once
44
55#include < scratchcpp/iextension.h>
6+ #include < vector>
7+ #include < memory>
68
79namespace libscratchcpp
810{
911
12+ class IAudioInput ;
13+ class IClock ;
14+ class ExecutionContext ;
15+ class Thread ;
16+
1017class SensingBlocks : public IExtension
1118{
1219 public:
@@ -15,6 +22,55 @@ class SensingBlocks : public IExtension
1522 Rgb color () const override ;
1623
1724 void registerBlocks (IEngine *engine) override ;
25+ void onInit (IEngine *engine) override ;
26+
27+ static void clearQuestions ();
28+ static void askQuestion (ExecutionContext *ctx, const StringPtr *question);
29+
30+ static inline IAudioInput *audioInput = nullptr ;
31+ static inline IClock *clock = nullptr ;
32+
33+ private:
34+ struct Question
35+ {
36+ Question (const std::string &question, Thread *thread, bool wasVisible, bool wasStage) :
37+ question (question),
38+ thread (thread),
39+ wasVisible (wasVisible),
40+ wasStage (wasStage)
41+ {
42+ }
43+
44+ std::string question;
45+ Thread *thread = nullptr ;
46+ bool wasVisible = false ;
47+ bool wasStage = false ;
48+ };
49+
50+ static CompilerValue *compileTouchingObject (Compiler *compiler);
51+ static CompilerValue *compileTouchingColor (Compiler *compiler);
52+ static CompilerValue *compileColorIsTouchingColor (Compiler *compiler);
53+ static CompilerValue *compileDistanceTo (Compiler *compiler);
54+ static CompilerValue *compileAskAndWait (Compiler *compiler);
55+ static CompilerValue *compileAnswer (Compiler *compiler);
56+ static CompilerValue *compileKeyPressed (Compiler *compiler);
57+ static CompilerValue *compileMouseDown (Compiler *compiler);
58+ static CompilerValue *compileMouseX (Compiler *compiler);
59+ static CompilerValue *compileMouseY (Compiler *compiler);
60+ static CompilerValue *compileSetDragMode (Compiler *compiler);
61+ static CompilerValue *compileLoudness (Compiler *compiler);
62+ static CompilerValue *compileLoud (Compiler *compiler);
63+ static CompilerValue *compileTimer (Compiler *compiler);
64+ static CompilerValue *compileResetTimer (Compiler *compiler);
65+ static CompilerValue *compileOf (Compiler *compiler);
66+ static CompilerValue *compileCurrent (Compiler *compiler);
67+ static CompilerValue *compileDaysSince2000 (Compiler *compiler);
68+
69+ static void onAnswer (const std::string &answer);
70+ static void enqueueAsk (const std::string &question, Thread *thread);
71+ static void askNextQuestion ();
72+
73+ static inline std::vector<std::unique_ptr<Question>> m_questions;
1874};
1975
2076} // namespace libscratchcpp
0 commit comments