@@ -27,12 +27,27 @@ Rgb SoundBlocks::color() const
2727void SoundBlocks::registerBlocks (IEngine *engine)
2828{
2929 engine->addCompileFunction (this , " sound_play" , &compilePlay);
30+ engine->addCompileFunction (this , " sound_playuntildone" , &compilePlayUntilDone);
3031}
3132
3233CompilerValue *SoundBlocks::compilePlay (Compiler *compiler)
3334{
3435 auto sound = compiler->addInput (" SOUND_MENU" );
35- compiler->addTargetFunctionCall (" sound_play" , Compiler::StaticType::Void, { Compiler::StaticType::Unknown }, { sound });
36+ compiler->addTargetFunctionCall (" sound_play" , Compiler::StaticType::Pointer, { Compiler::StaticType::Unknown }, { sound });
37+ return nullptr ;
38+ }
39+
40+ CompilerValue *SoundBlocks::compilePlayUntilDone (Compiler *compiler)
41+ {
42+ auto sound = compiler->addInput (" SOUND_MENU" );
43+ auto soundPtr = compiler->addTargetFunctionCall (" sound_play" , Compiler::StaticType::Pointer, { Compiler::StaticType::Unknown }, { sound });
44+
45+ compiler->beginLoopCondition ();
46+ auto numType = Compiler::StaticType::Number;
47+ auto playing = compiler->addFunctionCall (" sound_is_playing" , Compiler::StaticType::Bool, { Compiler::StaticType::Pointer }, { soundPtr });
48+ compiler->beginWhileLoop (playing);
49+ compiler->endLoop ();
50+
3651 return nullptr ;
3752}
3853
@@ -78,11 +93,23 @@ int sound_get_index(Target *target, const ValueData *sound)
7893 return -1 ;
7994}
8095
81- extern " C" void sound_play (Target *target, const ValueData *soundName)
96+ extern " C" Sound * sound_play (Target *target, const ValueData *soundName)
8297{
8398 int index = sound_get_index (target, soundName);
8499 auto sound = target->soundAt (index);
85100
86- if (sound)
101+ if (sound) {
87102 sound->start ();
103+ return sound.get ();
104+ }
105+
106+ return nullptr ;
107+ }
108+
109+ extern " C" bool sound_is_playing (Sound *sound)
110+ {
111+ if (!sound)
112+ return false ;
113+
114+ return sound->isPlaying ();
88115}
0 commit comments