#include "beatmapimpl.h" #include #include //debug print #include "beatsetimpl.h" namespace Beatsaber { bool BeatMapImpl::load() { // try to open info.dat if(isZip) { return false; } std::ifstream info(path + "/info.dat"); //try diffrent filenames if not found? try { info >> infobase; //load the beatset const json& beatsets = infobase["_difficultyBeatmapSets"]; if(beatsets.is_array()) { beatSets.reserve(beatsets.size()); //load all the beatsets for(const json& jsonbeatset : beatsets) { beatSets.push_back(std::make_shared(jsonbeatset)); } } return true; } catch(...) {} //catch any json errors return false; } BeatMapImpl::BeatMapImpl(const std::string& path, bool isZip) : path(path), isZip(isZip) {} BeatMapImpl::~BeatMapImpl() {} std::string BeatMapImpl::getVersion() const { return infobase.value("_version", ""); } std::string BeatMapImpl::getSongName() const { return infobase.value("_songName", ""); } std::string BeatMapImpl::getSubName() const { return infobase.value("_songSubName", ""); } std::string BeatMapImpl::getSongAuthorName() const { return infobase.value("_songAuthorName", ""); } std::string BeatMapImpl::getMapperName() const { return infobase.value("_levelAuthorName", ""); } double BeatMapImpl::getBPM() const { return infobase.value("_beatsPerMinute", -1); } double BeatMapImpl::getTimeOffset() const { return infobase.value("_songTimeOffset", 0); } double BeatMapImpl::getSchuffle() const { return infobase.value("_shuffle", 0); } double BeatMapImpl::getSchufflePeriod() const { return infobase.value("_shufflePeriod", 0); } double BeatMapImpl::getPreviewStart() const { return infobase.value("_previewStartTime", 0); } double BeatMapImpl::getPreviewDuration() const { return infobase.value("_previewDuration", 0); } std::string BeatMapImpl::getSongFilename() const { return infobase.value("_songFilename", ""); } std::string BeatMapImpl::getImageFilename() const { return infobase.value("_coverImageFilename", ""); } std::string BeatMapImpl::getEnvName() const { return infobase.value("_environmentName", ""); } std::string BeatMapImpl::get360EnvName() const { return infobase.value("_allDirectionsEnvironmentName", ""); } std::string BeatMapImpl::getCustomData() const { return infobase["_customData"].dump(); } const std::vector>& BeatMapImpl::getBeatSets() const { return beatSets; } std::uint32_t BeatMapImpl::getBeatSetCount() const { return beatSets.size(); } const std::shared_ptr BeatMapImpl::getBeatSet(BeatmapCharacteristic::BeatmapCharacteristic characteristic) const { for(auto it = beatSets.begin(); it != beatSets.end(); ++it) { if((*it)->getCharacteristic() == characteristic) { return *it; } } return nullptr; } std::shared_ptr BeatMapImpl::getBeatSet(BeatmapCharacteristic::BeatmapCharacteristic characteristic) { for(auto it = beatSets.begin(); it != beatSets.end(); ++it) { if((*it)->getCharacteristic() == characteristic) { return *it; } } return nullptr; } void BeatMapImpl::printDebug() const { std::cout << "SongName: " << getSongName() << " - " << getSongAuthorName() << " (" << getSubName() << ")" << "\nMapper: " << getMapperName() << "\nVersion: " << getVersion() << "\nBPM: " << getBPM() << " offset: " << getTimeOffset() << "\nSchuffle " << getSchuffle() << " period: " << getSchufflePeriod() << "\nPreviewStart: " << getPreviewStart() << " duration: " << getPreviewDuration() << "\nSongFile: " << getSongFilename() << "\nImageFile: " << getImageFilename() << "\nEnvName: " << getEnvName() << " 360Env: " << get360EnvName() << "\ncustomData: " << getCustomData() << "\nBeatSetCount: " << getBeatSetCount() << std::endl; } std::unique_ptr BeatMap::loadFromFolder(const std::string& folderPath) { auto map = std::make_unique(folderPath, false); if(!map->load()) return nullptr; return map; } std::unique_ptr BeatMap::loadFromZip(const std::string& zipPath) { auto map = std::make_unique(zipPath, true); if(!map->load()) return nullptr; return map; } }