libBeatsaber/src/beatset.cpp

47 lines
1.2 KiB
C++

#include "beatsetimpl.h"
#include <iostream> //debug print
#include <nlohmann/json.hpp>
#include "beatlevelimpl.h"
namespace Beatsaber {
BeatSetImpl::BeatSetImpl(std::weak_ptr<BeatMap> p, std::shared_ptr<FileReader> r, const json& j) : parent(p) {
try {
characteristic = BeatmapCharacteristic::getByString(j["_beatmapCharacteristicName"]);
//load level
const json& arr = j["_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));
}
}
} catch(std::exception& e) {
std::cout << "Could not read BeatSet: " << e.what() << std::endl;
characteristic = BeatmapCharacteristic::NONE;
}
}
BeatSetImpl::~BeatSetImpl() {}
void BeatSetImpl::printDebug() const {
std::cout << " Characteristic: " << BeatmapCharacteristic::toString(characteristic) << std::endl;
for(auto it : level) {
it->printDebug();
}
}
BeatmapCharacteristic::BeatmapCharacteristic BeatSetImpl::getCharacteristic() const {
return characteristic;
}
std::shared_ptr<BeatMap> BeatSetImpl::getBeatMap() const {
return parent.lock();
}
}