libscratchcpp
A library for C++ based Scratch project players
Loading...
Searching...
No Matches
libscratchcpp::Block Class Reference

The Block class represents a Scratch block. More...

#include <scratchcpp/block.h>

Inheritance diagram for libscratchcpp::Block:
Collaboration diagram for libscratchcpp::Block:

Public Member Functions

 Block (const std::string &id, const std::string &opcode, bool isMonitorBlock=false)
 
 Block (const Block &)=delete
 
CompilerValuecompile (Compiler *compiler)
 
const std::string & opcode () const
 
Blocknext () const
 
const std::string & nextId () const
 
void setNext (Block *block)
 
void setNextId (const std::string &nextId)
 
Blockparent () const
 
const std::string & parentId () const
 
void setParent (Block *block)
 
void setParentId (const std::string &id)
 
const std::vector< std::shared_ptr< Input > > & inputs () const
 
int addInput (std::shared_ptr< Input > input)
 
std::shared_ptr< InputinputAt (int index) const
 
int findInput (const std::string &inputName) const
 
const std::vector< std::shared_ptr< Field > > & fields () const
 
int addField (std::shared_ptr< Field > field)
 
std::shared_ptr< FieldfieldAt (int index) const
 
int findField (const std::string &fieldName) const
 
bool shadow () const
 
void setShadow (bool newShadow)
 
bool topLevel () const
 
int x () const
 
void setX (int x)
 
int y () const
 
void setY (int y)
 
std::shared_ptr< Commentcomment () const
 
const std::string & commentId () const
 
void setComment (std::shared_ptr< Comment > comment)
 
void setCommentId (const std::string &commentId)
 
void setEngine (IEngine *newEngine)
 
IEngineengine () const
 
void setTarget (Target *newTarget)
 
Targettarget () const
 
BlockComp compileFunction () const
 
void setCompileFunction (BlockComp newCompileFunction)
 
HatPredicateCompileFunc hatPredicateCompileFunction () const
 
void setHatPredicateCompileFunction (HatPredicateCompileFunc newHatPredicateCompileFunction)
 
bool mutationHasNext () const
 
void setMutationHasNext (bool newMutationHasNext)
 
BlockPrototypemutationPrototype ()
 
bool isTopLevelReporter () const
 
void setIsTopLevelReporter (bool isTopLevelReporter)
 
InputValuetopLevelReporterInfo ()
 
bool isMonitorBlock () const
 
const std::string & id () const
 
void setId (const std::string &newId)
 

Detailed Description

The Block class represents a Scratch block.

Constructor & Destructor Documentation

◆ Block() [1/2]

Block::Block ( const std::string & id,
const std::string & opcode,
bool isMonitorBlock = false )

Constructs Block

◆ Block() [2/2]

libscratchcpp::Block::Block ( const Block & )
delete

Member Function Documentation

◆ addField()

int Block::addField ( std::shared_ptr< Field > field)

Adds a field and returns its index.

◆ addInput()

int Block::addInput ( std::shared_ptr< Input > input)

Adds an input and returns its index.

◆ comment()

std::shared_ptr< Comment > Block::comment ( ) const

Returns the comment which is attached to this block.

◆ commentId()

const std::string & Block::commentId ( ) const

Returns the ID of the comment which is attached to this block.

◆ compile()

CompilerValue * Block::compile ( Compiler * compiler)

Calls the compile function.

◆ compileFunction()

BlockComp Block::compileFunction ( ) const

Returns the compile function.

See also
Block sections

◆ engine()

IEngine * Block::engine ( ) const

Returns the Engine.

◆ fieldAt()

std::shared_ptr< Field > Block::fieldAt ( int index) const

Returns the field at index.

◆ fields()

const std::vector< std::shared_ptr< Field > > & Block::fields ( ) const

Returns the list of fields.

◆ findField()

int Block::findField ( const std::string & fieldName) const

Returns the index of the field with the given name.

◆ findInput()

int Block::findInput ( const std::string & inputName) const

Returns the index of the input with the given name.

◆ hatPredicateCompileFunction()

HatPredicateCompileFunc Block::hatPredicateCompileFunction ( ) const

Returns the edge-activated hat predicate compile function.

See also
Block sections

◆ id()

const std::string & Entity::id ( ) const
inherited

Returns the ID.

◆ inputAt()

std::shared_ptr< Input > Block::inputAt ( int index) const

Returns the input at index.

◆ inputs()

const std::vector< std::shared_ptr< Input > > & Block::inputs ( ) const

Returns the list of inputs.

◆ isMonitorBlock()

bool Block::isMonitorBlock ( ) const

Returns true if this block belongs to a monitor.

◆ isTopLevelReporter()

bool Block::isTopLevelReporter ( ) const

Returns true if this is a top level reporter block for a variable or a list.

◆ mutationHasNext()

bool Block::mutationHasNext ( ) const

Returns true if the block can have a block following it.

◆ mutationPrototype()

BlockPrototype * Block::mutationPrototype ( )

Returns the block prototype (in custom block definition).

◆ next()

Block * Block::next ( ) const

Returns the next block.

◆ nextId()

const std::string & Block::nextId ( ) const

Returns the ID of the next block.

◆ opcode()

const std::string & Block::opcode ( ) const

Returns the opcode.

◆ parent()

Block * Block::parent ( ) const

Returns the parent block.

◆ parentId()

const std::string & Block::parentId ( ) const

Returns the ID of the parent block.

◆ setComment()

void Block::setComment ( std::shared_ptr< Comment > comment)

Sets the comment which is attached to this block.

◆ setCommentId()

void Block::setCommentId ( const std::string & commentId)

Sets the ID of the comment which is attached to this block.

◆ setCompileFunction()

void Block::setCompileFunction ( BlockComp newCompileFunction)

Sets the compile function.

See also
Block sections

◆ setEngine()

void Block::setEngine ( IEngine * newEngine)

Sets the Engine.

◆ setHatPredicateCompileFunction()

void Block::setHatPredicateCompileFunction ( HatPredicateCompileFunc newHatPredicateCompileFunction)

Sets the edge-activated hat predicate compile function.

See also
Block sections

◆ setId()

void Entity::setId ( const std::string & newId)
inherited

Sets the ID.

◆ setIsTopLevelReporter()

void Block::setIsTopLevelReporter ( bool isTopLevelReporter)

Sets whether this block is a top level reporter block for a variable or a list.

Note
Setting this to true will allow the use of topLevelReporterInfo().

◆ setMutationHasNext()

void Block::setMutationHasNext ( bool newMutationHasNext)

Sets whether the block can have a block following it.

◆ setNext()

void Block::setNext ( Block * block)

Sets the next block.

◆ setNextId()

void Block::setNextId ( const std::string & nextId)

Sets the next block by ID.

◆ setParent()

void Block::setParent ( Block * block)

Sets the parent block.

◆ setParentId()

void Block::setParentId ( const std::string & id)

Sets the parent block by ID.

◆ setShadow()

void Block::setShadow ( bool newShadow)

Toggles whether this block is a shadow block.

◆ setTarget()

void Block::setTarget ( Target * newTarget)

Sets the Target.

◆ setX()

void Block::setX ( int x)

Sets the X-coordinate of the block in the code area (only for top level blocks).

◆ setY()

void Block::setY ( int y)

Sets the Y-coordinate of the block in the code area (only for top level blocks).

◆ shadow()

bool Block::shadow ( ) const

Returns true if this is a shadow block.

◆ target()

Target * Block::target ( ) const

Returns the Target.

◆ topLevel()

bool Block::topLevel ( ) const

Returns true if this is a top level block.

◆ topLevelReporterInfo()

InputValue * Block::topLevelReporterInfo ( )

Returns the information about this top level reporter block (if this is a top level reporter block).

Note
This function will return nullptr if this isn't a top level reporter block. Use setIsTopLevelReporter(true) before using this function.

◆ x()

int Block::x ( ) const

Returns the X-coordinate of the block in the code area (only for top level blocks).

◆ y()

int Block::y ( ) const

Returns the Y-coordinate of the block in the code area (only for top level blocks).


The documentation for this class was generated from the following files: