|
8 | 8 | #include <scratchcpp/variable.h> |
9 | 9 | #include <scratchcpp/list.h> |
10 | 10 | #include <scratchcpp/costume.h> |
| 11 | +#include <scratchcpp/comment.h> |
11 | 12 | #include <scratchcpp/sound.h> |
12 | 13 | #include <scratchcpp/stage.h> |
13 | 14 | #include <scratchcpp/sprite.h> |
@@ -188,10 +189,37 @@ bool Scratch3Reader::load() |
188 | 189 | READER_STEP(step, "target -> block -> shadow"); |
189 | 190 | block->setShadow(blockInfo["shadow"]); |
190 | 191 |
|
| 192 | + // comment |
| 193 | + READER_STEP(step, "target -> block -> comment"); |
| 194 | + if (!blockInfo["comment"].is_null()) |
| 195 | + block->setCommentId(blockInfo["comment"]); |
| 196 | + |
191 | 197 | target->addBlock(block); |
192 | 198 | } |
193 | 199 |
|
194 | | - // TODO: Add comments |
| 200 | + // comments |
| 201 | + READER_STEP(step, "target -> comments"); |
| 202 | + auto comments = jsonTarget["comments"]; |
| 203 | + for (json::iterator it = comments.begin(); it != comments.end(); ++it) { |
| 204 | + auto commentInfo = it.value(); |
| 205 | + READER_STEP(step, "target -> comment -> { id, x, y }"); |
| 206 | + auto comment = std::make_shared<Comment>(it.key(), jsonToValue(commentInfo["x"]).toDouble(), jsonToValue(commentInfo["y"]).toDouble()); |
| 207 | + READER_STEP(step, "target -> comment -> blockId"); |
| 208 | + |
| 209 | + if (!commentInfo["blockId"].is_null()) |
| 210 | + comment->setBlockId(commentInfo["blockId"]); |
| 211 | + |
| 212 | + READER_STEP(step, "target -> comment -> width"); |
| 213 | + comment->setWidth(jsonToValue(commentInfo["width"]).toDouble()); |
| 214 | + READER_STEP(step, "target -> comment -> height"); |
| 215 | + comment->setHeight(jsonToValue(commentInfo["height"]).toDouble()); |
| 216 | + READER_STEP(step, "target -> comment -> minimized"); |
| 217 | + comment->setMinimized(commentInfo["minimized"]); |
| 218 | + READER_STEP(step, "target -> comment -> text"); |
| 219 | + comment->setText(commentInfo["text"]); |
| 220 | + |
| 221 | + target->addComment(comment); |
| 222 | + } |
195 | 223 |
|
196 | 224 | // costumes |
197 | 225 | READER_STEP(step, "target -> costumes"); |
|
0 commit comments