Skip to content

Commit 00437aa

Browse files
Refactored Maze::fromFile to filter lines starting with '[' or blank, added support for loading multiple files, and switched configuration storage to .ini files.
1 parent 8b553bc commit 00437aa

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

src/Maze.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,21 @@ Maze *Maze::fromFile(const QString &path) {
2626
lines.append(line);
2727
}
2828

29+
// Filters lines that start with '[' or are blank
30+
QVector<QString> filteredLines;
31+
for (const QString& l : lines) {
32+
QString trimmed = l.trimmed();
33+
if (trimmed.isEmpty() || trimmed.startsWith('['))
34+
continue;
35+
filteredLines.append(trimmed);
36+
}
37+
2938
// Try map format first, then num
30-
Maze *maze = fromMapFile(lines);
39+
Maze *maze = fromMapFile(filteredLines);
3140
if (maze != nullptr) {
3241
return maze;
3342
}
34-
return fromNumFile(lines);
43+
return fromNumFile(filteredLines);
3544
}
3645

3746
int Maze::getWidth() const { return m_tiles.size(); }

src/Settings.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ void Settings::update(QString group, QString key, QString value,
127127
}
128128

129129
Settings::Settings() {
130+
// Define the path for the .ini file in the same directory as the executable
131+
QString iniFilePath = QCoreApplication::applicationDirPath() + "/config.ini";
132+
133+
// Set QSettings to use the .ini file instead of the registry
134+
QSettings::setDefaultFormat(QSettings::IniFormat);
135+
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, iniFilePath);
136+
130137
QCoreApplication::setOrganizationName("mackorone");
131138
QCoreApplication::setOrganizationDomain("www.github.com/mackorone");
132139
QCoreApplication::setApplicationName("mms");

src/Window.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,25 @@ void Window::closeEvent(QCloseEvent *event) {
356356
}
357357

358358
void Window::onMazeFileButtonPressed() {
359-
QString path = QFileDialog::getOpenFileName(this, tr("Load Maze"));
360-
if (path.isNull()) {
361-
return;
359+
QStringList paths = QFileDialog::getOpenFileNames(this, tr("Load Mazes"));
360+
if (paths.isEmpty()) {
361+
return;
362362
}
363-
Maze *maze = Maze::fromFile(path);
364-
if (maze == nullptr) {
365-
showInvalidMazeFileWarning(path);
366-
return;
363+
QString validPath; // To remember the last valid one loaded
364+
for (const QString& path : paths) {
365+
Maze *maze = Maze::fromFile(path);
366+
if (maze == nullptr) {
367+
showInvalidMazeFileWarning(path);
368+
continue;
369+
}
370+
SettingsMazeFiles::addPath(path);
371+
validPath = path;
372+
}
373+
// Now refresh the combo and load the last valid one selected
374+
if (!validPath.isEmpty()) {
375+
refreshMazeFileComboBox(validPath);
376+
updateMazeAndPath(Maze::fromFile(validPath), validPath);
367377
}
368-
SettingsMazeFiles::addPath(path);
369-
refreshMazeFileComboBox(path);
370-
updateMazeAndPath(maze, path);
371378
}
372379

373380
void Window::onMazeFileComboBoxChanged(QString path) {

0 commit comments

Comments
 (0)