]> git.tdb.fi Git - libs/game.git/blob - source/game/resources.cpp
Load the various setups through resources
[libs/game.git] / source / game / resources.cpp
1 #include <msp/core/application.h>
2 #include <msp/fs/dir.h>
3 #include <msp/fs/stat.h>
4 #include "resources.h"
5 #include "setups.h"
6
7 using namespace std;
8
9 namespace Msp::Game {
10
11 Resources::Resources()
12 {
13         add_type<CameraSetup>().suffix(".camera.setup");
14 }
15
16
17 ApplicationResources::ApplicationResources()
18 {
19         FS::Path data_dir = FS::get_sys_data_dir()/"data";
20 #ifdef DEBUG
21         if(FS::exists(data_dir))
22                 add_dir(data_dir);
23         add_source(dir_src);
24 #endif
25
26         FS::Path main_pack = FS::get_sys_data_dir()/(Application::get_name()+".mdp");
27         if(FS::exists(main_pack))
28                 pack_src.add_pack_file(main_pack.str());
29         if(FS::exists(data_dir))
30         {
31                 for(const string &f: FS::list_filtered(data_dir, "\\.mdp$"))
32                         pack_src.add_pack_file((data_dir/f).str());
33         }
34         add_source(pack_src);
35 }
36
37 void ApplicationResources::add_dir(const FS::Path &path)
38 {
39         dir_src.add_directory(path);
40         for(const string &f: FS::list_files(path))
41         {
42                 FS::Path p = path/f;
43                 if(FS::is_dir(p))
44                         add_dir(p);
45         }
46 }
47
48 } // namespace Msp::Game