Skip to content

Commit 7f713f8

Browse files
committed
Merge extensions and block sections
1 parent 688c257 commit 7f713f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1233
-1488
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ target_sources(scratchcpp
3131
include/scratchcpp/scratchconfiguration.h
3232
include/scratchcpp/iengine.h
3333
include/scratchcpp/iextension.h
34-
include/scratchcpp/iblocksection.h
3534
include/scratchcpp/thread.h
3635
include/scratchcpp/asset.h
3736
include/scratchcpp/costume.h

include/scratchcpp/iblocksection.h

Lines changed: 0 additions & 44 deletions
This file was deleted.

include/scratchcpp/iengine.h

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace libscratchcpp
1515
{
1616

17-
class IBlockSection;
17+
class IExtension;
1818
class Broadcast;
1919
class Block;
2020
class Target;
@@ -217,66 +217,60 @@ class LIBSCRATCHCPP_EXPORT IEngine
217217
/*! Returns the timer of the project. */
218218
virtual ITimer *timer() const = 0;
219219

220-
/*!
221-
* Registers the given block section.
222-
* \see <a href="blockSections.html">Block sections</a>
223-
*/
224-
virtual void registerSection(std::shared_ptr<IBlockSection> section) = 0;
225-
226220
/*! Returns the index of the given block function. */
227221
virtual unsigned int functionIndex(BlockFunc f) = 0;
228222

229223
/*! Returns the list of block functions. */
230224
virtual const std::vector<BlockFunc> &blockFunctions() const = 0;
231225

232226
/*!
233-
* Call this from IBlockSection#registerBlocks() to add a compile function to a block section.
234-
* \see <a href="blockSections.html">Block sections</a>
227+
* Call this from IExtension#registerBlocks() to add a compile function to a block section.
228+
* \see <a href="extensions.html">Extensions</a>
235229
*/
236-
virtual void addCompileFunction(IBlockSection *section, const std::string &opcode, BlockComp f) = 0;
230+
virtual void addCompileFunction(IExtension *extension, const std::string &opcode, BlockComp f) = 0;
237231

238232
/*!
239-
* Call this from IBlockSection#registerBlocks() to add a hat block predicate compile function to a block section.
233+
* Call this from IExtension#registerBlocks() to add a hat block predicate compile function to a block section.
240234
* \note This only works with edge-activated hats.
241-
* \see <a href="blockSections.html">Block sections</a>
235+
* \see <a href="extensions.html">Extensions</a>
242236
*/
243-
virtual void addHatPredicateCompileFunction(IBlockSection *section, const std::string &opcode, HatPredicateCompileFunc f) = 0;
237+
virtual void addHatPredicateCompileFunction(IExtension *extension, const std::string &opcode, HatPredicateCompileFunc f) = 0;
244238

245239
/*!
246-
* Call this from IBlockSection#registerBlocks() to add a monitor name function to a block section.
247-
* \see <a href="blockSections.html">Block sections</a>
240+
* Call this from IExtension#registerBlocks() to add a monitor name function to a block section.
241+
* \see <a href="extensions.html">Extensions</a>
248242
*/
249-
virtual void addMonitorNameFunction(IBlockSection *section, const std::string &opcode, MonitorNameFunc f) = 0;
243+
virtual void addMonitorNameFunction(IExtension *extension, const std::string &opcode, MonitorNameFunc f) = 0;
250244

251245
/*!
252-
* Call this from IBlockSection#registerBlocks() to add a monitor value change function to a block section.
253-
* \see <a href="blockSections.html">Block sections</a>
246+
* Call this from IExtension#registerBlocks() to add a monitor value change function to a block section.
247+
* \see <a href="extensions.html">Extensions</a>
254248
*/
255-
virtual void addMonitorChangeFunction(IBlockSection *section, const std::string &opcode, MonitorChangeFunc f) = 0;
249+
virtual void addMonitorChangeFunction(IExtension *extension, const std::string &opcode, MonitorChangeFunc f) = 0;
256250

257251
/*!
258-
* Call this from IBlockSection#registerBlocks() to add a hat block to a block section.
259-
* \see <a href="blockSections.html">Block sections</a>
252+
* Call this from IExtension#registerBlocks() to add a hat block to a block section.
253+
* \see <a href="extensions.html">Extensions</a>
260254
*/
261-
virtual void addHatBlock(IBlockSection *section, const std::string &opcode) = 0;
255+
virtual void addHatBlock(IExtension *extension, const std::string &opcode) = 0;
262256

263257
/*!
264-
* Call this from IBlockSection#registerBlocks() to add an input to a block section.
265-
* \see <a href="blockSections.html">Block sections</a>
258+
* Call this from IExtension#registerBlocks() to add an input to a block section.
259+
* \see <a href="extensions.html">Extensions</a>
266260
*/
267-
virtual void addInput(IBlockSection *section, const std::string &name, int id) = 0;
261+
virtual void addInput(IExtension *extension, const std::string &name, int id) = 0;
268262

269263
/*!
270-
* Call this from IBlockSection#registerBlocks() to add a field to a block section.
271-
* \see <a href="blockSections.html">Block sections</a>
264+
* Call this from IExtension#registerBlocks() to add a field to a block section.
265+
* \see <a href="extensions.html">Extensions</a>
272266
*/
273-
virtual void addField(IBlockSection *section, const std::string &name, int id) = 0;
267+
virtual void addField(IExtension *extension, const std::string &name, int id) = 0;
274268

275269
/*!
276-
* Call this from IBlockSection#registerBlocks() to add a field value to a block section.
277-
* \see <a href="blockSections.html">Block sections</a>
270+
* Call this from IExtension#registerBlocks() to add a field value to a block section.
271+
* \see <a href="extensions.html">Extensions</a>
278272
*/
279-
virtual void addFieldValue(IBlockSection *section, const std::string &value, int id) = 0;
273+
virtual void addFieldValue(IExtension *extension, const std::string &value, int id) = 0;
280274

281275
/*! Returns the list of broadcasts. */
282276
virtual const std::vector<std::shared_ptr<Broadcast>> &broadcasts() const = 0;
@@ -381,11 +375,13 @@ class LIBSCRATCHCPP_EXPORT IEngine
381375
/*! Emits when a question is answered. */
382376
virtual sigslot::signal<const std::string &> &questionAnswered() = 0;
383377

378+
#ifndef USE_LLVM
384379
/*! Returns the list of extension names. */
385380
virtual const std::vector<std::string> &extensions() const = 0;
386381

387382
/*! Sets the list of extension names. */
388383
virtual void setExtensions(const std::vector<std::string> &newExtensions) = 0;
384+
#endif
389385

390386
/*! Returns the map of scripts (each top level block has a Script object). */
391387
virtual const std::unordered_map<std::shared_ptr<Block>, std::shared_ptr<Script>> &scripts() const = 0;

include/scratchcpp/iextension.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ class LIBSCRATCHCPP_EXPORT IExtension
2727
/*! Returns the description of the extension. */
2828
virtual std::string description() const = 0;
2929

30-
/*!
31-
* Returns true if the extension is hidden from the block palette
32-
* and should be available in a Scratch project by default
33-
*/
34-
virtual bool includeByDefault() const { return false; }
35-
36-
/*! Registers block sections. \see <a href="blockSections.html">Block sections</a> */
37-
virtual void registerSections(IEngine *engine) = 0;
30+
/*! Override this method to register blocks. */
31+
virtual void registerBlocks(IEngine *engine) = 0;
32+
33+
/*! This method is called when a project is loaded. */
34+
virtual void onInit(IEngine *engine) { }
3835
};
3936

4037
} // namespace libscratchcpp

include/scratchcpp/monitor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace libscratchcpp
1212
class IMonitorHandler;
1313
class Block;
1414
class Script;
15-
class IBlockSection;
15+
class IExtension;
1616
class Sprite;
1717
class Value;
1818
class Rect;
@@ -48,8 +48,8 @@ class LIBSCRATCHCPP_EXPORT Monitor : public Entity
4848
std::shared_ptr<Script> script() const;
4949
void setScript(std::shared_ptr<Script> script);
5050

51-
std::shared_ptr<IBlockSection> blockSection() const;
52-
void setBlockSection(std::shared_ptr<IBlockSection> blockSection);
51+
IExtension *extension() const;
52+
void setExtension(IExtension *extension);
5353

5454
Sprite *sprite() const;
5555
void setSprite(Sprite *sprite);

include/scratchcpp/scratchconfiguration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class LIBSCRATCHCPP_EXPORT ScratchConfiguration
2121
ScratchConfiguration() = delete;
2222

2323
static void registerExtension(std::shared_ptr<IExtension> extension);
24+
static void removeExtension(std::shared_ptr<IExtension> extension);
2425
static IExtension *getExtension(const std::string &name);
2526

2627
/*! Finds the extension of class T. Returns nullptr if it isn't registered. */

src/blocks/CMakeLists.txt

Lines changed: 112 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,115 @@
11
target_sources(scratchcpp
22
PRIVATE
3-
standardblocks.cpp
4-
standardblocks.h
5-
motionblocks.cpp
6-
looksblocks.cpp
7-
soundblocks.cpp
8-
eventblocks.cpp
9-
controlblocks.cpp
10-
sensingblocks.cpp
11-
operatorblocks.cpp
12-
variableblocks.cpp
13-
listblocks.cpp
14-
customblocks.cpp
15-
PUBLIC
16-
motionblocks.h
17-
looksblocks.h
18-
soundblocks.h
19-
eventblocks.h
20-
controlblocks.h
21-
sensingblocks.h
22-
operatorblocks.h
23-
variableblocks.h
24-
listblocks.h
25-
customblocks.h
3+
blocks.cpp
4+
blocks.h
265
)
6+
7+
# Motion blocks
8+
option(LIBSCRATCHCPP_ENABLE_MOTION_BLOCKS "Motion blocks support" ON)
9+
if (LIBSCRATCHCPP_ENABLE_MOTION_BLOCKS)
10+
target_compile_definitions(scratchcpp PRIVATE ENABLE_MOTION_BLOCKS)
11+
target_sources(scratchcpp
12+
PRIVATE
13+
motionblocks.cpp
14+
motionblocks.h
15+
)
16+
endif()
17+
18+
# Looks blocks
19+
option(LIBSCRATCHCPP_ENABLE_LOOKS_BLOCKS "Looks blocks support" ON)
20+
if (LIBSCRATCHCPP_ENABLE_LOOKS_BLOCKS)
21+
target_compile_definitions(scratchcpp PRIVATE ENABLE_LOOKS_BLOCKS)
22+
target_sources(scratchcpp
23+
PRIVATE
24+
looksblocks.cpp
25+
looksblocks.h
26+
)
27+
endif()
28+
29+
# Sound blocks
30+
option(LIBSCRATCHCPP_ENABLE_SOUND_BLOCKS "Sound blocks support" ON)
31+
if (LIBSCRATCHCPP_ENABLE_SOUND_BLOCKS)
32+
target_compile_definitions(scratchcpp PRIVATE ENABLE_SOUND_BLOCKS)
33+
target_sources(scratchcpp
34+
PRIVATE
35+
soundblocks.cpp
36+
soundblocks.h
37+
)
38+
endif()
39+
40+
# Event blocks
41+
option(LIBSCRATCHCPP_ENABLE_EVENT_BLOCKS "Event blocks support" ON)
42+
if (LIBSCRATCHCPP_ENABLE_EVENT_BLOCKS)
43+
target_compile_definitions(scratchcpp PRIVATE ENABLE_EVENT_BLOCKS)
44+
target_sources(scratchcpp
45+
PRIVATE
46+
eventblocks.cpp
47+
eventblocks.h
48+
)
49+
endif()
50+
51+
# Control blocks
52+
option(LIBSCRATCHCPP_ENABLE_CONTROL_BLOCKS "Control blocks support" ON)
53+
if (LIBSCRATCHCPP_ENABLE_CONTROL_BLOCKS)
54+
target_compile_definitions(scratchcpp PRIVATE ENABLE_CONTROL_BLOCKS)
55+
target_sources(scratchcpp
56+
PRIVATE
57+
controlblocks.cpp
58+
controlblocks.h
59+
)
60+
endif()
61+
62+
# Sensing blocks
63+
option(LIBSCRATCHCPP_ENABLE_SENSING_BLOCKS "Sensing blocks support" ON)
64+
if (LIBSCRATCHCPP_ENABLE_SENSING_BLOCKS)
65+
target_compile_definitions(scratchcpp PRIVATE ENABLE_SENSING_BLOCKS)
66+
target_sources(scratchcpp
67+
PRIVATE
68+
sensingblocks.cpp
69+
sensingblocks.h
70+
)
71+
endif()
72+
73+
# Operator blocks
74+
option(LIBSCRATCHCPP_ENABLE_OPERATOR_BLOCKS "Operator blocks support" ON)
75+
if (LIBSCRATCHCPP_ENABLE_OPERATOR_BLOCKS)
76+
target_compile_definitions(scratchcpp PRIVATE ENABLE_OPERATOR_BLOCKS)
77+
target_sources(scratchcpp
78+
PRIVATE
79+
operatorblocks.cpp
80+
operatorblocks.h
81+
)
82+
endif()
83+
84+
# Variable blocks
85+
option(LIBSCRATCHCPP_ENABLE_VARIABLE_BLOCKS "Variable blocks support" ON)
86+
if (LIBSCRATCHCPP_ENABLE_VARIABLE_BLOCKS)
87+
target_compile_definitions(scratchcpp PRIVATE ENABLE_VARIABLE_BLOCKS)
88+
target_sources(scratchcpp
89+
PRIVATE
90+
variableblocks.cpp
91+
variableblocks.h
92+
)
93+
endif()
94+
95+
# List blocks
96+
option(LIBSCRATCHCPP_ENABLE_LIST_BLOCKS "List blocks support" ON)
97+
if (LIBSCRATCHCPP_ENABLE_LIST_BLOCKS)
98+
target_compile_definitions(scratchcpp PRIVATE ENABLE_LIST_BLOCKS)
99+
target_sources(scratchcpp
100+
PRIVATE
101+
listblocks.cpp
102+
listblocks.h
103+
)
104+
endif()
105+
106+
# Custom blocks
107+
option(LIBSCRATCHCPP_ENABLE_CUSTOM_BLOCKS "Custom blocks support" ON)
108+
if (LIBSCRATCHCPP_ENABLE_CUSTOM_BLOCKS)
109+
target_compile_definitions(scratchcpp PRIVATE ENABLE_CUSTOM_BLOCKS)
110+
target_sources(scratchcpp
111+
PRIVATE
112+
customblocks.cpp
113+
customblocks.h
114+
)
115+
endif()

0 commit comments

Comments
 (0)