Skip to content

Commit b54ac00

Browse files
committed
Implement sound_cleareffects block
1 parent 7af93e1 commit b54ac00

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/blocks/soundblocks.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void SoundBlocks::registerBlocks(IEngine *engine)
3636
engine->addCompileFunction(this, "sound_stopallsounds", &compileStopAllSounds);
3737
engine->addCompileFunction(this, "sound_seteffectto", &compileSetEffectTo);
3838
engine->addCompileFunction(this, "sound_changeeffectby", &compileChangeEffectBy);
39+
engine->addCompileFunction(this, "sound_cleareffects", &compileClearEffects);
3940
}
4041

4142
void SoundBlocks::onInit(IEngine *engine)
@@ -121,6 +122,12 @@ CompilerValue *SoundBlocks::compileChangeEffectBy(Compiler *compiler)
121122
return nullptr;
122123
}
123124

125+
CompilerValue *SoundBlocks::compileClearEffects(Compiler *compiler)
126+
{
127+
compiler->addTargetFunctionCall("sound_cleareffects");
128+
return nullptr;
129+
}
130+
124131
int sound_wrap_clamp_index(Target *target, int index)
125132
{
126133
const long soundCount = target->sounds().size();
@@ -210,3 +217,8 @@ extern "C" void sound_change_pan_effect(Target *target, double value)
210217
{
211218
target->setSoundEffectValue(Sound::Effect::Pan, target->soundEffectValue(Sound::Effect::Pan) + value);
212219
}
220+
221+
extern "C" void sound_cleareffects(Target *target)
222+
{
223+
target->clearSoundEffects();
224+
}

src/blocks/soundblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class SoundBlocks : public IExtension
2525
static CompilerValue *compileStopAllSounds(Compiler *compiler);
2626
static CompilerValue *compileSetEffectTo(Compiler *compiler);
2727
static CompilerValue *compileChangeEffectBy(Compiler *compiler);
28+
static CompilerValue *compileClearEffects(Compiler *compiler);
2829
};
2930

3031
} // namespace libscratchcpp

test/blocks/sound_blocks_test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,3 +1009,22 @@ TEST_F(SoundBlocksTest, ChangeEffectBy_Pan)
10091009
EXPECT_CALL(*target, setSoundEffectValue(Sound::Effect::Pan, -11.3));
10101010
thread.run();
10111011
}
1012+
1013+
TEST_F(SoundBlocksTest, ClearEffects)
1014+
{
1015+
auto target = std::make_shared<TargetMock>();
1016+
1017+
ScriptBuilder builder(m_extension.get(), m_engine, target);
1018+
builder.addBlock("sound_cleareffects");
1019+
auto block = builder.currentBlock();
1020+
1021+
Compiler compiler(&m_engineMock, target.get());
1022+
auto code = compiler.compile(block);
1023+
Script script(target.get(), block, &m_engineMock);
1024+
script.setCode(code);
1025+
Thread thread(target.get(), &m_engineMock, &script);
1026+
1027+
EXPECT_CALL(*target, clearSoundEffects());
1028+
EXPECT_CALL(*target, setSoundEffectValue).Times(0);
1029+
thread.run();
1030+
}

0 commit comments

Comments
 (0)