DolphinQt: Allow $ line when entering AR/Gecko code

When you come across a cheat code in a place like the Dolphin
wiki, it's often posted like this:

$16:9 Widescreen
0441187C 3FE38E39

Sometimes users try to paste this in its entirety into the Code
field, which leads to Dolphin reporting an error on the first line.
I think it would be nice to make this a little smoother by having
Dolphin accept having a first line that starts with $.
This commit is contained in:
JosJuice 2021-08-10 19:19:34 +02:00
parent 67c06cfc55
commit cda442d2d8
1 changed files with 22 additions and 2 deletions

View File

@ -120,6 +120,8 @@ void CheatCodeEditor::ConnectWidgets()
bool CheatCodeEditor::AcceptAR() bool CheatCodeEditor::AcceptAR()
{ {
QString name = m_name_edit->text();
std::vector<ActionReplay::AREntry> entries; std::vector<ActionReplay::AREntry> entries;
std::vector<std::string> encrypted_lines; std::vector<std::string> encrypted_lines;
@ -132,6 +134,14 @@ bool CheatCodeEditor::AcceptAR()
if (line.isEmpty()) if (line.isEmpty())
continue; continue;
if (i == 0 && line[0] == u'$')
{
if (name.isEmpty())
name = line.right(line.size() - 1);
continue;
}
QStringList values = line.split(QLatin1Char{' '}); QStringList values = line.split(QLatin1Char{' '});
bool good = true; bool good = true;
@ -218,7 +228,7 @@ bool CheatCodeEditor::AcceptAR()
return false; return false;
} }
m_ar_code->name = m_name_edit->text().toStdString(); m_ar_code->name = name.toStdString();
m_ar_code->ops = std::move(entries); m_ar_code->ops = std::move(entries);
m_ar_code->user_defined = true; m_ar_code->user_defined = true;
@ -227,6 +237,8 @@ bool CheatCodeEditor::AcceptAR()
bool CheatCodeEditor::AcceptGecko() bool CheatCodeEditor::AcceptGecko()
{ {
QString name = m_name_edit->text();
std::vector<Gecko::GeckoCode::Code> entries; std::vector<Gecko::GeckoCode::Code> entries;
QStringList lines = m_code_edit->toPlainText().split(QLatin1Char{'\n'}); QStringList lines = m_code_edit->toPlainText().split(QLatin1Char{'\n'});
@ -238,6 +250,14 @@ bool CheatCodeEditor::AcceptGecko()
if (line.isEmpty()) if (line.isEmpty())
continue; continue;
if (i == 0 && line[0] == u'$')
{
if (name.isEmpty())
name = line.right(line.size() - 1);
continue;
}
QStringList values = line.split(QLatin1Char{' '}); QStringList values = line.split(QLatin1Char{' '});
bool good = values.size() == 2; bool good = values.size() == 2;
@ -282,7 +302,7 @@ bool CheatCodeEditor::AcceptGecko()
return false; return false;
} }
m_gecko_code->name = m_name_edit->text().toStdString(); m_gecko_code->name = name.toStdString();
m_gecko_code->creator = m_creator_edit->text().toStdString(); m_gecko_code->creator = m_creator_edit->text().toStdString();
m_gecko_code->codes = std::move(entries); m_gecko_code->codes = std::move(entries);
m_gecko_code->user_defined = true; m_gecko_code->user_defined = true;