2022-03-31 03:50:15 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <optional>
|
|
|
|
#include <set>
|
|
|
|
|
2022-04-14 01:26:31 +02:00
|
|
|
#include <fmt/core.h>
|
2022-03-31 03:50:15 +02:00
|
|
|
#include <json.hpp>
|
|
|
|
|
|
|
|
#include "better_hakus.hpp"
|
|
|
|
#include "better_notes.hpp"
|
|
|
|
#include "better_timing.hpp"
|
|
|
|
#include "special_numeric_types.hpp"
|
|
|
|
|
|
|
|
namespace better {
|
|
|
|
struct Chart {
|
|
|
|
std::optional<Decimal> level;
|
2022-04-03 15:59:05 +02:00
|
|
|
std::optional<Timing> timing;
|
2022-03-31 03:50:15 +02:00
|
|
|
std::optional<Hakus> hakus;
|
|
|
|
Notes notes;
|
|
|
|
|
2022-04-13 02:29:33 +02:00
|
|
|
bool operator==(const Chart&) const = default;
|
|
|
|
|
2022-04-02 04:10:09 +02:00
|
|
|
nlohmann::ordered_json dump_to_memon_1_0_0(
|
2022-04-01 01:41:47 +02:00
|
|
|
const nlohmann::ordered_json& fallback_timing_object
|
|
|
|
) const;
|
2022-04-02 04:10:09 +02:00
|
|
|
|
2022-04-03 15:59:05 +02:00
|
|
|
static Chart load_from_memon_1_0_0(const nlohmann::json& json, const nlohmann::json& fallback_timing);
|
|
|
|
static Chart load_from_memon_legacy(const nlohmann::json& json);
|
2022-04-14 01:26:31 +02:00
|
|
|
|
2022-04-16 02:26:37 +02:00
|
|
|
friend std::ostream& operator<<(std::ostream& out, const Chart& c);
|
2022-03-31 03:50:15 +02:00
|
|
|
};
|
2022-04-01 01:41:47 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Create a brand new json based on 'object' but with keys identical to
|
|
|
|
'fallback' removed
|
|
|
|
*/
|
2022-04-03 15:59:05 +02:00
|
|
|
nlohmann::ordered_json remove_keys_already_in_fallback(
|
2022-04-01 01:41:47 +02:00
|
|
|
const nlohmann::ordered_json& object,
|
|
|
|
const nlohmann::ordered_json& fallback
|
|
|
|
);
|
|
|
|
|
|
|
|
nlohmann::ordered_json dump_memon_1_0_0_timing_object(
|
2022-04-16 02:26:37 +02:00
|
|
|
const std::optional<better::Timing>& timing,
|
2022-04-01 01:41:47 +02:00
|
|
|
const std::optional<Hakus>& hakus,
|
|
|
|
const nlohmann::ordered_json& fallback_timing_object
|
|
|
|
);
|
2022-04-14 01:26:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
struct fmt::formatter<std::optional<T>>: formatter<string_view> {
|
|
|
|
// parse is inherited from formatter<string_view>.
|
|
|
|
template <typename FormatContext>
|
|
|
|
auto format(const std::optional<T>& opt, FormatContext& ctx) {
|
|
|
|
if (opt) {
|
|
|
|
return format_to(ctx.out(), "{}", *opt);
|
|
|
|
} else {
|
|
|
|
return format_to(ctx.out(), "∅");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct fmt::formatter<better::Chart>: formatter<string_view> {
|
|
|
|
// parse is inherited from formatter<string_view>.
|
|
|
|
template <typename FormatContext>
|
|
|
|
auto format(const better::Chart& c, FormatContext& ctx) {
|
|
|
|
return format_to(
|
|
|
|
ctx.out(),
|
2022-04-16 02:26:37 +02:00
|
|
|
"Chart(level: {}, timing: {}, hakus: {}, notes: {})",
|
2022-04-14 01:26:31 +02:00
|
|
|
c.level,
|
|
|
|
c.timing,
|
|
|
|
c.hakus,
|
|
|
|
c.notes
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|