libBeatsaber/src/beatset.cpp

59 lines
1.5 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), reader(r), base(j) {}
BeatSetImpl::~BeatSetImpl() {}
bool BeatSetImpl::load() {
try {
characteristic = BeatmapCharacteristic::getByString(base["_beatmapCharacteristicName"]);
//load level
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) {
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;
}
void BeatSetImpl::printDebug() const {
std::cout << " Characteristic: " << BeatmapCharacteristic::toString(characteristic)
<< "\n Levels: " << level.size() << std::endl;
for(auto it : level) {
it->printDebug();
}
}
const std::vector<std::shared_ptr<BeatLevel>>& BeatSetImpl::getLevel() const {
return level;
}
BeatmapCharacteristic::BeatmapCharacteristic BeatSetImpl::getCharacteristic() const {
return characteristic;
}
std::shared_ptr<BeatMap> BeatSetImpl::getBeatMap() const {
return parent.lock();
}
}