2022-04-09 00:54:06 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <variant>
|
|
|
|
|
2022-10-14 02:42:13 +02:00
|
|
|
#include "better_metadata.hpp"
|
2022-04-09 00:54:06 +02:00
|
|
|
#include "better_notes.hpp"
|
|
|
|
#include "better_song.hpp"
|
|
|
|
|
|
|
|
class EditorState;
|
|
|
|
|
|
|
|
|
|
|
|
class HistoryItem {
|
|
|
|
public:
|
|
|
|
explicit HistoryItem(std::string message = "") :
|
|
|
|
message(std::move(message)) {};
|
|
|
|
|
|
|
|
const std::string& get_message() const;
|
|
|
|
virtual void do_action(EditorState& ed) const {};
|
|
|
|
virtual void undo_action(EditorState& ed) const {};
|
|
|
|
|
|
|
|
virtual ~HistoryItem() = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string message;
|
|
|
|
};
|
|
|
|
|
2022-10-13 00:59:40 +02:00
|
|
|
|
|
|
|
class AddNotes : public HistoryItem {
|
2022-04-09 00:54:06 +02:00
|
|
|
public:
|
2022-10-13 00:59:40 +02:00
|
|
|
AddNotes(
|
|
|
|
const std::string& difficulty_name,
|
|
|
|
const better::Notes& notes
|
|
|
|
);
|
2022-04-09 00:54:06 +02:00
|
|
|
|
|
|
|
void do_action(EditorState& ed) const override;
|
2022-10-13 00:59:40 +02:00
|
|
|
void undo_action(EditorState& ed) const override;
|
2022-04-09 00:54:06 +02:00
|
|
|
|
|
|
|
protected:
|
2022-10-13 00:59:40 +02:00
|
|
|
std::string difficulty_name;
|
2022-04-09 00:54:06 +02:00
|
|
|
better::Notes notes;
|
|
|
|
};
|
|
|
|
|
2022-10-13 00:59:40 +02:00
|
|
|
|
|
|
|
class RemoveNotes : public AddNotes {
|
2022-04-09 00:54:06 +02:00
|
|
|
public:
|
2022-10-13 00:59:40 +02:00
|
|
|
RemoveNotes(
|
|
|
|
const std::string& difficulty_name,
|
|
|
|
const better::Notes& notes
|
|
|
|
);
|
|
|
|
|
|
|
|
void do_action(EditorState& ed) const override;
|
|
|
|
void undo_action(EditorState& ed) const override;
|
|
|
|
};
|
|
|
|
|
2022-11-10 23:39:39 +01:00
|
|
|
class AddChart : public HistoryItem {
|
|
|
|
public:
|
|
|
|
AddChart(
|
|
|
|
const std::string& difficulty_name,
|
|
|
|
const better::Chart& chart
|
|
|
|
);
|
|
|
|
|
|
|
|
void do_action(EditorState& ed) const override;
|
|
|
|
void undo_action(EditorState& ed) const override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string difficulty_name;
|
|
|
|
better::Chart chart;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RemoveChart : public AddChart {
|
|
|
|
public:
|
|
|
|
RemoveChart(
|
|
|
|
const std::string& difficulty_name,
|
|
|
|
const better::Chart& chart
|
|
|
|
);
|
|
|
|
|
|
|
|
void do_action(EditorState& ed) const override;
|
|
|
|
void undo_action(EditorState& ed) const override;
|
|
|
|
};
|
|
|
|
|
2022-10-13 00:59:40 +02:00
|
|
|
|
|
|
|
class RerateChart : public HistoryItem {
|
|
|
|
public:
|
|
|
|
RerateChart(
|
|
|
|
const std::string& chart,
|
|
|
|
const std::optional<Decimal>& old_level,
|
|
|
|
const std::optional<Decimal>& new_level
|
|
|
|
);
|
2022-04-09 00:54:06 +02:00
|
|
|
|
|
|
|
void do_action(EditorState& ed) const override;
|
|
|
|
void undo_action(EditorState& ed) const override;
|
|
|
|
|
|
|
|
protected:
|
2022-10-13 00:59:40 +02:00
|
|
|
std::string chart;
|
|
|
|
std::optional<Decimal> old_level;
|
|
|
|
std::optional<Decimal> new_level;
|
2022-04-09 00:54:06 +02:00
|
|
|
};
|
|
|
|
|
2022-10-13 00:59:40 +02:00
|
|
|
|
|
|
|
class RenameChart : public HistoryItem {
|
2022-04-09 00:54:06 +02:00
|
|
|
public:
|
2022-10-13 00:59:40 +02:00
|
|
|
RenameChart(
|
|
|
|
const std::string& old_name,
|
|
|
|
const std::string& new_name
|
|
|
|
);
|
2022-04-09 00:54:06 +02:00
|
|
|
|
|
|
|
void do_action(EditorState& ed) const override;
|
|
|
|
void undo_action(EditorState& ed) const override;
|
|
|
|
|
2022-10-13 00:59:40 +02:00
|
|
|
protected:
|
|
|
|
std::string old_name;
|
|
|
|
std::string new_name;
|
|
|
|
};
|
2022-10-14 02:42:13 +02:00
|
|
|
|
|
|
|
template<class T>
|
2022-10-26 23:35:00 +02:00
|
|
|
class ChangeValue : public HistoryItem {
|
2022-10-14 02:42:13 +02:00
|
|
|
public:
|
|
|
|
|
2022-10-26 23:35:00 +02:00
|
|
|
ChangeValue(const T& old_value, const T& new_value) :
|
2022-10-14 02:42:13 +02:00
|
|
|
old_value(old_value),
|
|
|
|
new_value(new_value)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_action(EditorState& ed) const override {
|
|
|
|
set_value(ed, new_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void undo_action(EditorState& ed) const override {
|
|
|
|
set_value(ed, old_value);
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
virtual void set_value(EditorState& ed, const T& value) const = 0;
|
|
|
|
|
|
|
|
T old_value;
|
|
|
|
T new_value;
|
|
|
|
};
|
|
|
|
|
2022-10-26 23:35:00 +02:00
|
|
|
class ChangeTitle : public ChangeValue<std::string> {
|
2022-10-14 02:42:13 +02:00
|
|
|
public:
|
|
|
|
ChangeTitle(const std::string& old_value, const std::string& new_value);
|
|
|
|
protected:
|
|
|
|
void set_value(EditorState& ed, const std::string& value) const override;
|
|
|
|
};
|
|
|
|
|
2022-10-26 23:35:00 +02:00
|
|
|
class ChangeArtist : public ChangeValue<std::string> {
|
2022-10-14 02:42:13 +02:00
|
|
|
public:
|
|
|
|
ChangeArtist(const std::string& old_value, const std::string& new_value);
|
|
|
|
protected:
|
|
|
|
void set_value(EditorState& ed, const std::string& value) const override;
|
|
|
|
};
|
|
|
|
|
2022-10-26 23:35:00 +02:00
|
|
|
class ChangeAudio : public ChangeValue<std::string> {
|
2022-10-14 02:42:13 +02:00
|
|
|
public:
|
|
|
|
ChangeAudio(const std::string& old_value, const std::string& new_value);
|
|
|
|
protected:
|
|
|
|
void set_value(EditorState& ed, const std::string& value) const override;
|
|
|
|
};
|
|
|
|
|
2022-10-26 23:35:00 +02:00
|
|
|
class ChangeJacket : public ChangeValue<std::string> {
|
2022-10-14 02:42:13 +02:00
|
|
|
public:
|
|
|
|
ChangeJacket(const std::string& old_value, const std::string& new_value);;
|
|
|
|
protected:
|
|
|
|
void set_value(EditorState& ed, const std::string& value) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
using PreviewState = std::variant<better::PreviewLoop, std::string>;
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct fmt::formatter<PreviewState>: formatter<string_view> {
|
|
|
|
// parse is inherited from formatter<string_view>.
|
|
|
|
template <typename FormatContext>
|
|
|
|
auto format(const PreviewState& c, FormatContext& ctx) {
|
|
|
|
const auto format_ = VariantVisitor {
|
|
|
|
[&](const better::PreviewLoop& loop) {
|
|
|
|
return format_to(ctx.out(), "{}", loop);
|
|
|
|
},
|
|
|
|
[&](const std::string& file) {
|
|
|
|
return format_to(ctx.out(), "\"{}\"", file);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return std::visit(format_, c);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-26 23:35:00 +02:00
|
|
|
class ChangePreview : public ChangeValue<PreviewState> {
|
2022-10-14 02:42:13 +02:00
|
|
|
public:
|
|
|
|
ChangePreview(const PreviewState& old_value, const PreviewState& new_value);
|
|
|
|
protected:
|
|
|
|
void set_value(EditorState& ed, const PreviewState& value) const override;
|
|
|
|
};
|
2022-10-26 23:35:00 +02:00
|
|
|
|
|
|
|
struct GlobalTimingObject {};
|
|
|
|
|
|
|
|
using TimingOrigin = std::variant<GlobalTimingObject, std::string>;
|
|
|
|
|
|
|
|
class ChangeTiming : public ChangeValue<better::Timing> {
|
|
|
|
public:
|
|
|
|
ChangeTiming(
|
|
|
|
const better::Timing& old_timing,
|
|
|
|
const better::Timing& new_timing,
|
|
|
|
const TimingOrigin& origin
|
|
|
|
);
|
|
|
|
protected:
|
|
|
|
TimingOrigin origin;
|
|
|
|
|
|
|
|
void set_value(EditorState& ed, const better::Timing& value) const override;
|
|
|
|
};
|