fix setting of parent
This commit is contained in:
parent
03cd4b3822
commit
3bce6bdfd9
|
@ -20,6 +20,7 @@ protected:
|
|||
double njs;
|
||||
double nso;
|
||||
|
||||
std::shared_ptr<FileReader> reader;
|
||||
const json& base;
|
||||
|
||||
std::vector<Note> notes;
|
||||
|
@ -29,6 +30,8 @@ public:
|
|||
BeatLevelImpl(std::weak_ptr<BeatSet> p, std::shared_ptr<FileReader> r, const json& j);
|
||||
virtual ~BeatLevelImpl();
|
||||
|
||||
bool load();
|
||||
|
||||
virtual Difficulty::Difficulty getDifficulty() const override;
|
||||
virtual int32_t getDifficultyRank() const override;
|
||||
virtual std::string getFilename() const override;
|
||||
|
|
|
@ -11,6 +11,8 @@ class BeatSetImpl : public BeatSet, public std::enable_shared_from_this<BeatSetI
|
|||
protected:
|
||||
|
||||
std::weak_ptr<BeatMap> parent;
|
||||
std::shared_ptr<FileReader> reader;
|
||||
const json& base;
|
||||
BeatmapCharacteristic::BeatmapCharacteristic characteristic;
|
||||
|
||||
std::vector<std::shared_ptr<BeatLevel>> level;
|
||||
|
@ -21,6 +23,8 @@ public:
|
|||
BeatSetImpl() = default;
|
||||
virtual ~BeatSetImpl();
|
||||
|
||||
bool load();
|
||||
|
||||
virtual void printDebug() const override;
|
||||
|
||||
virtual BeatmapCharacteristic::BeatmapCharacteristic getCharacteristic() const override;
|
||||
|
|
|
@ -9,24 +9,31 @@
|
|||
|
||||
namespace Beatsaber {
|
||||
|
||||
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", "");
|
||||
njs = j.value("_noteJumpMovementSpeed", -1);
|
||||
nso = j.value("_noteJumpStartBeatOffset", 0);
|
||||
BeatLevelImpl::BeatLevelImpl(std::weak_ptr<BeatSet> p, std::shared_ptr<FileReader> r, const json& j) : parent(p), reader(r), base(j) {
|
||||
}
|
||||
|
||||
BeatLevelImpl::~BeatLevelImpl() {}
|
||||
|
||||
bool BeatLevelImpl::load() {
|
||||
dif = Difficulty::getByString(base.value("_difficulty", ""));
|
||||
diffRank = base.value("_difficultyRank", 0);
|
||||
filename = base.value("_beatmapFilename", "");
|
||||
njs = base.value("_noteJumpMovementSpeed", -1);
|
||||
nso = base.value("_noteJumpStartBeatOffset", 0);
|
||||
|
||||
//load level content
|
||||
if(!filename.empty()) {
|
||||
try {
|
||||
std::shared_ptr<std::istream> stream = r->getFileStream(filename);
|
||||
std::shared_ptr<std::istream> stream = reader->getFileStream(filename);
|
||||
json diffjson;
|
||||
(*stream) >> diffjson;
|
||||
|
||||
const std::string& version = diffjson["_version"];
|
||||
if(version != "2.0.0") {
|
||||
//not supported
|
||||
return;
|
||||
|
||||
if(diffjson.contains("_version") && diffjson["_version"].is_string()) {
|
||||
const std::string& version = diffjson["_version"];
|
||||
if(version != "2.0.0") {
|
||||
//not supported
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//load notes
|
||||
|
@ -46,18 +53,19 @@ BeatLevelImpl::BeatLevelImpl(std::weak_ptr<BeatSet> p, std::shared_ptr<FileReade
|
|||
walls.push_back(wall);
|
||||
}
|
||||
}
|
||||
} catch(...) {
|
||||
|
||||
return true;
|
||||
} catch(const std::exception& exc) {
|
||||
std::string mapname = "<unknown>";
|
||||
auto par = parent.lock();
|
||||
if(par)
|
||||
mapname = par->getBeatMap()->getSongName();
|
||||
std::cout << "Could not load difficulty: " << filename << " from: " << mapname << std::endl; //is the direct access after p.lock() a problem? is the parent always loaded?
|
||||
std::cout << "Could not load difficulty: " << filename << " from: " << mapname << " " << exc.what() << std::endl; //is the direct access after p.lock() a problem? is the parent always loaded?
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
BeatLevelImpl::~BeatLevelImpl() {}
|
||||
|
||||
Difficulty::Difficulty BeatLevelImpl::getDifficulty() const {
|
||||
return dif;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,10 @@ bool BeatMapImpl::load() {
|
|||
|
||||
//load all the beatsets
|
||||
for(const json& jsonbeatset : beatsets) {
|
||||
beatSets.push_back(std::make_shared<BeatSetImpl>(weak_from_this(), reader, jsonbeatset));
|
||||
auto beatset = std::make_shared<BeatSetImpl>(weak_from_this(), reader, jsonbeatset);
|
||||
if(beatset->load())
|
||||
beatSets.push_back(beatset);
|
||||
//return false on false?
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,27 +7,34 @@
|
|||
|
||||
namespace Beatsaber {
|
||||
|
||||
BeatSetImpl::BeatSetImpl(std::weak_ptr<BeatMap> p, std::shared_ptr<FileReader> r, const json& j) : parent(p) {
|
||||
BeatSetImpl::BeatSetImpl(std::weak_ptr<BeatMap> p, std::shared_ptr<FileReader> r, const json& j) : parent(p), reader(r), base(j) {}
|
||||
|
||||
BeatSetImpl::~BeatSetImpl() {}
|
||||
|
||||
bool BeatSetImpl::load() {
|
||||
try {
|
||||
characteristic = BeatmapCharacteristic::getByString(j["_beatmapCharacteristicName"]);
|
||||
characteristic = BeatmapCharacteristic::getByString(base["_beatmapCharacteristicName"]);
|
||||
|
||||
//load level
|
||||
const json& arr = j["_difficultyBeatmaps"];
|
||||
const json& arr = base["_difficultyBeatmaps"];
|
||||
if(arr.is_array()) {
|
||||
level.reserve(arr.size());
|
||||
//std::cout << "Try to load: " << arr.size() << " BeatLevel" << std::endl;
|
||||
for(const json& beat : arr) {
|
||||
level.push_back(std::make_shared<BeatLevelImpl>(weak_from_this(), r, beat));
|
||||
auto beatlevel = std::make_shared<BeatLevelImpl>(weak_from_this(), reader, beat);
|
||||
if(beatlevel->load())
|
||||
level.push_back(beatlevel);
|
||||
// return false on false?
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
std::cout << "Could not read BeatSet: " << e.what() << std::endl;
|
||||
characteristic = BeatmapCharacteristic::NONE;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
BeatSetImpl::~BeatSetImpl() {}
|
||||
|
||||
void BeatSetImpl::printDebug() const {
|
||||
std::cout << " Characteristic: " << BeatmapCharacteristic::toString(characteristic) << std::endl;
|
||||
|
||||
|
|
Loading…
Reference in New Issue