From 9d10431da7ca2c7d82922ef495f06870f2708d02 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Thu, 11 Mar 2021 09:57:41 -0600 Subject: [PATCH] store a position in area config and sort areas numerically --- bin/config_sample/areas.ini | 4 ++-- src/server.cpp | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bin/config_sample/areas.ini b/bin/config_sample/areas.ini index 14f79ca..632bb2f 100644 --- a/bin/config_sample/areas.ini +++ b/bin/config_sample/areas.ini @@ -1,5 +1,5 @@ -[Basement] +[0:Basement] background=gs4 -[Courtroom 1] +[1:Courtroom 1] background=gs4 diff --git a/src/server.cpp b/src/server.cpp index b9acff4..2f3a17d 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -79,7 +79,16 @@ void Server::start() bg_file.close(); QSettings areas_ini("config/areas.ini", QSettings::IniFormat); - area_names = areas_ini.childGroups(); + area_names = areas_ini.childGroups(); // invisibly does a lexicographical sort, because Qt is great like that + std::sort(area_names.begin(), area_names.end(), [] (const QString &a, const QString &b) {return a.split(":")[0].toInt() < b.split(":")[0].toInt();}); + QStringList sanitized_area_names; + for (QString area_name : area_names) { + QStringList name_split = area_name.split(":"); + name_split.removeFirst(); + QString area_name_sanitized = name_split.join(":"); + sanitized_area_names.append(area_name_sanitized); + } + area_names = sanitized_area_names; for (int i = 0; i < area_names.length(); i++) { QString area_name = area_names[i]; areas.insert(i, new AreaData(characters, area_name, i));