2017-08-17 23:41:11 +02:00
|
|
|
//
|
|
|
|
// Created by Syméon on 17/08/2017.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Fumen.h"
|
2017-08-25 13:14:38 +02:00
|
|
|
|
|
|
|
void Fumen::loadFromMemon(std::string path) {
|
|
|
|
|
|
|
|
// for convenience
|
|
|
|
using json = nlohmann::json;
|
|
|
|
json j;
|
|
|
|
std::ifstream fichier(path);
|
|
|
|
|
|
|
|
fichier >> j;
|
|
|
|
|
2018-12-23 01:55:43 +01:00
|
|
|
this->songTitle = j.at("metadata").value("song title","");
|
|
|
|
this->artist = j.at("metadata").value("artist","");
|
|
|
|
this->musicPath = j.at("metadata").value("music path","");
|
|
|
|
this->jacketPath = j.at("metadata").value("jacket path","");
|
|
|
|
for (auto& chart_json : j.at("data")) {
|
|
|
|
Chart chart = Chart(chart_json.at("dif_name"),chart_json.value("level",0),chart_json.at("resolution"));
|
|
|
|
for (auto& note : chart_json.at("notes")) {
|
|
|
|
chart.Notes.emplace(note.at("n"),note.at("t"),note.at("l"),note.at("p"));
|
2017-08-25 23:12:27 +02:00
|
|
|
}
|
2018-12-23 01:55:43 +01:00
|
|
|
this->Charts[chart.dif_name] = chart;
|
2017-08-25 23:12:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fumen::saveAsMemon(std::string path) {
|
|
|
|
|
|
|
|
std::ofstream fichier(path);
|
|
|
|
using json = nlohmann::json;
|
|
|
|
json j;
|
|
|
|
j["metadata"] = json::object();
|
2018-12-23 01:55:43 +01:00
|
|
|
j["metadata"]["song_title"] = this->songTitle;
|
|
|
|
j["metadata"]["artist"] = this->artist;
|
|
|
|
j["metadata"]["music_path"] = this->musicPath;
|
|
|
|
j["metadata"]["jacket_path"] = this->jacketPath;
|
|
|
|
j["metadata"]["BPM"] = this->BPM;
|
|
|
|
j["metadata"]["offset"] = this->offset;
|
2017-08-25 23:12:27 +02:00
|
|
|
j["data"] = json::array();
|
2018-12-23 01:55:43 +01:00
|
|
|
for (auto& tuple : this->Charts) {
|
2017-08-25 23:12:27 +02:00
|
|
|
json chart_json;
|
2018-12-23 01:55:43 +01:00
|
|
|
chart_json["dif_name"] = tuple.second.dif_name;
|
|
|
|
chart_json["level"] = tuple.second.level;
|
|
|
|
chart_json["resolution"] = tuple.second.getResolution();
|
2017-08-25 23:12:27 +02:00
|
|
|
chart_json["notes"] = json::array();
|
2018-12-23 01:55:43 +01:00
|
|
|
for (auto& note : tuple.second.Notes) {
|
2017-08-25 23:12:27 +02:00
|
|
|
json note_json;
|
|
|
|
note_json["n"] = note.getPos();
|
|
|
|
note_json["t"] = note.getTiming();
|
|
|
|
note_json["l"] = note.getLength();
|
|
|
|
note_json["p"] = note.getTrail_pos();
|
|
|
|
chart_json["notes"].push_back(note_json);
|
|
|
|
}
|
|
|
|
j["data"].push_back(chart_json);
|
|
|
|
}
|
|
|
|
|
2018-12-23 01:55:43 +01:00
|
|
|
fichier << j.dump(4) << std::endl;
|
2017-08-25 13:14:38 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Fumen::Fumen(const std::string &songTitle,
|
|
|
|
const std::string &artist,
|
|
|
|
const std::string &musicPath,
|
|
|
|
const std::string &jacketPath,
|
|
|
|
float BPM,
|
|
|
|
float offset) : songTitle(songTitle),
|
|
|
|
artist(artist),
|
|
|
|
musicPath(musicPath),
|
|
|
|
jacketPath(jacketPath),
|
|
|
|
BPM(BPM),
|
2017-08-25 23:12:27 +02:00
|
|
|
offset(offset) {}
|