Skip to content

Commit f5f4fba

Browse files
committed
Implement looks_cleargraphiceffects block
1 parent 7bcc078 commit f5f4fba

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

src/blocks/looksblocks.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void LooksBlocks::registerBlocks(IEngine *engine)
2828
engine->addCompileFunction(this, "looks_hide", &compileHide);
2929
engine->addCompileFunction(this, "looks_changeeffectby", &compileChangeEffectBy);
3030
engine->addCompileFunction(this, "looks_seteffectto", &compileSetEffectTo);
31+
engine->addCompileFunction(this, "looks_cleargraphiceffects", &compileClearGraphicEffects);
3132
engine->addCompileFunction(this, "looks_changesizeby", &compileChangeSizeBy);
3233
engine->addCompileFunction(this, "looks_setsizeto", &compileSetSizeTo);
3334
engine->addCompileFunction(this, "looks_size", &compileSize);
@@ -238,6 +239,11 @@ void LooksBlocks::compileSetEffectTo(Compiler *compiler)
238239
}
239240
}
240241

242+
void LooksBlocks::compileClearGraphicEffects(Compiler *compiler)
243+
{
244+
compiler->addFunctionCall(&clearGraphicEffects);
245+
}
246+
241247
void LooksBlocks::compileChangeSizeBy(Compiler *compiler)
242248
{
243249
compiler->addInput(CHANGE);
@@ -594,6 +600,16 @@ unsigned int LooksBlocks::setGhostEffectTo(VirtualMachine *vm)
594600
return 1;
595601
}
596602

603+
unsigned int LooksBlocks::clearGraphicEffects(VirtualMachine *vm)
604+
{
605+
Sprite *sprite = dynamic_cast<Sprite *>(vm->target());
606+
607+
if (sprite)
608+
sprite->clearGraphicsEffects();
609+
610+
return 0;
611+
}
612+
597613
unsigned int LooksBlocks::changeSizeBy(VirtualMachine *vm)
598614
{
599615
Sprite *sprite = dynamic_cast<Sprite *>(vm->target());

src/blocks/looksblocks.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class LooksBlocks : public IBlockSection
5454
static void compileHide(Compiler *compiler);
5555
static void compileChangeEffectBy(Compiler *compiler);
5656
static void compileSetEffectTo(Compiler *compiler);
57+
static void compileClearGraphicEffects(Compiler *compiler);
5758
static void compileChangeSizeBy(Compiler *compiler);
5859
static void compileSetSizeTo(Compiler *compiler);
5960
static void compileSize(Compiler *compiler);
@@ -86,6 +87,7 @@ class LooksBlocks : public IBlockSection
8687
static unsigned int setBrightnessEffectTo(VirtualMachine *vm);
8788
static unsigned int setGhostEffectTo(VirtualMachine *vm);
8889

90+
static unsigned int clearGraphicEffects(VirtualMachine *vm);
8991
static unsigned int changeSizeBy(VirtualMachine *vm);
9092
static unsigned int setSizeTo(VirtualMachine *vm);
9193
static unsigned int size(VirtualMachine *vm);

test/blocks/looks_blocks_test.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ TEST_F(LooksBlocksTest, RegisterBlocks)
108108
EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "looks_hide", &LooksBlocks::compileHide));
109109
EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "looks_changeeffectby", &LooksBlocks::compileChangeEffectBy));
110110
EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "looks_seteffectto", &LooksBlocks::compileSetEffectTo));
111+
EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "looks_cleargraphiceffects", &LooksBlocks::compileClearGraphicEffects));
111112
EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "looks_changesizeby", &LooksBlocks::compileChangeSizeBy));
112113
EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "looks_setsizeto", &LooksBlocks::compileSetSizeTo));
113114
EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "looks_size", &LooksBlocks::compileSize));
@@ -785,6 +786,43 @@ TEST_F(LooksBlocksTest, SetEffectToImpl)
785786
ASSERT_EQ(sprite.graphicsEffectValue(ScratchConfiguration::getGraphicsEffect("ghost")), 0.01);*/
786787
}
787788

789+
TEST_F(LooksBlocksTest, ClearGraphicEffects)
790+
{
791+
Compiler compiler(&m_engineMock);
792+
793+
auto block = std::make_shared<Block>("a", "looks_cleargraphiceffects");
794+
795+
EXPECT_CALL(m_engineMock, functionIndex(&LooksBlocks::clearGraphicEffects)).WillOnce(Return(0));
796+
797+
compiler.init();
798+
compiler.setBlock(block);
799+
LooksBlocks::compileClearGraphicEffects(&compiler);
800+
compiler.end();
801+
802+
ASSERT_EQ(compiler.bytecode(), std::vector<unsigned int>({ vm::OP_START, vm::OP_EXEC, 0, vm::OP_HALT }));
803+
ASSERT_TRUE(compiler.constValues().empty());
804+
}
805+
806+
TEST_F(LooksBlocksTest, ClearGraphicEffectsImpl)
807+
{
808+
static unsigned int bytecode[] = { vm::OP_START, vm::OP_EXEC, 0, vm::OP_HALT };
809+
static BlockFunc functions[] = { &LooksBlocks::clearGraphicEffects };
810+
811+
Sprite sprite;
812+
GraphicsEffectMock effect1, effect2;
813+
sprite.setGraphicsEffectValue(&effect1, 48.21);
814+
sprite.setGraphicsEffectValue(&effect2, -107.08);
815+
816+
VirtualMachine vm(&sprite, nullptr, nullptr);
817+
vm.setBytecode(bytecode);
818+
vm.setFunctions(functions);
819+
vm.run();
820+
821+
ASSERT_EQ(vm.registerCount(), 0);
822+
ASSERT_EQ(sprite.graphicsEffectValue(&effect1), 0);
823+
ASSERT_EQ(sprite.graphicsEffectValue(&effect2), 0);
824+
}
825+
788826
TEST_F(LooksBlocksTest, ChangeSizeBy)
789827
{
790828
Compiler compiler(&m_engineMock);

0 commit comments

Comments
 (0)