File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed
Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 1414
1515#include " scratch3reader.h"
1616#include " reader_common.h"
17- #include " zipreader.h"
1817
1918using namespace libscratchcpp ;
2019using json = nlohmann::json;
@@ -211,6 +210,11 @@ bool Scratch3Reader::load()
211210 costume->setRotationCenterX (jsonCostume[" rotationCenterX" ]);
212211 READER_STEP (step, " target -> costume -> rotationCenterY" );
213212 costume->setRotationCenterY (jsonCostume[" rotationCenterY" ]);
213+
214+ void *data;
215+ m_zipReader->readFile (costume->fileName (), &data);
216+ costume->setData (static_cast <char *>(data));
217+
214218 target->addCostume (costume);
215219 }
216220
@@ -360,11 +364,11 @@ std::vector<std::string> Scratch3Reader::extensions()
360364void Scratch3Reader::read ()
361365{
362366 // Read project.json
363- ZipReader reader (fileName ());
364- if (reader. open ()) {
367+ m_zipReader = std::make_unique<ZipReader> (fileName ());
368+ if (m_zipReader-> open ()) {
365369 // Parse the JSON
366370 try {
367- m_json = json::parse (reader. readFileToString (" project.json" ));
371+ m_json = json::parse (m_zipReader-> readFileToString (" project.json" ));
368372 } catch (std::exception &e) {
369373 printErr (" invalid JSON file" , e.what ());
370374 }
Original file line number Diff line number Diff line change 55#include " iprojectreader.h"
66#include < nlohmann/json.hpp>
77
8+ #include " zipreader.h"
9+
810namespace libscratchcpp
911{
1012
@@ -20,6 +22,7 @@ class Scratch3Reader : public IProjectReader
2022
2123 private:
2224 void read ();
25+ std::unique_ptr<ZipReader> m_zipReader;
2326 nlohmann::json m_json = " " ;
2427 std::vector<std::shared_ptr<Target>> m_targets;
2528 std::vector<std::shared_ptr<Broadcast>> m_broadcasts;
Original file line number Diff line number Diff line change @@ -54,6 +54,13 @@ TEST(LoadProjectTest, EmptyProject)
5454 ASSERT_FALSE (backdrop->id ().empty ());
5555 ASSERT_EQ (backdrop->fileName (), backdrop->id () + " .svg" );
5656 ASSERT_EQ (backdrop->dataFormat (), " svg" );
57+ ASSERT_TRUE (backdrop->data ());
58+ ASSERT_EQ (
59+ strcmp (
60+ backdrop->data (),
61+ " <svg version=\" 1.1\" width=\" 2\" height=\" 2\" viewBox=\" -1 -1 2 2\" xmlns=\" http://www.w3.org/2000/svg\" xmlns:xlink=\" http://www.w3.org/1999/xlink\" >\n <!-- Exported by Scratch - "
62+ " http://scratch.mit.edu/ -->\n </svg>" ),
63+ 0 );
5764
5865 i++;
5966 }
You can’t perform that action at this time.
0 commit comments