mirror of
https://gitlab.com/square-game-liberation-front/F.E.I.S.git
synced 2025-02-28 23:41:33 +01:00
Refactor Notes load/dumping
This commit is contained in:
parent
be1eeaf21e
commit
a5fe10600f
@ -49,40 +49,24 @@ namespace better {
|
||||
*/
|
||||
hakus = load_hakus(json["timing"]);
|
||||
}
|
||||
Chart chart{
|
||||
return Chart{
|
||||
.level = level,
|
||||
.timing = timing,
|
||||
.hakus = hakus,
|
||||
.notes = {}
|
||||
.notes = Notes::load_from_memon_1_0_0(json.at("notes"), chart_resolution)
|
||||
};
|
||||
for (auto& json_note : json.at("notes")) {
|
||||
try {
|
||||
const auto note = Note::load_from_memon_0_1_0(json_note, chart_resolution);
|
||||
chart.notes.insert(note);
|
||||
} catch (const std::exception&) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return chart;
|
||||
}
|
||||
|
||||
Chart Chart::load_from_memon_legacy(const nlohmann::json& json) {
|
||||
Chart chart {
|
||||
return Chart{
|
||||
.level = Decimal{json["level"].get<int>()},
|
||||
.timing = {},
|
||||
.hakus = {},
|
||||
.notes = {}
|
||||
.notes = Notes::load_from_memon_legacy(
|
||||
json.at("notes"),
|
||||
json.at("resolution").get<std::uint64_t>()
|
||||
)
|
||||
};
|
||||
const auto resolution = json["resolution"].get<std::uint64_t>();
|
||||
for (auto& json_note : json.at("notes")) {
|
||||
try {
|
||||
const auto note = Note::load_from_memon_legacy(json_note, resolution);
|
||||
chart.notes.insert(note);
|
||||
} catch (const std::exception&) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return chart;
|
||||
}
|
||||
|
||||
nlohmann::ordered_json remove_keys_already_in_fallback(
|
||||
|
@ -109,7 +109,7 @@ namespace better {
|
||||
Notes res;
|
||||
res.interval_tree::insert(*its.begin(), *its.end());
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
std::size_t Notes::count_between(const Interval<Fraction>& bounds) {
|
||||
std::size_t count = 0;
|
||||
@ -118,7 +118,7 @@ namespace better {
|
||||
[&](const Notes::const_iterator& it){count++;}
|
||||
);
|
||||
return count;
|
||||
}
|
||||
};
|
||||
|
||||
nlohmann::ordered_json Notes::dump_to_memon_1_0_0() const {
|
||||
auto json_notes = nlohmann::ordered_json::array();
|
||||
@ -126,5 +126,31 @@ namespace better {
|
||||
json_notes.push_back(note.dump_to_memon_1_0_0());
|
||||
}
|
||||
return json_notes;
|
||||
}
|
||||
};
|
||||
|
||||
Notes Notes::load_from_memon_1_0_0(const nlohmann::json& json, std::uint64_t resolution) {
|
||||
Notes notes;
|
||||
for (auto& json_note : json) {
|
||||
try {
|
||||
const auto note = Note::load_from_memon_1_0_0(json_note, resolution);
|
||||
notes.insert(note);
|
||||
} catch (const std::exception&) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return notes;
|
||||
};
|
||||
|
||||
Notes Notes::load_from_memon_legacy(const nlohmann::json& json, std::uint64_t resolution) {
|
||||
Notes notes;
|
||||
for (auto& json_note : json) {
|
||||
try {
|
||||
const auto note = Note::load_from_memon_legacy(json_note, resolution);
|
||||
notes.insert(note);
|
||||
} catch (const std::exception&) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return notes;
|
||||
};
|
||||
}
|
@ -37,5 +37,8 @@ namespace better {
|
||||
std::size_t count_between(const Interval<Fraction>& bounds);
|
||||
|
||||
nlohmann::ordered_json dump_to_memon_1_0_0() const;
|
||||
|
||||
static Notes load_from_memon_1_0_0(const nlohmann::json& json, std::uint64_t resolution = 240);
|
||||
static Notes load_from_memon_legacy(const nlohmann::json& json, std::uint64_t resolution);
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user