130 lines
3.3 KiB
C++
130 lines
3.3 KiB
C++
#include "beatlevelimpl.h"
|
|
|
|
#include <iostream>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include "beatsaber.h"
|
|
#include "beatset.h"
|
|
#include "beatnoteimpl.h"
|
|
#include "beatmap.h" // for debug print
|
|
#include "beatlevelrenderhelperimpl.h"
|
|
|
|
namespace Beatsaber {
|
|
|
|
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 = reader->getFileStream(filename);
|
|
json diffjson;
|
|
(*stream) >> diffjson;
|
|
|
|
if(!ignoreVersionMissmatch && diffjson.contains("_version") && diffjson["_version"].is_string()) {
|
|
const std::string& version = diffjson["_version"];
|
|
if(version != "2.0.0") {
|
|
//not supported
|
|
std::cout << "version not supported: " << version << std::endl;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
//load notes
|
|
const json& jnotes = diffjson["_notes"];
|
|
if(jnotes.is_array()) {
|
|
notes.reserve(jnotes.size());
|
|
for(const json& note : jnotes) {
|
|
notes.push_back(note);
|
|
}
|
|
}
|
|
|
|
//load walls
|
|
const json& jwalls = diffjson["_obstacles"];
|
|
if(jwalls.is_array()) {
|
|
walls.reserve(jwalls.size());
|
|
for(const json& wall : jwalls) {
|
|
walls.push_back(wall);
|
|
}
|
|
}
|
|
|
|
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 << " " << exc.what() << std::endl; //is the direct access after p.lock() a problem? is the parent always loaded?
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
const std::vector<Wall>& BeatLevelImpl::getWalls() const {
|
|
return walls;
|
|
}
|
|
|
|
void BeatLevelImpl::printDebug() const {
|
|
std::cout <<
|
|
" Difficulty: " << Difficulty::toString(dif) << " (" << diffRank << ")"
|
|
<< "\n Filename: " << getFilename()
|
|
<< "\n njs: " << getNoteJumpSpeed() << " nso: " << getNoteStartOffset()
|
|
<< "\n noteCount: " << notes.size() << " wallCount: " << walls.size()
|
|
<< "\n CustomData: " << getCustomData()
|
|
<< std::endl;
|
|
}
|
|
|
|
std::shared_ptr<BeatSet> BeatLevelImpl::getBeatSet() const {
|
|
return parent.lock();
|
|
}
|
|
|
|
std::shared_ptr<BeatMap> BeatLevelImpl::getBeatMap() const {
|
|
return parent.lock()->getBeatMap();
|
|
}
|
|
|
|
std::shared_ptr<BeatLevelRenderHelper> BeatLevelImpl::getRenderHelper() const {
|
|
auto ptr = std::make_shared<BeatLevelRenderHelperImpl>(shared_from_this());
|
|
return ptr;
|
|
}
|
|
|
|
} |