changed to FileReader
This commit is contained in:
parent
fd6f908671
commit
340096b20f
|
@ -3,9 +3,10 @@
|
|||
#include "beatlevel.h"
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
#include "filereader.h"
|
||||
|
||||
namespace Beatsaber {
|
||||
|
||||
class BeatLevelImpl : public BeatLevel, public std::enable_shared_from_this<BeatLevelImpl> {
|
||||
|
@ -22,7 +23,7 @@ protected:
|
|||
const json& base;
|
||||
|
||||
public:
|
||||
BeatLevelImpl(std::weak_ptr<BeatSet> p, const json& j);
|
||||
BeatLevelImpl(std::weak_ptr<BeatSet> p, std::shared_ptr<FileReader> r, const json& j);
|
||||
virtual ~BeatLevelImpl();
|
||||
|
||||
virtual Difficulty::Difficulty getDifficulty() const override;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <nlohmann/json.hpp>
|
||||
|
||||
#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<BeatMapImpl> {
|
||||
|
||||
protected:
|
||||
const std::string path;
|
||||
const bool isZip;
|
||||
std::shared_ptr<FileReader> reader;
|
||||
|
||||
json infobase;
|
||||
std::vector<std::shared_ptr<BeatSet>> beatSets;
|
||||
|
@ -23,7 +23,7 @@ protected:
|
|||
bool load();
|
||||
|
||||
public:
|
||||
BeatMapImpl(const std::string& path, bool isZip);
|
||||
BeatMapImpl(std::shared_ptr<FileReader> r);
|
||||
~BeatMapImpl();
|
||||
|
||||
virtual std::string getVersion() const override;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include "beatset.h"
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
#include "filereader.h"
|
||||
|
||||
namespace Beatsaber {
|
||||
|
||||
class BeatSetImpl : public BeatSet, public std::enable_shared_from_this<BeatSetImpl> {
|
||||
|
@ -15,7 +16,7 @@ protected:
|
|||
std::vector<std::shared_ptr<BeatLevel>> level;
|
||||
|
||||
public:
|
||||
BeatSetImpl(std::weak_ptr<BeatMap> p, const json& j);
|
||||
BeatSetImpl(std::weak_ptr<BeatMap> p, std::shared_ptr<FileReader> r, const json& j);
|
||||
BeatSetImpl(const BeatSetImpl& c) = default;
|
||||
BeatSetImpl() = default;
|
||||
virtual ~BeatSetImpl();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Beatsaber {
|
||||
|
||||
BeatLevelImpl::BeatLevelImpl(std::weak_ptr<BeatSet> p, const json& j) : parent(p), base(j) {
|
||||
BeatLevelImpl::BeatLevelImpl(std::weak_ptr<BeatSet> p, std::shared_ptr<FileReader> 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<BeatSet> p, const json& j) : parent(p
|
|||
|
||||
//load level content
|
||||
if(!filename.empty()) {
|
||||
|
||||
try {
|
||||
std::shared_ptr<std::istream> stream = r->getFileStream(filename);
|
||||
json json;
|
||||
(*stream) >> json;
|
||||
//TODO
|
||||
} catch(...) {
|
||||
std::cout << "Could not load difficulty: " << filename << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
#include "beatmapimpl.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream> //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<std::istream> 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<BeatSetImpl>(weak_from_this(), jsonbeatset));
|
||||
beatSets.push_back(std::make_shared<BeatSetImpl>(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<FileReader> r) : reader(r) {}
|
||||
|
||||
BeatMapImpl::~BeatMapImpl() {}
|
||||
|
||||
|
@ -152,14 +149,14 @@ void BeatMapImpl::printDebug() const {
|
|||
|
||||
|
||||
std::shared_ptr<BeatMap> BeatMap::loadFromFolder(const std::string& folderPath) {
|
||||
auto map = std::make_shared<BeatMapImpl>(folderPath, false);
|
||||
auto map = std::make_shared<BeatMapImpl>(std::make_shared<FolderReader>(folderPath));
|
||||
if(!map->load()) return nullptr;
|
||||
return map;
|
||||
}
|
||||
|
||||
std::shared_ptr<BeatMap> BeatMap::loadFromZip(const std::string& zipPath) {
|
||||
#if BEATSABERZIPSUPPORT == 1
|
||||
auto map = std::make_shared<BeatMapImpl>(zipPath, true);
|
||||
auto map = std::make_shared<BeatMapImpl>(std::make_shared<ZipReader>(zipPath));
|
||||
if(!map->load()) return nullptr;
|
||||
return map;
|
||||
#else
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Beatsaber {
|
||||
|
||||
BeatSetImpl::BeatSetImpl(std::weak_ptr<BeatMap> p, const json& j) : parent(p) {
|
||||
BeatSetImpl::BeatSetImpl(std::weak_ptr<BeatMap> p, std::shared_ptr<FileReader> r, const json& j) : parent(p) {
|
||||
try {
|
||||
characteristic = BeatmapCharacteristic::getByString(j["_beatmapCharacteristicName"]);
|
||||
|
||||
|
@ -17,7 +17,7 @@ BeatSetImpl::BeatSetImpl(std::weak_ptr<BeatMap> 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<BeatLevelImpl>(weak_from_this(), beat));
|
||||
level.push_back(std::make_shared<BeatLevelImpl>(weak_from_this(), r, beat));
|
||||
}
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
|
|
|
@ -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<Beatsaber::BeatMap> 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<Beatsaber::BeatMap> 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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue