Skip to content

Commit

Permalink
Start the new loadState
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro-Beirao committed May 31, 2024
1 parent 262339f commit 6000a0e
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ const QString DEFAULT_TOGGLE4ARG = "-solo-net";
const QString STYLE_TEXT_NORMAL = "border: 1px solid rgb(180, 180, 180); padding-left: 6px;height: 20px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); border-radius:3px";
const QString STYLE_TEXT_PLACEHOLDER = "border: 1px solid rgb(180, 180, 180); padding-left: 6px;height: 20px; color: rgb(150, 150, 150); background-color: rgb(255, 255, 255); border-radius:3px";

const QString STATE_HEADER = "dsdalauncherstatev1.4";

#endif // CONSTANTS_H
168 changes: 162 additions & 6 deletions src/states.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ void states::loadStateFromFile(QString filePath)
}
QTextStream stream(&file);

loadStateOld(stream);
QString header;
stream.readLineInto(&header);

if (header == "dsdalauncherstatev1.4") loadStateNew(stream);
else loadStateOld(stream);

file.close();
}
Expand All @@ -29,12 +33,11 @@ void states::loadStateFromString(QString string)

void states::loadStateOld(QTextStream &stream)
{
QString buffer;

MainWindow::pMainWindow->wads_listWidget()->clear();

while (!stream.atEnd())
{
QString buffer;
stream.readLineInto(&buffer);

QString buffer_name;
Expand Down Expand Up @@ -190,23 +193,176 @@ void states::loadStateOld(QTextStream &stream)
}
}

void states::loadStateNew(QTextStream &stream)
{
MainWindow::pMainWindow->wads_listWidget()->clear();

while (!stream.atEnd())
{
QString buffer;
stream.readLineInto(&buffer);

QString buffer_name;
QString buffer_value;

int pos = buffer.indexOf(' ');
buffer_name = buffer.mid(0, pos).trimmed();
buffer_value = buffer.mid(pos + 1).trimmed();

if (buffer_name == "iwad") // iwad
{
MainWindow::pMainWindow->iwad_comboBox()->setCurrentIndex(MainWindow::pMainWindow->iwad_comboBox()->findText(buffer_value));
}
else if (buffer_name == "complevel") // complevel
{
if (buffer_value.isEmpty()) continue;

int index = MainWindow::pMainWindow->complevel_comboBox()->findText(buffer_value);
if (index != -1)
{
MainWindow::pMainWindow->complevel_comboBox()->setCurrentIndex(index);
}
else
{
MainWindow::pMainWindow->complevel_comboBox()->addItem(buffer_value);
MainWindow::pMainWindow->complevel_comboBox()->setCurrentIndex(MainWindow::pMainWindow->complevel_comboBox()->count() - 1);
}
}
if (buffer_name == "warp1") // warp 1
{
MainWindow::pMainWindow->episode_lineEdit()->setText(buffer_value);
}
if (buffer_name == "warp2") // warp 2
{
MainWindow::pMainWindow->level_lineEdit()->setText(buffer_value);
}
if (buffer_name == "skill") // skill
{
if (buffer_value.length() > 0)
{
MainWindow::pMainWindow->difficulty_comboBox()->setCurrentIndex((buffer_value.toInt()));
}
else
{
MainWindow::pMainWindow->difficulty_comboBox()->setCurrentIndex(0);
}
}
if (buffer_name == "box1") // box1
{
if (buffer_value == "true") MainWindow::pMainWindow->toggle1_checkBox()->setChecked(true);
else MainWindow::pMainWindow->toggle1_checkBox()->setChecked(false);
}
if (buffer_name == "box2") // box2
{
if (buffer_value == "true") MainWindow::pMainWindow->toggle2_checkBox()->setChecked(true);
else MainWindow::pMainWindow->toggle2_checkBox()->setChecked(false);
}
if (buffer_name == "box3") // box3
{
if (buffer_value == "true") MainWindow::pMainWindow->toggle3_checkBox()->setChecked(true);
else MainWindow::pMainWindow->toggle3_checkBox()->setChecked(false);
}
if (buffer_name == "box4") // box4
{
if (buffer_value == "true") MainWindow::pMainWindow->toggle4_checkBox()->setChecked(true);
else MainWindow::pMainWindow->toggle4_checkBox()->setChecked(false);
}
if (buffer_name == "resolution") // resolution
{
MainWindow::pMainWindow->resolution_comboBox()->setCurrentIndex(MainWindow::pMainWindow->resolution_comboBox()->findText(buffer_value));
}
if (buffer_name == "fullscreen") // fullscreen
{
if (buffer_value == "true") MainWindow::pMainWindow->fullscreen_checkBox()->setChecked(true);
else MainWindow::pMainWindow->fullscreen_checkBox()->setChecked(false);
}
if (buffer_name == "hud") // hud
{
MainWindow::pMainWindow->hud_lineEdit()->setText(buffer_value);
}
if (buffer_name == "config") // config
{
MainWindow::pMainWindow->config_lineEdit()->setText(buffer_value);
}
if (buffer_name == "track") // track
{
if (buffer_value.length() > 0)
{
MainWindow::pMainWindow->track_comboBox()->setCurrentIndex(buffer_value.toInt());
}
else
{
MainWindow::pMainWindow->track_comboBox()->setCurrentIndex(0);
}
}
if (buffer_name == "time") // time
{
if (buffer_value.length() > 0)
{
MainWindow::pMainWindow->time_comboBox()->setCurrentIndex(buffer_value.toInt());
}
else
{
MainWindow::pMainWindow->time_comboBox()->setCurrentIndex(0);
}
}
/*if (buffer_name == "pwad")
{
while (stream.readLineInto(&buffer))
{
if (buffer.mid(0, 7) == "endpwad") break;
MainWindow::pMainWindow->wads_listWidget()->addItem(getFileName(buffer));
MainWindow::pMainWindow->wads_listWidget()->item(MainWindow::pMainWindow->wads_listWidget()->count() - 1)->setToolTip(buffer);
}
}*/
if (buffer_name == "record") // record demo
{
MainWindow::pMainWindow->record_lineEdit()->setText(buffer_value);
}
if (buffer_name == "playback") // playback demo
{
MainWindow::pMainWindow->playback_lineEdit()->setText(buffer_value);
}
if (buffer_name == "demodropdown") // demo drop down
{
if (buffer_value.length() > 0)
{
MainWindow::pMainWindow->playback_comboBox()->setCurrentIndex(buffer_value.toInt());
}
else
{
MainWindow::pMainWindow->playback_comboBox()->setCurrentIndex(0);
}
}
if (buffer_name == "viddump") // demo drop down
{
MainWindow::pMainWindow->viddump_lineEdit()->setText(buffer_value);
}
if (buffer_name == "additional") // additional arguments
{
MainWindow::pMainWindow->additionalArguments_textEdit()->setText(buffer_value);
}
}
}

QString bool_cast(bool b) { return b ? "true" : "false"; }

void states::saveStateToFile(QString filePath)
{
MainWindow *ui = MainWindow::pMainWindow;

QFile file(filePath);
if (!file.open(QFile::ReadWrite | QFile::Text))
if (!file.open(QFile::ReadWrite | QFile::Text | QFile::Truncate))
{
return;
}
QTextStream out(&file);

out << "version " + version + "\n\n";
out << STATE_HEADER + "\n\n";

out << "iwad " + ui->iwad_comboBox()->currentText() + "\n";
out << "complevel " + ui->complevel_comboBox()->currentText().mid(0, 2) + "\n";
out << "complevel " + ui->complevel_comboBox()->currentText() + "\n";
out << "warp1 " + ui->episode_lineEdit()->text() + "\n";
out << "warp2 " + ui->level_lineEdit()->text() + "\n";
out << "skill " + ui->difficulty_comboBox()->currentText() + "\n";
Expand Down
1 change: 1 addition & 0 deletions src/states.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class states : public QObject

private:
static void loadStateOld(QTextStream &stream);
static void loadStateNew(QTextStream &stream);

signals:
};
Expand Down

0 comments on commit 6000a0e

Please sign in to comment.