Skip to content

Commit 6f51dde

Browse files
committed
Block: Add support for mutations
1 parent 8cecd7b commit 6f51dde

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/scratch/block.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ void Block::setCompileFunction(BlockComp newCompileFunction)
3737
m_compileFunction = newCompileFunction;
3838
}
3939

40+
/*! Returns true if the block can have a block following it. */
41+
bool Block::mutationHasNext() const
42+
{
43+
return m_mutationHasNext;
44+
}
45+
46+
/*! Sets whether the block can have a block following it. */
47+
void Block::setMutationHasNext(bool newMutationHasNext)
48+
{
49+
m_mutationHasNext = newMutationHasNext;
50+
}
51+
52+
/*! Returns the block prototype (in custom block definition). */
53+
BlockPrototype *Block::mutationPrototype()
54+
{
55+
return &m_mutationPrototype;
56+
}
57+
4058
/*! Returns the next block. */
4159
std::shared_ptr<Block> Block::next() const
4260
{

src/scratch/block.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "field.h"
77
#include "ientity.h"
88
#include "input.h"
9+
#include "blockprototype.h"
910
#include <memory>
1011
#include <unordered_map>
1112
#include <string>
@@ -64,6 +65,11 @@ class LIBSCRATCHCPP_EXPORT Block : public IEntity
6465
BlockComp compileFunction() const;
6566
void setCompileFunction(BlockComp newCompileFunction);
6667

68+
bool mutationHasNext() const;
69+
void setMutationHasNext(bool newMutationHasNext);
70+
71+
BlockPrototype *mutationPrototype();
72+
6773
private:
6874
std::string m_opcode;
6975
BlockComp m_compileFunction = nullptr;
@@ -79,6 +85,8 @@ class LIBSCRATCHCPP_EXPORT Block : public IEntity
7985
bool m_topLevel = false;
8086
Engine *m_engine = nullptr;
8187
Target *m_target = nullptr;
88+
BlockPrototype m_mutationPrototype;
89+
bool m_mutationHasNext = true;
8290
};
8391

8492
} // namespace libscratchcpp

0 commit comments

Comments
 (0)