libscratchcpp
A library for C++ based Scratch project players
Loading...
Searching...
No Matches
block.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
5#include "entity.h"
6#include "blockprototype.h"
7
8namespace libscratchcpp
9{
10
11class IEngine;
12class Target;
13class CompilerValue;
14class Input;
15class Field;
16class Comment;
17class InputValue;
18class BlockPrivate;
19
22 : public Entity
23 , public std::enable_shared_from_this<Block>
24{
25 public:
26 Block(const std::string &id, const std::string &opcode, bool isMonitorBlock = false);
27 Block(const Block &) = delete;
28
29 CompilerValue *compile(Compiler *compiler);
30
31 const std::string &opcode() const;
32
33 Block *next() const;
34 const std::string &nextId() const;
35 void setNext(Block *block);
36 void setNextId(const std::string &nextId);
37
38 Block *parent() const;
39 const std::string &parentId() const;
40 void setParent(Block *block);
41 void setParentId(const std::string &id);
42
43 const std::vector<std::shared_ptr<Input>> &inputs() const;
44 int addInput(std::shared_ptr<Input> input);
45 std::shared_ptr<Input> inputAt(int index) const;
46 int findInput(const std::string &inputName) const;
47
48 const std::vector<std::shared_ptr<Field>> &fields() const;
49 int addField(std::shared_ptr<Field> field);
50 std::shared_ptr<Field> fieldAt(int index) const;
51 int findField(const std::string &fieldName) const;
52
53 bool shadow() const;
54 void setShadow(bool newShadow);
55
56 bool topLevel() const;
57
58 int x() const;
59 void setX(int x);
60
61 int y() const;
62 void setY(int y);
63
64 std::shared_ptr<Comment> comment() const;
65 const std::string &commentId() const;
66 void setComment(std::shared_ptr<Comment> comment);
67 void setCommentId(const std::string &commentId);
68
69 void setEngine(IEngine *newEngine);
70 IEngine *engine() const;
71
72 void setTarget(Target *newTarget);
73 Target *target() const;
74
76 void setCompileFunction(BlockComp newCompileFunction);
77
79 void setHatPredicateCompileFunction(HatPredicateCompileFunc newHatPredicateCompileFunction);
80
81 bool mutationHasNext() const;
82 void setMutationHasNext(bool newMutationHasNext);
83
85
86 bool isTopLevelReporter() const;
88
90
91 bool isMonitorBlock() const;
92
93 private:
94 spimpl::unique_impl_ptr<BlockPrivate> impl;
95};
96
97} // namespace libscratchcpp
The BlockPrototype class represents the prototype of a custom block.
Definition blockprototype.h:17
int x() const
Definition block.cpp:281
int addInput(std::shared_ptr< Input > input)
Definition block.cpp:193
Block * parent() const
Definition block.cpp:157
Target * target() const
Definition block.cpp:359
bool topLevel() const
Definition block.cpp:275
std::shared_ptr< Input > inputAt(int index) const
Definition block.cpp:205
const std::string & commentId() const
Definition block.cpp:317
void setMutationHasNext(bool newMutationHasNext)
Definition block.cpp:74
IEngine * engine() const
Definition block.cpp:347
int y() const
Definition block.cpp:296
void setIsTopLevelReporter(bool isTopLevelReporter)
Definition block.cpp:95
const std::string & parentId() const
Definition block.cpp:163
BlockComp compileFunction() const
Definition block.cpp:38
void setY(int y)
Definition block.cpp:302
void setShadow(bool newShadow)
Definition block.cpp:269
bool mutationHasNext() const
Definition block.cpp:68
Block(const std::string &id, const std::string &opcode, bool isMonitorBlock=false)
Definition block.cpp:16
void setTarget(Target *newTarget)
Definition block.cpp:353
void setParent(Block *block)
Definition block.cpp:169
void setNextId(const std::string &nextId)
Definition block.cpp:150
void setCommentId(const std::string &commentId)
Definition block.cpp:334
void setHatPredicateCompileFunction(HatPredicateCompileFunc newHatPredicateCompileFunction)
Definition block.cpp:56
bool isMonitorBlock() const
Definition block.cpp:121
void setEngine(IEngine *newEngine)
Definition block.cpp:341
Block(const Block &)=delete
bool shadow() const
Definition block.cpp:263
BlockPrototype * mutationPrototype()
Definition block.cpp:80
Block * next() const
Definition block.cpp:127
int findField(const std::string &fieldName) const
Definition block.cpp:252
InputValue * topLevelReporterInfo()
Definition block.cpp:112
void setX(int x)
Definition block.cpp:287
int addField(std::shared_ptr< Field > field)
Definition block.cpp:231
const std::string & nextId() const
Definition block.cpp:133
CompilerValue * compile(Compiler *compiler)
Definition block.cpp:23
std::shared_ptr< Comment > comment() const
Definition block.cpp:311
bool isTopLevelReporter() const
Definition block.cpp:86
HatPredicateCompileFunc hatPredicateCompileFunction() const
Definition block.cpp:50
void setComment(std::shared_ptr< Comment > comment)
Definition block.cpp:323
void setCompileFunction(BlockComp newCompileFunction)
Definition block.cpp:44
void setNext(Block *block)
Definition block.cpp:139
const std::vector< std::shared_ptr< Input > > & inputs() const
Definition block.cpp:187
void setParentId(const std::string &id)
Definition block.cpp:180
std::shared_ptr< Field > fieldAt(int index) const
Definition block.cpp:243
const std::vector< std::shared_ptr< Field > > & fields() const
Definition block.cpp:225
const std::string & opcode() const
Definition block.cpp:32
int findInput(const std::string &inputName) const
Definition block.cpp:214
The Comment class represents a comment in the code area.
Definition comment.h:15
The CompilerValue class represents a local value in compiled code.
Definition compilervalue.h:14
The Compiler class provides API for compiling Scratch scripts.
Definition compiler.h:33
Entity(const std::string &id)
Definition entity.cpp:10
The Field class represents a Scratch block field.
Definition field.h:20
The IEngine interface provides an API for running Scratch projects.
Definition iengine.h:41
The InputValue class provides methods for the value of an Input.
Definition inputvalue.h:20
The Input class represents a Scratch block input.
Definition input.h:18
The Target class is the Stage or a Sprite.
Definition target.h:28
#define LIBSCRATCHCPP_EXPORT
Definition global.h:17
The main namespace of the library.
Definition asset.h:10
CompilerValue *(*)(Compiler *vm) HatPredicateCompileFunc
Definition global.h:57
CompilerValue *(*)(Compiler *) BlockComp
Definition global.h:36