basic hirachy, basic map loading
This commit is contained in:
parent
be3296acb9
commit
37edb342fa
|
@ -0,0 +1,3 @@
|
||||||
|
# libBeatsaber
|
||||||
|
|
||||||
|
a small Library to read and write beatsaber level.
|
|
@ -0,0 +1,41 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "beatlevel.h"
|
||||||
|
|
||||||
|
#include <nlohmann/json_fwd.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
namespace Beatsaber {
|
||||||
|
|
||||||
|
class BeatLevelImpl : public BeatLevel, protected std::enable_shared_from_this<BeatLevelImpl> {
|
||||||
|
protected:
|
||||||
|
std::weak_ptr<BeatSet> parent;
|
||||||
|
|
||||||
|
Difficulty::Difficulty dif;
|
||||||
|
int32_t diffRank;
|
||||||
|
std::string filename;
|
||||||
|
|
||||||
|
double njs;
|
||||||
|
double nso;
|
||||||
|
|
||||||
|
const json& base;
|
||||||
|
|
||||||
|
public:
|
||||||
|
BeatLevelImpl(std::weak_ptr<BeatSet> p, const json& j);
|
||||||
|
virtual ~BeatLevelImpl();
|
||||||
|
|
||||||
|
virtual Difficulty::Difficulty getDifficulty() const override;
|
||||||
|
virtual int32_t getDifficultyRank() const override;
|
||||||
|
virtual std::string getFilename() const override;
|
||||||
|
virtual double getNoteJumpSpeed() const override; // in m
|
||||||
|
virtual double getNoteStartOffset() const override;
|
||||||
|
virtual std::string getCustomData() const override;
|
||||||
|
|
||||||
|
//TODO: get level content
|
||||||
|
|
||||||
|
virtual std::shared_ptr<BeatSet> getBeatSet() const override;
|
||||||
|
virtual std::shared_ptr<BeatMap> getBeatMap() const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "beatmap.h"
|
#include "beatmap.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#include "beatset.h"
|
#include "beatset.h"
|
||||||
|
@ -10,7 +11,7 @@ using json = nlohmann::json;
|
||||||
|
|
||||||
namespace Beatsaber {
|
namespace Beatsaber {
|
||||||
|
|
||||||
class BeatMapImpl : public BeatMap {
|
class BeatMapImpl : public BeatMap, protected std::enable_shared_from_this<BeatMapImpl> {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const std::string path;
|
const std::string path;
|
||||||
|
|
|
@ -6,18 +6,21 @@ using json = nlohmann::json;
|
||||||
|
|
||||||
namespace Beatsaber {
|
namespace Beatsaber {
|
||||||
|
|
||||||
class BeatSetImpl : public BeatSet {
|
class BeatSetImpl : public BeatSet, protected std::enable_shared_from_this<BeatSetImpl> {
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
std::weak_ptr<BeatMap> parent;
|
||||||
BeatmapCharacteristic::BeatmapCharacteristic characteristic;
|
BeatmapCharacteristic::BeatmapCharacteristic characteristic;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BeatSetImpl(const json& j);
|
BeatSetImpl(std::weak_ptr<BeatMap> p, const json& j);
|
||||||
BeatSetImpl(const BeatSetImpl& c) = default;
|
BeatSetImpl(const BeatSetImpl& c) = default;
|
||||||
BeatSetImpl() = default;
|
BeatSetImpl() = default;
|
||||||
virtual ~BeatSetImpl();
|
virtual ~BeatSetImpl();
|
||||||
|
|
||||||
virtual BeatmapCharacteristic::BeatmapCharacteristic getCharacteristic() const;
|
virtual BeatmapCharacteristic::BeatmapCharacteristic getCharacteristic() const override;
|
||||||
|
virtual std::shared_ptr<BeatMap> getBeatMap() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "difficulties.h"
|
||||||
|
|
||||||
|
namespace Beatsaber {
|
||||||
|
|
||||||
|
//fwd
|
||||||
|
class BeatSet;
|
||||||
|
class BeatMap;
|
||||||
|
|
||||||
|
class BeatLevel {
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual ~BeatLevel() {}
|
||||||
|
|
||||||
|
virtual Difficulty::Difficulty getDifficulty() const = 0;
|
||||||
|
virtual int32_t getDifficultyRank() const = 0;
|
||||||
|
virtual std::string getFilename() const = 0;
|
||||||
|
virtual double getNoteJumpSpeed() const = 0; // in m
|
||||||
|
virtual double getNoteStartOffset() const = 0;
|
||||||
|
virtual std::string getCustomData() const = 0;
|
||||||
|
|
||||||
|
//TODO: get level content
|
||||||
|
|
||||||
|
virtual std::shared_ptr<BeatSet> getBeatSet() const = 0; // parent
|
||||||
|
virtual std::shared_ptr<BeatMap> getBeatMap() const = 0; // grandparent
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -6,15 +6,12 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "beatmapcharacteristic.h"
|
#include "beatmapcharacteristic.h"
|
||||||
|
#include "beatlevel.h"
|
||||||
|
|
||||||
#include "beatset.h"
|
#include "beatset.h"
|
||||||
|
|
||||||
namespace Beatsaber {
|
namespace Beatsaber {
|
||||||
|
|
||||||
class BeatLevel {
|
|
||||||
public:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class BeatMap {
|
class BeatMap {
|
||||||
public:
|
public:
|
||||||
virtual ~BeatMap() {}
|
virtual ~BeatMap() {}
|
||||||
|
|
|
@ -1,15 +1,21 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "beatmapcharacteristic.h"
|
#include "beatmapcharacteristic.h"
|
||||||
|
#include "beatlevel.h"
|
||||||
|
|
||||||
namespace Beatsaber {
|
namespace Beatsaber {
|
||||||
|
|
||||||
|
//fwd decl.
|
||||||
|
class BeatMap;
|
||||||
|
|
||||||
class BeatSet {
|
class BeatSet {
|
||||||
public:
|
public:
|
||||||
virtual ~BeatSet() {}
|
virtual ~BeatSet() {}
|
||||||
|
|
||||||
virtual BeatmapCharacteristic::BeatmapCharacteristic getCharacteristic() const = 0;
|
virtual BeatmapCharacteristic::BeatmapCharacteristic getCharacteristic() const = 0;
|
||||||
|
virtual std::shared_ptr<BeatMap> getBeatMap() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -12,5 +12,10 @@ namespace Beatsaber {
|
||||||
EXPERT,
|
EXPERT,
|
||||||
EXPERTP,
|
EXPERTP,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const std::string difficultyName[] {"None", "Easy", "Normal", "Hard", "Expert", "ExpertPlus"};
|
||||||
|
const std::uint8_t difficultyNameSize = sizeof(difficultyName)/sizeof(std::string);
|
||||||
|
|
||||||
|
Difficulty getByString(const std::string& str);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
#include "beatlevelimpl.h"
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include "beatset.h"
|
||||||
|
|
||||||
|
namespace Beatsaber {
|
||||||
|
|
||||||
|
BeatLevelImpl::BeatLevelImpl(std::weak_ptr<BeatSet> p, 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);
|
||||||
|
|
||||||
|
//load level content
|
||||||
|
if(!filename.empty()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BeatLevelImpl::~BeatLevelImpl() {}
|
||||||
|
|
||||||
|
Difficulty::Difficulty BeatLevelImpl::getDifficulty() const {
|
||||||
|
return dif;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t BeatLevelImpl::getDifficultyRank() const {
|
||||||
|
return diffRank;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BeatLevelImpl::getFilename() const {
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
double BeatLevelImpl::getNoteJumpSpeed() const {
|
||||||
|
return njs;
|
||||||
|
}
|
||||||
|
|
||||||
|
double BeatLevelImpl::getNoteStartOffset() const {
|
||||||
|
return nso;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BeatLevelImpl::getCustomData() const {
|
||||||
|
if(base.contains("_customData")) {
|
||||||
|
return base["_customData"].dump();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<BeatSet> BeatLevelImpl::getBeatSet() const {
|
||||||
|
return parent.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<BeatMap> BeatLevelImpl::getBeatMap() const {
|
||||||
|
return parent.lock()->getBeatMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -24,7 +24,7 @@ bool BeatMapImpl::load() {
|
||||||
|
|
||||||
//load all the beatsets
|
//load all the beatsets
|
||||||
for(const json& jsonbeatset : beatsets) {
|
for(const json& jsonbeatset : beatsets) {
|
||||||
beatSets.push_back(std::make_shared<BeatSetImpl>(jsonbeatset));
|
beatSets.push_back(std::make_shared<BeatSetImpl>(shared_from_this(), jsonbeatset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,10 @@ std::string BeatMapImpl::get360EnvName() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BeatMapImpl::getCustomData() const {
|
std::string BeatMapImpl::getCustomData() const {
|
||||||
return infobase["_customData"].dump();
|
if(infobase.contains("_customData")) {
|
||||||
|
return infobase["_customData"].dump();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::shared_ptr<BeatSet>>& BeatMapImpl::getBeatSets() const {
|
const std::vector<std::shared_ptr<BeatSet>>& BeatMapImpl::getBeatSets() const {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
namespace Beatsaber {
|
namespace Beatsaber {
|
||||||
|
|
||||||
BeatSetImpl::BeatSetImpl(const json& j) : characteristic(BeatmapCharacteristic::getByString(j["_beatmapCharacteristicName"])) {
|
BeatSetImpl::BeatSetImpl(std::weak_ptr<BeatMap> p, const json& j) : parent(p), characteristic(BeatmapCharacteristic::getByString(j["_beatmapCharacteristicName"])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
BeatSetImpl::~BeatSetImpl() {}
|
BeatSetImpl::~BeatSetImpl() {}
|
||||||
|
@ -13,4 +13,8 @@ BeatmapCharacteristic::BeatmapCharacteristic BeatSetImpl::getCharacteristic() co
|
||||||
return characteristic;
|
return characteristic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<BeatMap> BeatSetImpl::getBeatMap() const {
|
||||||
|
return parent.lock();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
#include "beatmapcharacteristic.h"
|
#include "beatmapcharacteristic.h"
|
||||||
|
#include "difficulties.h"
|
||||||
|
|
||||||
namespace Beatsaber {
|
namespace Beatsaber {
|
||||||
namespace BeatmapCharacteristic {
|
namespace BeatmapCharacteristic {
|
||||||
|
@ -12,5 +13,16 @@ BeatmapCharacteristic getByString(const std::string& str) {
|
||||||
return BeatmapCharacteristic::NONE;
|
return BeatmapCharacteristic::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Difficulty {
|
||||||
|
Difficulty getByString(const std::string& str) {
|
||||||
|
for(uint8_t i = 0; i < difficultyNameSize; ++i) {
|
||||||
|
if(str == difficultyName[i]) { //TODO equals ignore Case
|
||||||
|
return (Difficulty) i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Difficulty::NONE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,8 +4,12 @@
|
||||||
#include "beatmap.h"
|
#include "beatmap.h"
|
||||||
|
|
||||||
//tests
|
//tests
|
||||||
|
int difficulties_test();
|
||||||
|
int characteristics_test();
|
||||||
|
|
||||||
test_t tests[] = {NULL};
|
test_t tests[] = {
|
||||||
|
difficulties_test, characteristics_test,
|
||||||
|
NULL};
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define TESTDATA "./tests/data/"
|
#define TESTDATA "./tests/data/"
|
||||||
|
|
||||||
#define ASSERT(BED, ERR) if(!(BED)) { std::cout << __FILE__ << ":" << __LINE__ << " " << ERR << std::endl; return TESTFAILED; }
|
#define ASSERT(BED, ERR) if(!(BED)) { std::cout << __FILE__ << ":" << __LINE__ << " " << ERR << std::endl; return TESTFAILED; }
|
||||||
// #define ASSERT(BED) ASSERT(BED, "")
|
#define CMPASSERTE(A, B, ERR) if( !((A) == (B))) { std::cout << __FILE__ << ":" << __LINE__ << " is: \"" << (A) << "\" should: \"" << (B) << "\""<< std::endl; return TESTFAILED; }
|
||||||
|
#define CMPASSERT(A, B) CMPASSERTE(A, B, "")
|
||||||
|
|
||||||
typedef int (*test_t)();
|
typedef int (*test_t)();
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
#include "difficulties.h"
|
||||||
|
#include "beatmapcharacteristic.h"
|
||||||
|
|
||||||
|
int difficulties_test() {
|
||||||
|
|
||||||
|
using d = Beatsaber::Difficulty::Difficulty;
|
||||||
|
using namespace Beatsaber::Difficulty;
|
||||||
|
|
||||||
|
CMPASSERT(d::EASY, getByString("Easy"));
|
||||||
|
CMPASSERT(d::NORMAL, getByString("Normal"));
|
||||||
|
|
||||||
|
CMPASSERT(d::NONE, getByString(""));
|
||||||
|
CMPASSERT(d::NONE, getByString("abc"));
|
||||||
|
|
||||||
|
CMPASSERT(d::HARD, getByString("Hard"));
|
||||||
|
CMPASSERT(d::EXPERTP, getByString("ExpertPlus"));
|
||||||
|
|
||||||
|
return TESTGOOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
int characteristics_test() {
|
||||||
|
|
||||||
|
using c = Beatsaber::BeatmapCharacteristic::BeatmapCharacteristic;
|
||||||
|
using namespace Beatsaber::BeatmapCharacteristic;
|
||||||
|
|
||||||
|
CMPASSERT(c::NONE, getByString(""));
|
||||||
|
CMPASSERT(c::NONE, getByString("abc"));
|
||||||
|
|
||||||
|
CMPASSERT(c::STANDARD, getByString("Standard"));
|
||||||
|
CMPASSERT(c::ONESABER, getByString("OneSaber"));
|
||||||
|
CMPASSERT(c::NOARROWS, getByString("NoArrows"));
|
||||||
|
CMPASSERT(c::DEGREE90, getByString("90Degree"));
|
||||||
|
CMPASSERT(c::DEGREE360, getByString("360Degree"));
|
||||||
|
|
||||||
|
return TESTGOOD;
|
||||||
|
}
|
Loading…
Reference in New Issue