Add DLC filtering in DataManager.cpp and namegen.cpp
authorWuzzy <almikes@aol.com>
Fri, 21 Apr 2017 17:42:09 +0200
changeset 12300 ac57d564efce
parent 12299 0deabf747b8f
child 12301 62975c0a89c6
Add DLC filtering in DataManager.cpp and namegen.cpp
QTfrontend/util/DataManager.cpp
QTfrontend/util/DataManager.h
QTfrontend/util/namegen.cpp
QTfrontend/util/namegen.h
--- a/QTfrontend/util/DataManager.cpp	Thu Apr 20 11:22:29 2017 -0400
+++ b/QTfrontend/util/DataManager.cpp	Fri Apr 21 17:42:09 2017 +0200
@@ -31,6 +31,7 @@
 #include "hwconsts.h"
 #include "HWApplication.h"
 #include "sdlkeys.h"
+#include "physfs.h"
 
 #include "DataManager.h"
 
@@ -61,7 +62,8 @@
 QStringList DataManager::entryList(
     const QString & subDirectory,
     QDir::Filters filters,
-    const QStringList & nameFilters
+    const QStringList & nameFilters,
+    bool withDLC
 ) const
 {
     QDir tmpDir(QString("physfs://%1").arg(subDirectory));
@@ -69,9 +71,13 @@
 
     // sort case-insensitive
     QMap<QString, QString> sortedFileNames;
+    QString absolutePath = datadir->absolutePath().toLocal8Bit().data();
     foreach ( QString fn, result)
     {
-        sortedFileNames.insert(fn.toLower(), fn);
+        // Filter out DLC entries if desired
+        QString realDir = PHYSFS_getRealDir(QString(subDirectory + "/" + fn).toLocal8Bit().data());
+        if(withDLC || realDir == absolutePath)
+            sortedFileNames.insert(fn.toLower(), fn);
     }
     result = sortedFileNames.values();
 
--- a/QTfrontend/util/DataManager.h	Thu Apr 20 11:22:29 2017 -0400
+++ b/QTfrontend/util/DataManager.h	Fri Apr 21 17:42:09 2017 +0200
@@ -66,7 +66,8 @@
          */
         QStringList entryList(const QString & subDirectory,
                               QDir::Filters filters = QDir::NoFilter,
-                              const QStringList & nameFilters = QStringList("*")
+                              const QStringList & nameFilters = QStringList("*"),
+                              bool withDLC = true
                              ) const;
 
         /**
--- a/QTfrontend/util/namegen.cpp	Thu Apr 20 11:22:29 2017 -0400
+++ b/QTfrontend/util/namegen.cpp	Fri Apr 21 17:42:09 2017 +0200
@@ -40,24 +40,24 @@
         team.setName(newName);
 }
 
-void HWNamegen::teamRandomFlag(HWTeam & team)
+void HWNamegen::teamRandomFlag(HWTeam & team, bool withDLC)
 {
-    team.setFlag(getRandomFlag());
+    team.setFlag(getRandomFlag(withDLC));
 }
 
-void HWNamegen::teamRandomVoice(HWTeam & team)
+void HWNamegen::teamRandomVoice(HWTeam & team, bool withDLC)
 {
-    team.setVoicepack(getRandomVoice());
+    team.setVoicepack(getRandomVoice(withDLC));
 }
 
-void HWNamegen::teamRandomGrave(HWTeam & team)
+void HWNamegen::teamRandomGrave(HWTeam & team, bool withDLC)
 {
-    team.setGrave(getRandomGrave());
+    team.setGrave(getRandomGrave(withDLC));
 }
 
-void HWNamegen::teamRandomFort(HWTeam & team)
+void HWNamegen::teamRandomFort(HWTeam & team, bool withDLC)
 {
-    team.setFort(getRandomFort());
+    team.setFort(getRandomFort(withDLC));
 }
 
 void HWNamegen::teamRandomEverything(HWTeam & team, const RandomTeamMode mode)
@@ -280,7 +280,7 @@
         return QString();
 }
 
-QString HWNamegen::getRandomGrave()
+QString HWNamegen::getRandomGrave(bool withDLC)
 {
     QStringList Graves;
 
@@ -288,7 +288,8 @@
     Graves.append(DataManager::instance().entryList(
                       "Graphics/Graves",
                       QDir::Files,
-                      QStringList("*.png")
+                      QStringList("*.png"),
+                      withDLC
                   ).replaceInStrings(QRegExp("\\.png$"), "")
                  );
 
@@ -302,7 +303,7 @@
     return Graves[rand()%(Graves.size())];
 }
 
-QString HWNamegen::getRandomFlag()
+QString HWNamegen::getRandomFlag(bool withDLC)
 {
     QStringList Flags;
 
@@ -310,7 +311,8 @@
     Flags.append(DataManager::instance().entryList(
                       "Graphics/Flags",
                       QDir::Files,
-                      QStringList("*.png")
+                      QStringList("*.png"),
+                      withDLC
                   ).replaceInStrings(QRegExp("\\.png$"), "")
                  );
     //remove internal flags
@@ -327,7 +329,7 @@
     return Flags[rand()%(Flags.size())];
 }
 
-QString HWNamegen::getRandomFort()
+QString HWNamegen::getRandomFort(bool withDLC)
 {
     QStringList Forts;
 
@@ -335,7 +337,8 @@
     Forts.append(DataManager::instance().entryList(
                      "Forts",
                      QDir::Files,
-                     QStringList("*L.png")
+                     QStringList("*L.png"),
+                     withDLC
                  ).replaceInStrings(QRegExp("L\\.png$"), "")
                 );
 
@@ -349,7 +352,7 @@
     return Forts[rand()%(Forts.size())];
 }
 
-QString HWNamegen::getRandomVoice()
+QString HWNamegen::getRandomVoice(bool withDLC)
 {
     QStringList Voices;
 
@@ -357,7 +360,8 @@
     Voices.append(DataManager::instance().entryList(
                      "Sounds/voices",
                      QDir::Dirs | QDir::NoDotAndDotDot,
-                     QStringList("*")));
+                     QStringList("*"),
+                     withDLC));
 
     if(Voices.size()==0)
     {
--- a/QTfrontend/util/namegen.h	Thu Apr 20 11:22:29 2017 -0400
+++ b/QTfrontend/util/namegen.h	Fri Apr 21 17:42:09 2017 +0200
@@ -36,10 +36,10 @@
         };
 
         static void teamRandomTeamName(HWTeam & team);
-        static void teamRandomGrave(HWTeam & team);
-        static void teamRandomFort(HWTeam & team);
-        static void teamRandomFlag(HWTeam & team);
-        static void teamRandomVoice(HWTeam & team);
+        static void teamRandomGrave(HWTeam & team, bool withDLC = true);
+        static void teamRandomFort(HWTeam & team, bool withDLC = true);
+        static void teamRandomFlag(HWTeam & team, bool withDLC = true);
+        static void teamRandomVoice(HWTeam & team, bool withDLC = true);
         static void teamRandomHogName(HWTeam & team, const int HedgehogNumber);
         static void teamRandomEverything(HWTeam & team, const enum RandomTeamMode mode);
         static void teamRandomHats(HWTeam & team);
@@ -48,10 +48,10 @@
         HWNamegen();
 
         static QString getRandomTeamName(int kind);
-        static QString getRandomGrave();
-        static QString getRandomFort();
-        static QString getRandomFlag();
-        static QString getRandomVoice();
+        static QString getRandomGrave(bool withDLC = true);
+        static QString getRandomFort(bool withDLC = true);
+        static QString getRandomFlag(bool withDLC = true);
+        static QString getRandomVoice(bool withDLC = true);
 
         static QList<QStringList> TypesTeamnames;
         static QList<QStringList> TypesHatnames;