libBeatsaber/src/beatlevel.cpp

95 lines
2.2 KiB
C++

#include "beatlevelimpl.h"
#include <iostream>
#include <nlohmann/json.hpp>
#include "beatset.h"
#include "beatnoteimpl.h"
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);
//load level content
if(!filename.empty()) {
try {
std::shared_ptr<std::istream> stream = r->getFileStream(filename);
json diffjson;
(*stream) >> diffjson;
const std::string& version = diffjson["_version"];
if(version != "2.0.0") {
//not supported
return;
}
//load notes
const json& jnotes = diffjson["_notes"];
if(jnotes.is_array()) {
notes.reserve(jnotes.size());
for(const json& note : jnotes) {
notes.push_back(note);
}
}
} catch(...) {
std::cout << "Could not load difficulty: " << filename << std::endl;
}
}
}
BeatLevelImpl::~BeatLevelImpl() {}
Difficulty::Difficulty BeatLevelImpl::getDifficulty() const {
return dif;
}
int32_t BeatLevelImpl::getDifficultyRank() const {
return diffRank;
}
std::string BeatLevelImpl::getFilename() const {
return filename;
}
double BeatLevelImpl::getNoteJumpSpeed() const {
return njs;
}
double BeatLevelImpl::getNoteStartOffset() const {
return nso;
}
std::string BeatLevelImpl::getCustomData() const {
if(base.contains("_customData")) {
return base["_customData"].dump();
}
return "";
}
const std::vector<Note>& BeatLevelImpl::getNotes() const {
return notes;
}
void BeatLevelImpl::printDebug() const {
std::cout <<
" Difficulty: " << Difficulty::toString(dif) << " (" << diffRank << ")"
<< "\n Filename: " << getFilename()
<< "\n njs: " << getNoteJumpSpeed() << " nso: " << getNoteStartOffset()
<< "\n noteCount: " << notes.size()
<< std::endl;
}
std::shared_ptr<BeatSet> BeatLevelImpl::getBeatSet() const {
return parent.lock();
}
std::shared_ptr<BeatMap> BeatLevelImpl::getBeatMap() const {
return parent.lock()->getBeatMap();
}
}