mirror of
https://gitlab.com/suyu-emu/suyu.git
synced 2024-03-15 23:15:44 +00:00
input_common: Handle errors on TAS scripts
This commit is contained in:
parent
a95c49e7d0
commit
ea089c012e
|
@ -105,11 +105,17 @@ void Tas::LoadTasFile(size_t player_index, size_t file_index) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const auto num_frames = std::stoi(seg_list[0]);
|
const auto num_frames = std::stoi(seg_list[0]);
|
||||||
while (frame_no < num_frames) {
|
while (frame_no < num_frames) {
|
||||||
commands[player_index].emplace_back();
|
commands[player_index].emplace_back();
|
||||||
frame_no++;
|
frame_no++;
|
||||||
}
|
}
|
||||||
|
} catch (const std::invalid_argument&) {
|
||||||
|
LOG_ERROR(Input, "Invalid argument: '{}' at command {}", seg_list[0], frame_no);
|
||||||
|
} catch (const std::out_of_range&) {
|
||||||
|
LOG_ERROR(Input, "Out of range: '{}' at command {}", seg_list[0], frame_no);
|
||||||
|
}
|
||||||
|
|
||||||
TASCommand command = {
|
TASCommand command = {
|
||||||
.buttons = ReadCommandButtons(seg_list[1]),
|
.buttons = ReadCommandButtons(seg_list[1]),
|
||||||
|
@ -233,10 +239,21 @@ TasAnalog Tas::ReadCommandAxis(const std::string& line) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (seg_list.size() < 2) {
|
||||||
|
LOG_ERROR(Input, "Invalid axis data: '{}'", line);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const float x = std::stof(seg_list.at(0)) / 32767.0f;
|
const float x = std::stof(seg_list.at(0)) / 32767.0f;
|
||||||
const float y = std::stof(seg_list.at(1)) / 32767.0f;
|
const float y = std::stof(seg_list.at(1)) / 32767.0f;
|
||||||
|
|
||||||
return {x, y};
|
return {x, y};
|
||||||
|
} catch (const std::invalid_argument&) {
|
||||||
|
LOG_ERROR(Input, "Invalid argument: '{}'", line);
|
||||||
|
} catch (const std::out_of_range&) {
|
||||||
|
LOG_ERROR(Input, "Out of range: '{}'", line);
|
||||||
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 Tas::ReadCommandButtons(const std::string& line) const {
|
u64 Tas::ReadCommandButtons(const std::string& line) const {
|
||||||
|
|
Loading…
Reference in a new issue