libBeatsaber/src/beatset.cpp

59 lines
1.5 KiB
C++
Raw Normal View History

2021-05-30 21:56:21 +02:00
#include "beatsetimpl.h"
2021-06-01 21:05:33 +02:00
#include <iostream> //debug print
2021-05-30 21:56:21 +02:00
#include <nlohmann/json.hpp>
2021-06-01 21:05:33 +02:00
#include "beatlevelimpl.h"
2021-05-30 21:56:21 +02:00
namespace Beatsaber {
2021-06-12 20:17:24 +02:00
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() {
2021-06-01 21:05:33 +02:00
try {
2021-06-12 20:17:24 +02:00
characteristic = BeatmapCharacteristic::getByString(base["_beatmapCharacteristicName"]);
2021-06-01 21:05:33 +02:00
//load level
2021-06-12 20:17:24 +02:00
const json& arr = base["_difficultyBeatmaps"];
2021-06-01 21:05:33 +02:00
if(arr.is_array()) {
level.reserve(arr.size());
2021-06-12 18:04:14 +02:00
//std::cout << "Try to load: " << arr.size() << " BeatLevel" << std::endl;
2021-06-01 21:05:33 +02:00
for(const json& beat : arr) {
2021-06-12 20:17:24 +02:00
auto beatlevel = std::make_shared<BeatLevelImpl>(weak_from_this(), reader, beat);
if(beatlevel->load())
level.push_back(beatlevel);
// return false on false?
2021-06-01 21:05:33 +02:00
}
2021-06-12 20:17:24 +02:00
return true;
2021-06-01 21:05:33 +02:00
}
} catch(std::exception& e) {
std::cout << "Could not read BeatSet: " << e.what() << std::endl;
characteristic = BeatmapCharacteristic::NONE;
}
2021-06-12 20:17:24 +02:00
return false;
2021-05-30 21:56:21 +02:00
}
2021-06-01 21:05:33 +02:00
void BeatSetImpl::printDebug() const {
2021-06-14 12:28:52 +02:00
std::cout << " Characteristic: " << BeatmapCharacteristic::toString(characteristic)
<< "\n Levels: " << level.size() << std::endl;
2021-06-01 21:05:33 +02:00
for(auto it : level) {
it->printDebug();
}
}
2021-06-14 12:28:52 +02:00
const std::vector<std::shared_ptr<BeatLevel>>& BeatSetImpl::getLevel() const {
return level;
}
2021-05-30 21:56:21 +02:00
BeatmapCharacteristic::BeatmapCharacteristic BeatSetImpl::getCharacteristic() const {
return characteristic;
}
2021-06-01 11:47:41 +02:00
std::shared_ptr<BeatMap> BeatSetImpl::getBeatMap() const {
return parent.lock();
}
2021-05-30 21:56:21 +02:00
}