From 483ed9a867394db10fa71adc6c1543453e3eecfd Mon Sep 17 00:00:00 2001 From: MrBesen Date: Fri, 4 Jun 2021 14:53:31 +0200 Subject: [PATCH] reading walls --- include/beatsaber-impl/beatlevelimpl.h | 2 ++ include/beatsaber-impl/beatnoteimpl.h | 1 + include/beatsaber/beatlevel.h | 1 + include/beatsaber/beatnote.h | 13 ++++++++++++- src/beatlevel.cpp | 15 ++++++++++++++- src/beatmap.cpp | 4 ++-- src/beatnote.cpp | 25 ++++++++++++++++++++----- src/filereader.cpp | 2 +- 8 files changed, 53 insertions(+), 10 deletions(-) diff --git a/include/beatsaber-impl/beatlevelimpl.h b/include/beatsaber-impl/beatlevelimpl.h index 00005f1..8e852a3 100644 --- a/include/beatsaber-impl/beatlevelimpl.h +++ b/include/beatsaber-impl/beatlevelimpl.h @@ -23,6 +23,7 @@ protected: const json& base; std::vector notes; + std::vector walls; public: BeatLevelImpl(std::weak_ptr p, std::shared_ptr r, const json& j); @@ -37,6 +38,7 @@ public: //TODO: get level content virtual const std::vector& getNotes() const override; + virtual const std::vector& getWalls() const override; virtual void printDebug() const override; diff --git a/include/beatsaber-impl/beatnoteimpl.h b/include/beatsaber-impl/beatnoteimpl.h index fde6aed..f8a6b8e 100644 --- a/include/beatsaber-impl/beatnoteimpl.h +++ b/include/beatsaber-impl/beatnoteimpl.h @@ -8,5 +8,6 @@ using json = nlohmann::json; namespace Beatsaber { void from_json(const json& j, Note& n); +void from_json(const json& j, Wall& n); } \ No newline at end of file diff --git a/include/beatsaber/beatlevel.h b/include/beatsaber/beatlevel.h index ad50eb9..83e917e 100644 --- a/include/beatsaber/beatlevel.h +++ b/include/beatsaber/beatlevel.h @@ -27,6 +27,7 @@ public: //TODO: get level content virtual const std::vector& getNotes() const = 0; + virtual const std::vector& getWalls() const = 0; virtual void printDebug() const = 0; diff --git a/include/beatsaber/beatnote.h b/include/beatsaber/beatnote.h index c9e0c2c..2c45e89 100644 --- a/include/beatsaber/beatnote.h +++ b/include/beatsaber/beatnote.h @@ -1,6 +1,7 @@ -#pragma once + #pragma once #include +#include namespace Beatsaber { @@ -10,6 +11,16 @@ struct Note { std::uint_fast8_t layer; //layer 0 = bottom, 2 = top std::uint_fast8_t type; //0 = rednote, 1 = bluenote, 2 = unused, 3 = bomb std::uint_fast8_t cutdir; + std::string customdata; +}; + +struct Wall { + std::uint32_t time; // time in beats when the note reaches the player + std::uint_fast8_t line; //0-3, 0 = left, 3 = right + std::uint_fast8_t type; // 0 = fullhight, 1 = crouch + std::int32_t duration; //time in beats the wall is there, might be nagtive... + std::int_fast8_t width; //might be negative (should be between 0-4) + std::string customdata; }; } \ No newline at end of file diff --git a/src/beatlevel.cpp b/src/beatlevel.cpp index 2e5fae2..4ed7b20 100644 --- a/src/beatlevel.cpp +++ b/src/beatlevel.cpp @@ -36,6 +36,15 @@ BeatLevelImpl::BeatLevelImpl(std::weak_ptr p, std::shared_ptr& BeatLevelImpl::getNotes() const { return notes; } +const std::vector& BeatLevelImpl::getWalls() const { + return walls; +} + void BeatLevelImpl::printDebug() const { std::cout << " Difficulty: " << Difficulty::toString(dif) << " (" << diffRank << ")" << "\n Filename: " << getFilename() << "\n njs: " << getNoteJumpSpeed() << " nso: " << getNoteStartOffset() - << "\n noteCount: " << notes.size() + << "\n noteCount: " << notes.size() << " wallCount: " << walls.size() << std::endl; } diff --git a/src/beatmap.cpp b/src/beatmap.cpp index 88bbeba..8012e31 100644 --- a/src/beatmap.cpp +++ b/src/beatmap.cpp @@ -9,7 +9,7 @@ namespace Beatsaber { bool BeatMapImpl::load() { // try to open info.dat - std::shared_ptr stream = reader->getFileStream("Info.dat"); + std::shared_ptr stream = reader->getFileStream("info.dat"); try { (*stream) >> infobase; @@ -26,7 +26,7 @@ bool BeatMapImpl::load() { return true; } catch(const nlohmann::detail::exception& e) { //catch any json errors - std::cout << "Could not Read BeatMap: " << e.what() << std::endl; + std::cout << "Could not read BeatMap: " << e.what() << std::endl; } return false; } diff --git a/src/beatnote.cpp b/src/beatnote.cpp index 191a330..5733891 100644 --- a/src/beatnote.cpp +++ b/src/beatnote.cpp @@ -5,11 +5,26 @@ namespace Beatsaber { void from_json(const json& j, Note& n) { - n.time = j["_time"]; - n.line = j["_lineIndex"]; - n.layer = j["_lineLayer"]; - n.type = j["_type"]; - n.cutdir = j["_cutDirection"]; + n.time = j.value("_time", 0); + n.line = j.value("_lineIndex", 0); + n.layer = j.value("_lineLayer", 0); + n.type = j.value("_type", 0); + n.cutdir = j.value("_cutDirection", 0); + if(j.contains("_customData")) { + n.customdata = j["_customData"].dump(); + } +} + +void from_json(const json& j, Wall& w) { + w.time = j.value("_time", 0); + w.line = j.value("_lineIndex", 0); + w.type = j.value("_type", 0); + w.duration = j.value("_duration", 0); + w.width = j.value("_width", 1); + + if(j.contains("_customData")) { + w.customdata = j["_customData"].dump(); + } } } \ No newline at end of file diff --git a/src/filereader.cpp b/src/filereader.cpp index 3a0923c..91c99dd 100644 --- a/src/filereader.cpp +++ b/src/filereader.cpp @@ -58,7 +58,7 @@ ZipReader::~ZipReader() { std::shared_ptr ZipReader::getFileStream(const std::string& filename) { std::shared_ptr stream = file.getInputStream(filename); - if(stream) { + if(!stream) { //search for other files std::vector entrys; getEntrys(entrys);