Skip to content

Commit 6482b86

Browse files
committed
Implement control_start_as_clone
1 parent f98e1d1 commit 6482b86

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/dev/blocks/controlblocks.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void ControlBlocks::registerBlocks(IEngine *engine)
3737
engine->addCompileFunction(this, "control_repeat_until", &compileRepeatUntil);
3838
engine->addCompileFunction(this, "control_while", &compileWhile);
3939
engine->addCompileFunction(this, "control_for_each", &compileForEach);
40+
engine->addCompileFunction(this, "control_start_as_clone", &compileStartAsClone);
4041
}
4142

4243
CompilerValue *ControlBlocks::compileForever(Compiler *compiler)
@@ -136,6 +137,12 @@ CompilerValue *ControlBlocks::compileForEach(Compiler *compiler)
136137
return nullptr;
137138
}
138139

140+
CompilerValue *ControlBlocks::compileStartAsClone(Compiler *compiler)
141+
{
142+
compiler->engine()->addCloneInitScript(compiler->block());
143+
return nullptr;
144+
}
145+
139146
extern "C" void control_stop_all(ExecutionContext *ctx)
140147
{
141148
ctx->engine()->stop();

src/dev/blocks/controlblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ControlBlocks : public IExtension
2626
static CompilerValue *compileRepeatUntil(Compiler *compiler);
2727
static CompilerValue *compileWhile(Compiler *compiler);
2828
static CompilerValue *compileForEach(Compiler *compiler);
29+
static CompilerValue *compileStartAsClone(Compiler *compiler);
2930
};
3031

3132
} // namespace libscratchcpp

test/dev/blocks/control_blocks_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,3 +754,16 @@ TEST_F(ControlBlocksTest, ForEach)
754754
ASSERT_GT(var1->value(), 0);
755755
}
756756
}
757+
758+
TEST_F(ControlBlocksTest, StartAsClone)
759+
{
760+
auto target = std::make_shared<Sprite>();
761+
ScriptBuilder builder(m_extension.get(), m_engine, target);
762+
763+
builder.addBlock("control_start_as_clone");
764+
auto block = builder.currentBlock();
765+
766+
Compiler compiler(&m_engineMock, target.get());
767+
EXPECT_CALL(m_engineMock, addCloneInitScript(block));
768+
compiler.compile(block);
769+
}

0 commit comments

Comments
 (0)