|
3 | 3 | #include "scratch3reader.h" |
4 | 4 | #include "../scratch/sprite.h" |
5 | 5 | #include "../scratch/stage.h" |
| 6 | +#include "../scratch/internal/shadowinput.h" |
| 7 | +#include "../scratch/internal/variableinput.h" |
| 8 | +#include "../scratch/internal/listinput.h" |
| 9 | +#include "../scratch/internal/blockinput.h" |
6 | 10 | #include "reader_common.h" |
7 | 11 |
|
8 | 12 | using namespace libscratchcpp; |
@@ -79,8 +83,29 @@ bool Scratch3Reader::load() |
79 | 83 | auto inputs = blockInfo["inputs"]; |
80 | 84 | for (json::iterator it = inputs.begin(); it != inputs.end(); ++it) { |
81 | 85 | auto inputInfo = it.value(); |
82 | | - auto input = std::make_shared<Input>(it.key(), static_cast<Input::Type>(inputInfo[0])); |
| 86 | + auto type = static_cast<Input::Type>(inputInfo[0]); |
83 | 87 | auto primary = inputInfo[1]; |
| 88 | + std::shared_ptr<Input> input; |
| 89 | + if (type == Input::Type::Shadow) |
| 90 | + input = std::make_shared<ShadowInput>(it.key(), type); |
| 91 | + else { |
| 92 | + if (primary.is_array()) { |
| 93 | + auto valueType = static_cast<InputValue::Type>(primary[0]); |
| 94 | + switch (valueType) { |
| 95 | + case InputValue::Type::Variable: |
| 96 | + input = std::make_shared<VariableInput>(it.key(), type); |
| 97 | + break; |
| 98 | + case InputValue::Type::List: |
| 99 | + input = std::make_shared<ListInput>(it.key(), type); |
| 100 | + break; |
| 101 | + default: |
| 102 | + assert(false); // a block can only be obscured by a variable or a list in this case |
| 103 | + break; |
| 104 | + } |
| 105 | + } else |
| 106 | + input = std::make_shared<BlockInput>(it.key(), type); |
| 107 | + } |
| 108 | + |
84 | 109 | if (primary.is_array()) { |
85 | 110 | input->setPrimaryValue(jsonToValue(primary[1])); |
86 | 111 | input->primaryValue()->setType(static_cast<InputValue::Type>(primary[0])); |
|
0 commit comments