From 53bb46545b0348729c28ffd676fc8e92cd7822d3 Mon Sep 17 00:00:00 2001 From: adazem009 <68537469+adazem009@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:33:22 +0200 Subject: [PATCH 1/2] Merge extensions and block sections --- CMakeLists.txt | 1 - include/scratchcpp/iblocksection.h | 44 --- include/scratchcpp/iengine.h | 58 ++- include/scratchcpp/iextension.h | 13 +- include/scratchcpp/monitor.h | 6 +- include/scratchcpp/scratchconfiguration.h | 1 + src/blocks/CMakeLists.txt | 135 +++++-- src/blocks/blocks.cpp | 85 +++++ src/blocks/blocks.h | 26 ++ src/blocks/controlblocks.cpp | 5 + src/blocks/controlblocks.h | 5 +- src/blocks/customblocks.cpp | 5 + src/blocks/customblocks.h | 5 +- src/blocks/eventblocks.cpp | 5 + src/blocks/eventblocks.h | 5 +- src/blocks/listblocks.cpp | 4 +- src/blocks/listblocks.h | 7 +- src/blocks/looksblocks.cpp | 5 + src/blocks/looksblocks.h | 6 +- src/blocks/motionblocks.cpp | 5 + src/blocks/motionblocks.h | 6 +- src/blocks/operatorblocks.cpp | 5 + src/blocks/operatorblocks.h | 5 +- src/blocks/sensingblocks.cpp | 5 + src/blocks/sensingblocks.h | 5 +- src/blocks/soundblocks.cpp | 5 + src/blocks/soundblocks.h | 5 +- src/blocks/standardblocks.cpp | 46 --- src/blocks/standardblocks.h | 21 -- src/blocks/variableblocks.cpp | 5 + src/blocks/variableblocks.h | 6 +- src/engine/CMakeLists.txt | 2 - src/engine/internal/blocksectioncontainer.cpp | 96 ----- src/engine/internal/blocksectioncontainer.h | 45 --- src/engine/internal/engine.cpp | 330 ++++++++++------- src/engine/internal/engine.h | 43 ++- src/scratch/field.cpp | 4 +- src/scratch/monitor.cpp | 12 +- src/scratch/monitor_p.h | 2 +- src/scratchconfiguration.cpp | 7 +- src/scratchconfiguration_p.cpp | 5 + src/scratchconfiguration_p.h | 6 +- test/blocks/CMakeLists.txt | 314 ++++++++-------- test/blocks/control_blocks_test.cpp | 65 ++-- test/blocks/custom_blocks_test.cpp | 27 +- test/blocks/event_blocks_test.cpp | 57 ++- test/blocks/list_blocks_test.cpp | 47 ++- test/blocks/looks_blocks_test.cpp | 113 +++--- test/blocks/motion_blocks_test.cpp | 85 ++--- test/blocks/operator_blocks_test.cpp | 107 +++--- test/blocks/sensing_blocks_test.cpp | 123 +++--- test/blocks/sound_blocks_test.cpp | 47 ++- test/blocks/variable_blocks_test.cpp | 33 +- test/compiler/CMakeLists.txt | 4 +- test/compiler/compiler_test.cpp | 36 +- ...testblocksection.cpp => testextension.cpp} | 15 +- .../{testblocksection.h => testextension.h} | 5 +- test/engine/engine_test.cpp | 349 +++--------------- test/extensions/CMakeLists.txt | 18 - test/extensions/iblocksection_test.cpp | 31 -- test/extensions/iextension_test.cpp | 12 +- test/extensions/testextension.cpp | 8 +- test/extensions/testextension.h | 5 +- test/extensions/testsection.cpp | 20 - test/extensions/testsection.h | 18 - test/mocks/enginemock.h | 17 +- .../{blocksectionmock.h => extensionmock.h} | 6 +- test/scratch_classes/CMakeLists.txt | 4 +- test/scratch_classes/monitor_test.cpp | 12 +- test/scratch_classes/testextension.cpp | 19 + .../{testsection.h => testextension.h} | 5 +- test/scratch_classes/testsection.cpp | 14 - test/scratchconfiguration/extensionbase.cpp | 7 +- test/scratchconfiguration/extensionbase.h | 3 +- .../scratchconfiguration_test.cpp | 8 + 75 files changed, 1236 insertions(+), 1490 deletions(-) delete mode 100644 include/scratchcpp/iblocksection.h create mode 100644 src/blocks/blocks.cpp create mode 100644 src/blocks/blocks.h delete mode 100644 src/blocks/standardblocks.cpp delete mode 100644 src/blocks/standardblocks.h delete mode 100644 src/engine/internal/blocksectioncontainer.cpp delete mode 100644 src/engine/internal/blocksectioncontainer.h rename test/compiler/{testblocksection.cpp => testextension.cpp} (74%) rename test/compiler/{testblocksection.h => testextension.h} (79%) delete mode 100644 test/extensions/iblocksection_test.cpp delete mode 100644 test/extensions/testsection.cpp delete mode 100644 test/extensions/testsection.h rename test/mocks/{blocksectionmock.h => extensionmock.h} (65%) create mode 100644 test/scratch_classes/testextension.cpp rename test/scratch_classes/{testsection.h => testextension.h} (60%) delete mode 100644 test/scratch_classes/testsection.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index deeb6780..0f9fcc13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,6 @@ target_sources(scratchcpp include/scratchcpp/scratchconfiguration.h include/scratchcpp/iengine.h include/scratchcpp/iextension.h - include/scratchcpp/iblocksection.h include/scratchcpp/thread.h include/scratchcpp/asset.h include/scratchcpp/costume.h diff --git a/include/scratchcpp/iblocksection.h b/include/scratchcpp/iblocksection.h deleted file mode 100644 index 92b71cfb..00000000 --- a/include/scratchcpp/iblocksection.h +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include -#include -#include "spimpl.h" - -#include "global.h" - -namespace libscratchcpp -{ - -class BlockSectionPrivate; -class IEngine; - -/*! - * \brief The IBlockSection class is an interface for block sections/categories. - * - * \see Block sections - */ -class LIBSCRATCHCPP_EXPORT IBlockSection -{ - public: - virtual ~IBlockSection() { } - - /*! Override this method to return the name of the block section. */ - virtual std::string name() const = 0; - - /*! - * Override this method to configure whether the category in the block palette should be visible.\n - * For example, there isn't a list category in the Scratch user interface. - * \note The default implementation returns true. - */ - virtual bool categoryVisible() const { return true; } - - /*! Override this method to register blocks. */ - virtual void registerBlocks(IEngine *engine) = 0; - - /*! This method is called when a project is loaded. */ - virtual void onInit(IEngine *engine) { } -}; - -} // namespace libscratchcpp diff --git a/include/scratchcpp/iengine.h b/include/scratchcpp/iengine.h index 48498790..f4938a3c 100644 --- a/include/scratchcpp/iengine.h +++ b/include/scratchcpp/iengine.h @@ -14,7 +14,7 @@ namespace libscratchcpp { -class IBlockSection; +class IExtension; class Broadcast; class Block; class Target; @@ -217,12 +217,6 @@ class LIBSCRATCHCPP_EXPORT IEngine /*! Returns the timer of the project. */ virtual ITimer *timer() const = 0; - /*! - * Registers the given block section. - * \see Block sections - */ - virtual void registerSection(std::shared_ptr section) = 0; - /*! Returns the index of the given block function. */ virtual unsigned int functionIndex(BlockFunc f) = 0; @@ -230,53 +224,53 @@ class LIBSCRATCHCPP_EXPORT IEngine virtual const std::vector &blockFunctions() const = 0; /*! - * Call this from IBlockSection#registerBlocks() to add a compile function to a block section. - * \see Block sections + * Call this from IExtension#registerBlocks() to add a compile function to a block section. + * \see Extensions */ - virtual void addCompileFunction(IBlockSection *section, const std::string &opcode, BlockComp f) = 0; + virtual void addCompileFunction(IExtension *extension, const std::string &opcode, BlockComp f) = 0; /*! - * Call this from IBlockSection#registerBlocks() to add a hat block predicate compile function to a block section. + * Call this from IExtension#registerBlocks() to add a hat block predicate compile function to a block section. * \note This only works with edge-activated hats. - * \see Block sections + * \see Extensions */ - virtual void addHatPredicateCompileFunction(IBlockSection *section, const std::string &opcode, HatPredicateCompileFunc f) = 0; + virtual void addHatPredicateCompileFunction(IExtension *extension, const std::string &opcode, HatPredicateCompileFunc f) = 0; /*! - * Call this from IBlockSection#registerBlocks() to add a monitor name function to a block section. - * \see Block sections + * Call this from IExtension#registerBlocks() to add a monitor name function to a block section. + * \see Extensions */ - virtual void addMonitorNameFunction(IBlockSection *section, const std::string &opcode, MonitorNameFunc f) = 0; + virtual void addMonitorNameFunction(IExtension *extension, const std::string &opcode, MonitorNameFunc f) = 0; /*! - * Call this from IBlockSection#registerBlocks() to add a monitor value change function to a block section. - * \see Block sections + * Call this from IExtension#registerBlocks() to add a monitor value change function to a block section. + * \see Extensions */ - virtual void addMonitorChangeFunction(IBlockSection *section, const std::string &opcode, MonitorChangeFunc f) = 0; + virtual void addMonitorChangeFunction(IExtension *extension, const std::string &opcode, MonitorChangeFunc f) = 0; /*! - * Call this from IBlockSection#registerBlocks() to add a hat block to a block section. - * \see Block sections + * Call this from IExtension#registerBlocks() to add a hat block to a block section. + * \see Extensions */ - virtual void addHatBlock(IBlockSection *section, const std::string &opcode) = 0; + virtual void addHatBlock(IExtension *extension, const std::string &opcode) = 0; /*! - * Call this from IBlockSection#registerBlocks() to add an input to a block section. - * \see Block sections + * Call this from IExtension#registerBlocks() to add an input to a block section. + * \see Extensions */ - virtual void addInput(IBlockSection *section, const std::string &name, int id) = 0; + virtual void addInput(IExtension *extension, const std::string &name, int id) = 0; /*! - * Call this from IBlockSection#registerBlocks() to add a field to a block section. - * \see Block sections + * Call this from IExtension#registerBlocks() to add a field to a block section. + * \see Extensions */ - virtual void addField(IBlockSection *section, const std::string &name, int id) = 0; + virtual void addField(IExtension *extension, const std::string &name, int id) = 0; /*! - * Call this from IBlockSection#registerBlocks() to add a field value to a block section. - * \see Block sections + * Call this from IExtension#registerBlocks() to add a field value to a block section. + * \see Extensions */ - virtual void addFieldValue(IBlockSection *section, const std::string &value, int id) = 0; + virtual void addFieldValue(IExtension *extension, const std::string &value, int id) = 0; /*! Returns the list of broadcasts. */ virtual const std::vector> &broadcasts() const = 0; @@ -381,11 +375,13 @@ class LIBSCRATCHCPP_EXPORT IEngine /*! Emits when a question is answered. */ virtual sigslot::signal &questionAnswered() = 0; +#ifndef USE_LLVM /*! Returns the list of extension names. */ virtual const std::vector &extensions() const = 0; /*! Sets the list of extension names. */ virtual void setExtensions(const std::vector &newExtensions) = 0; +#endif /*! Returns the map of scripts (each top level block has a Script object). */ virtual const std::unordered_map, std::shared_ptr