2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

input_common/tas: overwrite file dialog

This commit is contained in:
german77 2021-06-26 10:38:39 -05:00 committed by MonsterDruide1
parent f078b15565
commit 9bb6580d89
3 changed files with 16 additions and 20 deletions

View file

@ -102,7 +102,7 @@ void Tas::LoadTasFile(size_t player_index) {
LOG_INFO(Input, "TAS file loaded! {} frames", frame_no); LOG_INFO(Input, "TAS file loaded! {} frames", frame_no);
} }
void Tas::WriteTasFile() { void Tas::WriteTasFile(std::string file_name) {
std::string output_text; std::string output_text;
for (size_t frame = 0; frame < record_commands.size(); frame++) { for (size_t frame = 0; frame < record_commands.size(); frame++) {
if (!output_text.empty()) { if (!output_text.empty()) {
@ -113,7 +113,7 @@ void Tas::WriteTasFile() {
WriteCommandAxis(line.l_axis) + " " + WriteCommandAxis(line.r_axis); WriteCommandAxis(line.l_axis) + " " + WriteCommandAxis(line.r_axis);
} }
const size_t bytes_written = Common::FS::WriteStringToFile( const size_t bytes_written = Common::FS::WriteStringToFile(
Common::FS::GetYuzuPathString(Common::FS::YuzuPath::TASDir) + "record.txt", Common::FS::GetYuzuPathString(Common::FS::YuzuPath::TASDir) + file_name,
Common::FS::FileType::TextFile, output_text); Common::FS::FileType::TextFile, output_text);
if (bytes_written == output_text.size()) { if (bytes_written == output_text.size()) {
LOG_INFO(Input, "TAS file written to file!"); LOG_INFO(Input, "TAS file written to file!");
@ -189,18 +189,8 @@ void Tas::UpdateThread() {
if (is_recording) { if (is_recording) {
record_commands.push_back(last_input); record_commands.push_back(last_input);
} }
if (!is_recording && !record_commands.empty()) {
WriteTasFile();
needs_reset = true;
refresh_tas_fle = true;
record_commands.clear();
}
if (needs_reset) { if (needs_reset) {
current_command = 0; current_command = 0;
if (refresh_tas_fle) {
LoadTasFiles();
refresh_tas_fle = false;
}
needs_reset = false; needs_reset = false;
LoadTasFiles(); LoadTasFiles();
LOG_DEBUG(Input, "tas_reset done"); LOG_DEBUG(Input, "tas_reset done");
@ -306,10 +296,8 @@ void Tas::Reset() {
needs_reset = true; needs_reset = true;
} }
void Tas::Record() { bool Tas::Record() {
is_recording = !is_recording; is_recording = !is_recording;
<<<<<<< HEAD
=======
return is_recording; return is_recording;
} }
@ -326,7 +314,6 @@ void Tas::SaveRecording(bool overwrite_file) {
} }
needs_reset = true; needs_reset = true;
record_commands.clear(); record_commands.clear();
>>>>>>> 773d268db (config: disable pause on load)
} }
InputCommon::ButtonMapping Tas::GetButtonMappingForDevice( InputCommon::ButtonMapping Tas::GetButtonMappingForDevice(

View file

@ -68,7 +68,8 @@ public:
void StartStop(); void StartStop();
void Reset(); void Reset();
void Record(); bool Record();
void SaveRecording(bool overwrite_file);
/** /**
* Returns the current status values of TAS playback/recording * Returns the current status values of TAS playback/recording
@ -90,7 +91,7 @@ private:
}; };
void LoadTasFiles(); void LoadTasFiles();
void LoadTasFile(size_t player_index); void LoadTasFile(size_t player_index);
void WriteTasFile(); void WriteTasFile(std::string file_name);
TasAnalog ReadCommandAxis(const std::string& line) const; TasAnalog ReadCommandAxis(const std::string& line) const;
u32 ReadCommandButtons(const std::string& line) const; u32 ReadCommandButtons(const std::string& line) const;
std::string WriteCommandButtons(u32 data) const; std::string WriteCommandButtons(u32 data) const;
@ -106,7 +107,6 @@ private:
size_t script_length{0}; size_t script_length{0};
std::array<TasData, PLAYER_NUMBER> tas_data; std::array<TasData, PLAYER_NUMBER> tas_data;
bool refresh_tas_fle{false};
bool is_recording{false}; bool is_recording{false};
bool is_running{false}; bool is_running{false};
bool needs_reset{false}; bool needs_reset{false};

View file

@ -1027,7 +1027,16 @@ void GMainWindow::InitializeHotkeys() {
connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("TAS Reset"), this), connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("TAS Reset"), this),
&QShortcut::activated, this, [&] { input_subsystem->GetTas()->Reset(); }); &QShortcut::activated, this, [&] { input_subsystem->GetTas()->Reset(); });
connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("TAS Record"), this), connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("TAS Record"), this),
&QShortcut::activated, this, [&] { input_subsystem->GetTas()->Record(); }); &QShortcut::activated, this, [&] {
bool is_recording = input_subsystem->GetTas()->Record();
if (!is_recording) {
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, tr("TAS Recording"),
tr("Overwrite file of player 1?"),
QMessageBox::Yes | QMessageBox::No);
input_subsystem->GetTas()->SaveRecording(reply == QMessageBox::Yes);
}
});
} }
void GMainWindow::SetDefaultUIGeometry() { void GMainWindow::SetDefaultUIGeometry() {