Skip to content

Commit a8525ba

Browse files
committed
Implement looks_changesizeby block
1 parent ac6bb6e commit a8525ba

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/blocks/looksblocks.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void LooksBlocks::registerBlocks(IEngine *engine)
5050
engine->addCompileFunction(this, "looks_changeeffectby", &compileChangeEffectBy);
5151
engine->addCompileFunction(this, "looks_seteffectto", &compileSetEffectTo);
5252
engine->addCompileFunction(this, "looks_cleargraphiceffects", &compileClearGraphicEffects);
53+
engine->addCompileFunction(this, "looks_changesizeby", &compileChangeSizeBy);
5354
}
5455

5556
void LooksBlocks::onInit(IEngine *engine)
@@ -205,6 +206,16 @@ CompilerValue *LooksBlocks::compileClearGraphicEffects(Compiler *compiler)
205206
return nullptr;
206207
}
207208

209+
CompilerValue *LooksBlocks::compileChangeSizeBy(Compiler *compiler)
210+
{
211+
if (compiler->target()->isStage())
212+
return nullptr;
213+
214+
auto change = compiler->addInput("CHANGE");
215+
compiler->addTargetFunctionCall("looks_changesizeby", Compiler::StaticType::Void, { Compiler::StaticType::Number }, { change });
216+
return nullptr;
217+
}
218+
208219
extern "C" void looks_start_stack_timer(ExecutionContext *ctx, double duration)
209220
{
210221
ctx->stackTimer()->start(duration);
@@ -274,3 +285,8 @@ extern "C" void looks_cleargraphiceffects(Target *target)
274285
{
275286
target->clearGraphicsEffects();
276287
}
288+
289+
extern "C" void looks_changesizeby(Sprite *sprite, double change)
290+
{
291+
sprite->setSize(sprite->size() + change);
292+
}

src/blocks/looksblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class LooksBlocks : public IExtension
4040
static CompilerValue *compileChangeEffectBy(Compiler *compiler);
4141
static CompilerValue *compileSetEffectTo(Compiler *compiler);
4242
static CompilerValue *compileClearGraphicEffects(Compiler *compiler);
43+
static CompilerValue *compileChangeSizeBy(Compiler *compiler);
4344

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

test/blocks/looks_blocks_test.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,31 @@ TEST_F(LooksBlocksTest, ClearGraphicEffects)
526526
ASSERT_EQ(sprite->graphicsEffectValue(effect2), 0);
527527
ASSERT_EQ(sprite->graphicsEffectValue(effect3), 0);
528528
}
529+
530+
TEST_F(LooksBlocksTest, ChangeSizeBy)
531+
{
532+
{
533+
auto sprite = std::make_shared<Sprite>();
534+
ScriptBuilder builder(m_extension.get(), m_engine, sprite);
535+
builder.addBlock("looks_changesizeby");
536+
builder.addValueInput("CHANGE", 2.5);
537+
builder.build();
538+
539+
sprite->setEngine(nullptr);
540+
sprite->setSize(45.62);
541+
builder.run();
542+
ASSERT_EQ(sprite->size(), 48.12);
543+
}
544+
545+
m_engine->clear();
546+
547+
{
548+
auto stage = std::make_shared<Stage>();
549+
ScriptBuilder builder(m_extension.get(), m_engine, stage);
550+
builder.addBlock("looks_changesizeby");
551+
builder.addValueInput("CHANGE", 2.5);
552+
553+
builder.build();
554+
builder.run();
555+
}
556+
}

0 commit comments

Comments
 (0)