Skip to content

Commit ac6bb6e

Browse files
committed
Implement looks_cleargraphiceffects
1 parent fb2b55d commit ac6bb6e

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/blocks/looksblocks.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void LooksBlocks::registerBlocks(IEngine *engine)
4949
engine->addCompileFunction(this, "looks_hide", &compileHide);
5050
engine->addCompileFunction(this, "looks_changeeffectby", &compileChangeEffectBy);
5151
engine->addCompileFunction(this, "looks_seteffectto", &compileSetEffectTo);
52+
engine->addCompileFunction(this, "looks_cleargraphiceffects", &compileClearGraphicEffects);
5253
}
5354

5455
void LooksBlocks::onInit(IEngine *engine)
@@ -198,6 +199,12 @@ CompilerValue *LooksBlocks::compileSetEffectTo(Compiler *compiler)
198199
return nullptr;
199200
}
200201

202+
CompilerValue *LooksBlocks::compileClearGraphicEffects(Compiler *compiler)
203+
{
204+
compiler->addTargetFunctionCall("looks_cleargraphiceffects");
205+
return nullptr;
206+
}
207+
201208
extern "C" void looks_start_stack_timer(ExecutionContext *ctx, double duration)
202209
{
203210
ctx->stackTimer()->start(duration);
@@ -262,3 +269,8 @@ extern "C" void looks_seteffectto(Target *target, double index, double value)
262269
{
263270
target->setGraphicsEffectValue(LooksBlocks::getEffect(target->engine(), index), value);
264271
}
272+
273+
extern "C" void looks_cleargraphiceffects(Target *target)
274+
{
275+
target->clearGraphicsEffects();
276+
}

src/blocks/looksblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class LooksBlocks : public IExtension
3939
static CompilerValue *compileHide(Compiler *compiler);
4040
static CompilerValue *compileChangeEffectBy(Compiler *compiler);
4141
static CompilerValue *compileSetEffectTo(Compiler *compiler);
42+
static CompilerValue *compileClearGraphicEffects(Compiler *compiler);
4243

4344
IEngine *m_engine = nullptr;
4445
std::unordered_map<std::string, long> m_effectMap;

test/blocks/looks_blocks_test.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,34 @@ TEST_F(LooksBlocksTest, SetEffectTo)
495495
builder.run();
496496
}
497497
}
498+
499+
TEST_F(LooksBlocksTest, ClearGraphicEffects)
500+
{
501+
auto sprite = std::make_shared<Sprite>();
502+
sprite->setEngine(m_engine);
503+
504+
ScriptBuilder builder(m_extension.get(), m_engine, sprite);
505+
IGraphicsEffect *effect1 = ScratchConfiguration::getGraphicsEffect("WHIRL");
506+
IGraphicsEffect *effect2 = ScratchConfiguration::getGraphicsEffect("GHOST");
507+
IGraphicsEffect *effect3 = ScratchConfiguration::getGraphicsEffect("MOSAIC");
508+
ASSERT_TRUE(effect1);
509+
ASSERT_TRUE(effect2);
510+
ASSERT_TRUE(effect3);
511+
512+
builder.addBlock("looks_cleargraphiceffects");
513+
auto block = builder.currentBlock();
514+
515+
Compiler compiler(m_engine, sprite.get());
516+
auto code = compiler.compile(block);
517+
Script script(sprite.get(), block, m_engine);
518+
script.setCode(code);
519+
Thread thread(sprite.get(), m_engine, &script);
520+
521+
sprite->setGraphicsEffectValue(effect1, 86.84);
522+
sprite->setGraphicsEffectValue(effect2, -5.18);
523+
sprite->setGraphicsEffectValue(effect3, 12.98);
524+
thread.run();
525+
ASSERT_EQ(sprite->graphicsEffectValue(effect1), 0);
526+
ASSERT_EQ(sprite->graphicsEffectValue(effect2), 0);
527+
ASSERT_EQ(sprite->graphicsEffectValue(effect3), 0);
528+
}

0 commit comments

Comments
 (0)