|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +#include "blockprototype.h" |
| 4 | + |
| 5 | +using namespace libscratchcpp; |
| 6 | + |
| 7 | +/*! Constructs BlockPrototype. */ |
| 8 | +BlockPrototype::BlockPrototype() |
| 9 | +{ |
| 10 | +} |
| 11 | + |
| 12 | +/*! Constructs BlockPrototype. */ |
| 13 | +BlockPrototype::BlockPrototype(const std::string &procCode) |
| 14 | +{ |
| 15 | + setProcCode(procCode); |
| 16 | +} |
| 17 | + |
| 18 | +/*! Returns the name of the custom block, including inputs. */ |
| 19 | +const std::string &BlockPrototype::procCode() const |
| 20 | +{ |
| 21 | + return m_procCode; |
| 22 | +} |
| 23 | + |
| 24 | +/*! Sets the name of the custom block, including inputs. */ |
| 25 | +void BlockPrototype::setProcCode(const std::string &newProcCode) |
| 26 | +{ |
| 27 | + m_procCode = newProcCode; |
| 28 | + m_argumentDefaults.clear(); |
| 29 | + m_argumentTypes.clear(); |
| 30 | + bool arg = false; |
| 31 | + |
| 32 | + for (auto c : m_procCode) { |
| 33 | + if (c == '%') |
| 34 | + arg = true; |
| 35 | + else if (arg) { |
| 36 | + switch (c) { |
| 37 | + case 's': |
| 38 | + m_argumentDefaults.push_back(""); |
| 39 | + m_argumentTypes.push_back(ArgType::StringNum); |
| 40 | + break; |
| 41 | + |
| 42 | + case 'b': |
| 43 | + m_argumentDefaults.push_back(false); |
| 44 | + m_argumentTypes.push_back(ArgType::Bool); |
| 45 | + break; |
| 46 | + |
| 47 | + default: |
| 48 | + break; |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +/*! Returns the list of argument IDs. */ |
| 55 | +const std::vector<std::string> &BlockPrototype::argumentIds() const |
| 56 | +{ |
| 57 | + return m_argumentIds; |
| 58 | +} |
| 59 | + |
| 60 | +/*! Sets the list of argument IDs. */ |
| 61 | +void BlockPrototype::setArgumentIds(const std::vector<std::string> &newArgumentIds) |
| 62 | +{ |
| 63 | + m_argumentIds = newArgumentIds; |
| 64 | +} |
| 65 | + |
| 66 | +/*! Returns the list of argument names. */ |
| 67 | +const std::vector<std::string> &BlockPrototype::argumentNames() const |
| 68 | +{ |
| 69 | + return m_argumentNames; |
| 70 | +} |
| 71 | + |
| 72 | +/*! Sets the list of argument names. */ |
| 73 | +void BlockPrototype::setArgumentNames(const std::vector<std::string> &newArgumentNames) |
| 74 | +{ |
| 75 | + m_argumentNames = newArgumentNames; |
| 76 | +} |
| 77 | + |
| 78 | +/*! Returns the list of argument default values. */ |
| 79 | +const std::vector<Value> &BlockPrototype::argumentDefaults() const |
| 80 | +{ |
| 81 | + return m_argumentDefaults; |
| 82 | +} |
| 83 | + |
| 84 | +/*! Returns the list of argument types. */ |
| 85 | +const std::vector<BlockPrototype::ArgType> &BlockPrototype::argumentTypes() const |
| 86 | +{ |
| 87 | + return m_argumentTypes; |
| 88 | +} |
| 89 | + |
| 90 | +/*! Returns true if the block is set to run without screen refresh. */ |
| 91 | +bool BlockPrototype::warp() const |
| 92 | +{ |
| 93 | + return m_warp; |
| 94 | +} |
| 95 | + |
| 96 | +/*! Sets whether to run the block without screen refresh. */ |
| 97 | +void BlockPrototype::setWarp(bool newWarp) |
| 98 | +{ |
| 99 | + m_warp = newWarp; |
| 100 | +} |
0 commit comments