Compare commits
2 Commits
4dcfcee3dd
...
3bce6bdfd9
Author | SHA1 | Date |
---|---|---|
mrbesen | 3bce6bdfd9 | |
mrbesen | 03cd4b3822 |
|
@ -20,6 +20,7 @@ protected:
|
|||
double njs;
|
||||
double nso;
|
||||
|
||||
std::shared_ptr<FileReader> reader;
|
||||
const json& base;
|
||||
|
||||
std::vector<Note> notes;
|
||||
|
@ -29,6 +30,8 @@ public:
|
|||
BeatLevelImpl(std::weak_ptr<BeatSet> p, std::shared_ptr<FileReader> r, const json& j);
|
||||
virtual ~BeatLevelImpl();
|
||||
|
||||
bool load();
|
||||
|
||||
virtual Difficulty::Difficulty getDifficulty() const override;
|
||||
virtual int32_t getDifficultyRank() const override;
|
||||
virtual std::string getFilename() const override;
|
||||
|
|
|
@ -11,6 +11,8 @@ class BeatSetImpl : public BeatSet, public std::enable_shared_from_this<BeatSetI
|
|||
protected:
|
||||
|
||||
std::weak_ptr<BeatMap> parent;
|
||||
std::shared_ptr<FileReader> reader;
|
||||
const json& base;
|
||||
BeatmapCharacteristic::BeatmapCharacteristic characteristic;
|
||||
|
||||
std::vector<std::shared_ptr<BeatLevel>> level;
|
||||
|
@ -21,6 +23,8 @@ public:
|
|||
BeatSetImpl() = default;
|
||||
virtual ~BeatSetImpl();
|
||||
|
||||
bool load();
|
||||
|
||||
virtual void printDebug() const override;
|
||||
|
||||
virtual BeatmapCharacteristic::BeatmapCharacteristic getCharacteristic() const override;
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#include "beatmap.h"
|
||||
|
||||
namespace Beatsaber {
|
||||
|
||||
const uint32_t STEAMGAMEID = 620980;
|
||||
std::string findBeatsaberInstallation();
|
||||
|
||||
// when gamepath is empty, findBeatsaberInstallation is used to get a Path
|
||||
// from the installation folder as many mas as possible are loaded
|
||||
std::list<std::shared_ptr<BeatMap>> loadMapsfromInstallation(std::string gamePath = "");
|
||||
|
||||
}
|
|
@ -5,27 +5,35 @@
|
|||
|
||||
#include "beatset.h"
|
||||
#include "beatnoteimpl.h"
|
||||
#include "beatmap.h" // for debug print
|
||||
|
||||
namespace Beatsaber {
|
||||
|
||||
BeatLevelImpl::BeatLevelImpl(std::weak_ptr<BeatSet> p, std::shared_ptr<FileReader> r, const json& j) : parent(p), base(j) {
|
||||
dif = Difficulty::getByString(j.value("_difficulty", ""));
|
||||
diffRank = j.value("_difficultyRank", 0);
|
||||
filename = j.value("_beatmapFilename", "");
|
||||
njs = j.value("_noteJumpMovementSpeed", -1);
|
||||
nso = j.value("_noteJumpStartBeatOffset", 0);
|
||||
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 = r->getFileStream(filename);
|
||||
std::shared_ptr<std::istream> stream = reader->getFileStream(filename);
|
||||
json diffjson;
|
||||
(*stream) >> diffjson;
|
||||
|
||||
const std::string& version = diffjson["_version"];
|
||||
if(version != "2.0.0") {
|
||||
//not supported
|
||||
return;
|
||||
|
||||
if(diffjson.contains("_version") && diffjson["_version"].is_string()) {
|
||||
const std::string& version = diffjson["_version"];
|
||||
if(version != "2.0.0") {
|
||||
//not supported
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//load notes
|
||||
|
@ -45,14 +53,19 @@ BeatLevelImpl::BeatLevelImpl(std::weak_ptr<BeatSet> p, std::shared_ptr<FileReade
|
|||
walls.push_back(wall);
|
||||
}
|
||||
}
|
||||
} catch(...) {
|
||||
std::cout << "Could not load difficulty: " << filename << std::endl;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
BeatLevelImpl::~BeatLevelImpl() {}
|
||||
|
||||
Difficulty::Difficulty BeatLevelImpl::getDifficulty() const {
|
||||
return dif;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
#include <iostream> //debug print
|
||||
|
||||
#if BEATSABERZIPSUPPORT == 1
|
||||
#include <zipios/zipiosexceptions.hpp>
|
||||
#endif
|
||||
|
||||
#include "beatsetimpl.h"
|
||||
#include "filereaderimpl.h"
|
||||
|
||||
|
@ -20,7 +24,10 @@ bool BeatMapImpl::load() {
|
|||
|
||||
//load all the beatsets
|
||||
for(const json& jsonbeatset : beatsets) {
|
||||
beatSets.push_back(std::make_shared<BeatSetImpl>(weak_from_this(), reader, jsonbeatset));
|
||||
auto beatset = std::make_shared<BeatSetImpl>(weak_from_this(), reader, jsonbeatset);
|
||||
if(beatset->load())
|
||||
beatSets.push_back(beatset);
|
||||
//return false on false?
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,9 +163,13 @@ std::shared_ptr<BeatMap> BeatMap::loadFromFolder(const std::string& folderPath)
|
|||
|
||||
std::shared_ptr<BeatMap> BeatMap::loadFromZip(const std::string& zipPath) {
|
||||
#if BEATSABERZIPSUPPORT == 1
|
||||
auto map = std::make_shared<BeatMapImpl>(std::make_shared<ZipReader>(zipPath));
|
||||
if(!map->load()) return nullptr;
|
||||
return map;
|
||||
try {
|
||||
auto map = std::make_shared<BeatMapImpl>(std::make_shared<ZipReader>(zipPath));
|
||||
if(!map->load()) return nullptr;
|
||||
return map;
|
||||
} catch(zipios::Exception& e) {
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
// Zip not supported
|
||||
std::cerr << "Zip not supported" << std::endl;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <fstream>
|
||||
#include <iostream> //debug print
|
||||
#include <list>
|
||||
#include <filesystem>
|
||||
|
||||
namespace Beatsaber {
|
||||
|
||||
|
@ -56,13 +57,14 @@ std::string findBeatsaberInstallation() {
|
|||
|
||||
//search in libs for beatsaber
|
||||
for(const std::string& it : paths) {
|
||||
//check if manifest exists
|
||||
const std::string appmani = it + "appmanifest_" + std::to_string(STEAMGAMEID) + ".acf";
|
||||
//std::cout << "Try to read file: " << appmani << std::endl;
|
||||
std::ifstream appmanifest(appmani);
|
||||
if(appmanifest.is_open()) {
|
||||
//found it!
|
||||
//do stuff with the manifest???
|
||||
|
||||
|
||||
appmanifest.close();
|
||||
|
||||
return it + "common/Beat Saber/";
|
||||
|
@ -72,4 +74,31 @@ std::string findBeatsaberInstallation() {
|
|||
return ""; //not found
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<BeatMap>> loadMapsfromInstallation(std::string gamePath) {
|
||||
if(gamePath.empty()) {
|
||||
gamePath = findBeatsaberInstallation();
|
||||
}
|
||||
|
||||
std::filesystem::path path(gamePath);
|
||||
|
||||
std::list<std::shared_ptr<BeatMap>> out;
|
||||
|
||||
for(const auto& i : std::filesystem::directory_iterator(path / "Beat Saber_Data/CustomLevels")) {
|
||||
if(i.exists()) {
|
||||
if(i.is_directory()) {
|
||||
//try to load
|
||||
auto map = BeatMap::loadFromFolder(i.path().string());
|
||||
if(map)
|
||||
out.push_back(map);
|
||||
} else if(i.is_regular_file()) {
|
||||
auto map = BeatMap::loadFromZip(i.path().string());
|
||||
if(map)
|
||||
out.push_back(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
|
@ -7,27 +7,34 @@
|
|||
|
||||
namespace Beatsaber {
|
||||
|
||||
BeatSetImpl::BeatSetImpl(std::weak_ptr<BeatMap> p, std::shared_ptr<FileReader> r, const json& j) : parent(p) {
|
||||
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(j["_beatmapCharacteristicName"]);
|
||||
characteristic = BeatmapCharacteristic::getByString(base["_beatmapCharacteristicName"]);
|
||||
|
||||
//load level
|
||||
const json& arr = j["_difficultyBeatmaps"];
|
||||
const json& arr = base["_difficultyBeatmaps"];
|
||||
if(arr.is_array()) {
|
||||
level.reserve(arr.size());
|
||||
std::cout << "Try to load: " << arr.size() << std::endl;
|
||||
//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));
|
||||
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;
|
||||
}
|
||||
|
||||
BeatSetImpl::~BeatSetImpl() {}
|
||||
|
||||
void BeatSetImpl::printDebug() const {
|
||||
std::cout << " Characteristic: " << BeatmapCharacteristic::toString(characteristic) << std::endl;
|
||||
|
||||
|
|
|
@ -34,13 +34,24 @@ int main(int argc, char** argv) {
|
|||
std::string installdir = Beatsaber::findBeatsaberInstallation();
|
||||
std::cout << "Beatsaber installation directory: " << installdir << std::endl;
|
||||
|
||||
auto list = Beatsaber::loadMapsfromInstallation();
|
||||
std::cout << "Loaded: " << list.size() << " Maps from Beatsaber Installation" << std::endl;
|
||||
|
||||
/*for(auto i : list) {
|
||||
if(i) {
|
||||
i->printDebug();
|
||||
std::cin.get();
|
||||
}
|
||||
}*/
|
||||
|
||||
//simple read test
|
||||
std::shared_ptr<Beatsaber::BeatMap> bmap = Beatsaber::BeatMap::loadFromFolder("/home/yannis/Nextcloud/yannis/Beatsaber/BeatSaverLevel/1dd (Portal - Still Alive (Uppermost Remix) - kryptikos)");
|
||||
/*std::shared_ptr<Beatsaber::BeatMap> bmap = Beatsaber::BeatMap::loadFromFolder("/home/yannis/Nextcloud/yannis/Beatsaber/BeatSaverLevel/1dd (Portal - Still Alive (Uppermost Remix) - kryptikos)");
|
||||
if(!bmap) std::cout << "Could not load File" << std::endl;
|
||||
else bmap->printDebug();
|
||||
bmap = Beatsaber::BeatMap::loadFromZip("/home/yannis/Nextcloud/yannis/Beatsaber/BeatSaverLevel/18b92 (Empress of Light - ShadowLantern).zip");
|
||||
if(!bmap) std::cout << "Could not load File" << std::endl;
|
||||
else bmap->printDebug();
|
||||
*/
|
||||
|
||||
return failcount > 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue