diff --git a/include/beatsaber-impl/beatlevelimpl.h b/include/beatsaber-impl/beatlevelimpl.h index 60d2586..fff2dbf 100644 --- a/include/beatsaber-impl/beatlevelimpl.h +++ b/include/beatsaber-impl/beatlevelimpl.h @@ -3,9 +3,10 @@ #include "beatlevel.h" #include - using json = nlohmann::json; +#include "filereader.h" + namespace Beatsaber { class BeatLevelImpl : public BeatLevel, public std::enable_shared_from_this { @@ -22,7 +23,7 @@ protected: const json& base; public: - BeatLevelImpl(std::weak_ptr p, const json& j); + BeatLevelImpl(std::weak_ptr p, std::shared_ptr r, const json& j); virtual ~BeatLevelImpl(); virtual Difficulty::Difficulty getDifficulty() const override; diff --git a/include/beatsaber-impl/beatmapimpl.h b/include/beatsaber-impl/beatmapimpl.h index e576819..fa56350 100644 --- a/include/beatsaber-impl/beatmapimpl.h +++ b/include/beatsaber-impl/beatmapimpl.h @@ -6,6 +6,7 @@ #include #include "beatset.h" +#include "filereader.h" using json = nlohmann::json; @@ -14,8 +15,7 @@ namespace Beatsaber { class BeatMapImpl : public BeatMap, public std::enable_shared_from_this { protected: - const std::string path; - const bool isZip; + std::shared_ptr reader; json infobase; std::vector> beatSets; @@ -23,7 +23,7 @@ protected: bool load(); public: - BeatMapImpl(const std::string& path, bool isZip); + BeatMapImpl(std::shared_ptr r); ~BeatMapImpl(); virtual std::string getVersion() const override; diff --git a/include/beatsaber-impl/beatsetimpl.h b/include/beatsaber-impl/beatsetimpl.h index f3d9663..7eb98c6 100644 --- a/include/beatsaber-impl/beatsetimpl.h +++ b/include/beatsaber-impl/beatsetimpl.h @@ -1,9 +1,10 @@ #include "beatset.h" #include - using json = nlohmann::json; +#include "filereader.h" + namespace Beatsaber { class BeatSetImpl : public BeatSet, public std::enable_shared_from_this { @@ -15,7 +16,7 @@ protected: std::vector> level; public: - BeatSetImpl(std::weak_ptr p, const json& j); + BeatSetImpl(std::weak_ptr p, std::shared_ptr r, const json& j); BeatSetImpl(const BeatSetImpl& c) = default; BeatSetImpl() = default; virtual ~BeatSetImpl(); diff --git a/src/beatlevel.cpp b/src/beatlevel.cpp index 40d2305..492be40 100644 --- a/src/beatlevel.cpp +++ b/src/beatlevel.cpp @@ -7,7 +7,7 @@ namespace Beatsaber { -BeatLevelImpl::BeatLevelImpl(std::weak_ptr p, const json& j) : parent(p), base(j) { +BeatLevelImpl::BeatLevelImpl(std::weak_ptr p, std::shared_ptr r, const json& j) : parent(p), base(j) { dif = Difficulty::getByString(j.value("_difficulty", "")); diffRank = j.value("_difficultyRank", 0); filename = j.value("_beatmapFilename", ""); @@ -16,7 +16,14 @@ BeatLevelImpl::BeatLevelImpl(std::weak_ptr p, const json& j) : parent(p //load level content if(!filename.empty()) { - + try { + std::shared_ptr stream = r->getFileStream(filename); + json json; + (*stream) >> json; + //TODO + } catch(...) { + std::cout << "Could not load difficulty: " << filename << std::endl; + } } } diff --git a/src/beatmap.cpp b/src/beatmap.cpp index a0caa82..3568c10 100644 --- a/src/beatmap.cpp +++ b/src/beatmap.cpp @@ -1,20 +1,17 @@ #include "beatmapimpl.h" -#include #include //debug print #include "beatsetimpl.h" +#include "filereaderimpl.h" namespace Beatsaber { bool BeatMapImpl::load() { // try to open info.dat - if(isZip) { - return false; - } - std::ifstream info(path + "/info.dat"); //try diffrent filenames if not found? + std::shared_ptr stream = reader->getFileStream("info.dat"); try { - info >> infobase; + (*stream) >> infobase; //load the beatset const json& beatsets = infobase["_difficultyBeatmapSets"]; @@ -23,7 +20,7 @@ bool BeatMapImpl::load() { //load all the beatsets for(const json& jsonbeatset : beatsets) { - beatSets.push_back(std::make_shared(weak_from_this(), jsonbeatset)); + beatSets.push_back(std::make_shared(weak_from_this(), reader, jsonbeatset)); } } @@ -34,7 +31,7 @@ bool BeatMapImpl::load() { return false; } -BeatMapImpl::BeatMapImpl(const std::string& path, bool isZip) : path(path), isZip(isZip) {} +BeatMapImpl::BeatMapImpl(std::shared_ptr r) : reader(r) {} BeatMapImpl::~BeatMapImpl() {} @@ -152,14 +149,14 @@ void BeatMapImpl::printDebug() const { std::shared_ptr BeatMap::loadFromFolder(const std::string& folderPath) { - auto map = std::make_shared(folderPath, false); + auto map = std::make_shared(std::make_shared(folderPath)); if(!map->load()) return nullptr; return map; } std::shared_ptr BeatMap::loadFromZip(const std::string& zipPath) { #if BEATSABERZIPSUPPORT == 1 - auto map = std::make_shared(zipPath, true); + auto map = std::make_shared(std::make_shared(zipPath)); if(!map->load()) return nullptr; return map; #else diff --git a/src/beatset.cpp b/src/beatset.cpp index abb8cae..a733e79 100644 --- a/src/beatset.cpp +++ b/src/beatset.cpp @@ -7,7 +7,7 @@ namespace Beatsaber { -BeatSetImpl::BeatSetImpl(std::weak_ptr p, const json& j) : parent(p) { +BeatSetImpl::BeatSetImpl(std::weak_ptr p, std::shared_ptr r, const json& j) : parent(p) { try { characteristic = BeatmapCharacteristic::getByString(j["_beatmapCharacteristicName"]); @@ -17,7 +17,7 @@ BeatSetImpl::BeatSetImpl(std::weak_ptr p, const json& j) : parent(p) { level.reserve(arr.size()); std::cout << "Try to load: " << arr.size() << std::endl; for(const json& beat : arr) { - level.push_back(std::make_shared(weak_from_this(), beat)); + level.push_back(std::make_shared(weak_from_this(), r, beat)); } } } catch(std::exception& e) { diff --git a/tests/main.cpp b/tests/main.cpp index f7daeb1..d78680f 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -30,7 +30,7 @@ int main(int argc, char** argv) { printf("\033[1;93m%d\033[0;1m/%d failed\n", failcount, testcount); //simple read test - std::shared_ptr bmap = Beatsaber::BeatMap::loadFromFolder("/media/satassd/steam/steamapps/common/Beat Saber/Beat Saber_Data/CustomLevels/1dd (Portal - Still Alive (Uppermost Remix) - kryptikos)"); + std::shared_ptr bmap = Beatsaber::BeatMap::loadFromFolder("/home/yannis/Nextcloud/yannis/Beatsaber/BeatSaverLevel/1dd (Portal - Still Alive (Uppermost Remix) - kryptikos)"); if(!bmap) std::cout << "Could not load File" << std::endl; else bmap->printDebug();