2022-03-16 02:10:18 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
#include <map>
|
2022-10-26 02:08:19 +02:00
|
|
|
#include <memory>
|
2022-03-16 02:10:18 +01:00
|
|
|
#include <optional>
|
|
|
|
#include <set>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <tuple>
|
|
|
|
|
2022-03-31 03:50:15 +02:00
|
|
|
#include <json.hpp>
|
2022-03-16 02:10:18 +01:00
|
|
|
#include <SFML/System/Time.hpp>
|
|
|
|
|
2022-03-31 03:50:15 +02:00
|
|
|
#include "better_chart.hpp"
|
|
|
|
#include "better_hakus.hpp"
|
|
|
|
#include "better_metadata.hpp"
|
2022-03-16 02:10:18 +01:00
|
|
|
#include "better_notes.hpp"
|
|
|
|
#include "better_timing.hpp"
|
|
|
|
#include "special_numeric_types.hpp"
|
|
|
|
|
|
|
|
namespace better {
|
2022-03-27 03:32:13 +02:00
|
|
|
std::string stringify_level(std::optional<Decimal> level);
|
|
|
|
|
2022-04-04 22:03:10 +02:00
|
|
|
std::tuple<int, std::string> difficulty_name_comp_key(const std::string& s);
|
2022-03-16 02:10:18 +01:00
|
|
|
|
2022-04-04 22:03:10 +02:00
|
|
|
struct OrderByDifficultyName {
|
2022-04-06 15:47:04 +02:00
|
|
|
bool operator()(const std::string& a, const std::string& b) const;
|
2022-03-16 02:10:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Song {
|
2022-04-04 22:03:10 +02:00
|
|
|
std::map<std::string, better::Chart, OrderByDifficultyName> charts;
|
2022-03-16 02:10:18 +01:00
|
|
|
Metadata metadata;
|
2022-10-26 23:35:00 +02:00
|
|
|
std::shared_ptr<Timing> timing = std::make_shared<Timing>();
|
2022-03-31 03:50:15 +02:00
|
|
|
std::optional<Hakus> hakus;
|
|
|
|
|
2022-04-02 04:10:09 +02:00
|
|
|
nlohmann::ordered_json dump_to_memon_1_0_0() const;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Read the json file as memon by trying to guess version.
|
|
|
|
Throws various exceptions on error
|
|
|
|
*/
|
|
|
|
static Song load_from_memon(const nlohmann::json& memon);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Read the json file as memon v1.0.0.
|
|
|
|
https://memon-spec.readthedocs.io/en/latest/changelog.html#v1-0-0
|
|
|
|
*/
|
|
|
|
static Song load_from_memon_1_0_0(const nlohmann::json& memon);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Read the json file as memon v0.3.0.
|
|
|
|
https://memon-spec.readthedocs.io/en/latest/changelog.html#v0-3-0
|
|
|
|
*/
|
|
|
|
static Song load_from_memon_0_3_0(const nlohmann::json& memon);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Read the json file as memon v0.2.0.
|
|
|
|
https://memon-spec.readthedocs.io/en/latest/changelog.html#v0-2-0
|
|
|
|
*/
|
|
|
|
static Song load_from_memon_0_2_0(const nlohmann::json& memon);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Read the json file as memon v0.1.0.
|
|
|
|
https://memon-spec.readthedocs.io/en/latest/changelog.html#v0-1-0
|
|
|
|
*/
|
|
|
|
static Song load_from_memon_0_1_0(const nlohmann::json& memon);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Read the json file as a "legacy" (pre-versionning) memon file.
|
|
|
|
|
|
|
|
Notable quirks of this archaïc schema :
|
2022-10-04 00:46:28 +02:00
|
|
|
- "data" is an *array* of charts
|
2022-04-02 04:10:09 +02:00
|
|
|
- the difficulty name of a chart is stored as "dif_name" in the chart
|
2022-10-04 00:46:28 +02:00
|
|
|
object
|
2022-04-02 04:10:09 +02:00
|
|
|
- the album cover path field is named "jacket path"
|
|
|
|
*/
|
|
|
|
static Song load_from_memon_legacy(const nlohmann::json& memon);
|
2022-04-16 02:26:37 +02:00
|
|
|
|
2022-11-10 19:28:25 +01:00
|
|
|
bool operator==(const Song&) const;
|
2022-04-16 02:26:37 +02:00
|
|
|
friend std::ostream& operator<<(std::ostream& out, const Song& s);
|
2022-03-16 02:10:18 +01:00
|
|
|
};
|
2022-04-02 04:10:09 +02:00
|
|
|
|
2022-04-03 15:59:05 +02:00
|
|
|
Note load_legacy_note(const nlohmann::json& legacy_note, std::uint64_t resolution);
|
2022-04-02 04:10:09 +02:00
|
|
|
|
2022-04-03 15:59:05 +02:00
|
|
|
Position convert_legacy_memon_tail_index_to_position(const Position& pos, std::uint64_t tail_index);
|
2022-04-16 02:26:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct fmt::formatter<better::Song>: formatter<string_view> {
|
|
|
|
// parse is inherited from formatter<string_view>.
|
|
|
|
template <typename FormatContext>
|
|
|
|
auto format(const better::Song& s, FormatContext& ctx) {
|
|
|
|
return format_to(
|
|
|
|
ctx.out(),
|
|
|
|
"Song(charts: {}, metadata: {}, timing: {}, hakus: {})",
|
|
|
|
s.charts,
|
|
|
|
s.metadata,
|
2022-10-26 02:08:19 +02:00
|
|
|
*s.timing,
|
2022-04-16 02:26:37 +02:00
|
|
|
s.hakus
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|