From: Mikko Rasa Date: Wed, 2 Nov 2022 22:19:21 +0000 (+0200) Subject: Recursively add subdirectories of the data directory to resources X-Git-Url: http://git.tdb.fi/?p=libs%2Fgame.git;a=commitdiff_plain;h=9dcf96c82741e2e1d02e2fbc6f6e465e51ac9690 Recursively add subdirectories of the data directory to resources --- diff --git a/source/game/resources.cpp b/source/game/resources.cpp index 0893f97..2b186de 100644 --- a/source/game/resources.cpp +++ b/source/game/resources.cpp @@ -12,7 +12,7 @@ ApplicationResources::ApplicationResources() FS::Path data_dir = FS::get_sys_data_dir()/"data"; #ifdef DEBUG if(FS::exists(data_dir)) - dir_src.add_directory(data_dir); + add_dir(data_dir); add_source(dir_src); #endif @@ -27,4 +27,15 @@ ApplicationResources::ApplicationResources() add_source(pack_src); } +void ApplicationResources::add_dir(const FS::Path &path) +{ + dir_src.add_directory(path); + for(const string &f: FS::list_files(path)) + { + FS::Path p = path/f; + if(FS::is_dir(p)) + add_dir(p); + } +} + } // namespace Msp::Game diff --git a/source/game/resources.h b/source/game/resources.h index b8f10b0..c5b8372 100644 --- a/source/game/resources.h +++ b/source/game/resources.h @@ -4,6 +4,7 @@ #include #include #include +#include namespace Msp::Game { @@ -20,6 +21,9 @@ private: public: ApplicationResources(); + +private: + void add_dir(const FS::Path &); }; } // namespace Msp::Game