Adonthell  0.4
game.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 1999/2000/2001 Kai Sterker <kai.sterker@gmail.com>
3  Copyright (C) 2002 Alexandre Courbot <alexandrecourbot@linuxgames.com>
4  Part of the Adonthell Project <http://adonthell.nongnu.org>
5 
6  Adonthell is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  Adonthell is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 
21 /**
22  * @file game.h
23  * @author Kai Sterker <kai.sterker@gmail.com>
24  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
25  *
26  * @brief Declares the game class.
27  *
28  *
29  */
30 
31 
32 
33 #ifndef GAME_H__
34 #define GAME_H__
35 
36 
37 #include <string>
38 #include "types.h"
39 
40 #ifndef SWIG
41 using std::string;
42 #endif
43 
44 typedef enum { CONFIG, USER_DATA } sys_dir_type;
45 
46 /**
47  * Holds information about global settings.
48  *
49  * This static class should be the first to be initialised in your application,
50  * because many others depends on it's correct settings.
51  *
52  */
53 class game
54 {
55 public:
56  static string User_data_dir;
57  static string Global_data_dir;
58  static string Game_data_dir;
59 
60  /**
61  * Initialise the game framework.
62  *
63  * @param game_dir Global data directory.
64  */
65  static void init (string game_dir);
66 
67  /**
68  * Specify an additional data directory containing game data.
69  *
70  * @param game_dir Game data directory.
71  */
72  static void set_game_data_dir (string game_dir);
73 
74  /**
75  * Returns the absolute path to the user data directory (usually ~/.adonthell).
76  *
77  *
78  * @return user data directory
79  */
80  static string user_data_dir ()
81  {
82  return User_data_dir;
83  }
84 
85  /**
86  * Returns the absolute path to the global data directory.
87  *
88  *
89  * @return global data directory
90  */
91  static string global_data_dir ()
92  {
93  return Global_data_dir;
94  }
95 
96  /**
97  * Returns the absolute path to the current game's directory (if any).
98  *
99  *
100  * @return current game data directory, or empty string if none set.
101  */
102  static string game_data_dir ()
103  {
104  return Game_data_dir;
105  }
106 
107  /**
108  * Finds a file in the directories hierarchy, starting searching from
109  * game_data_dir(), then global_data_dir() and finally user_data_dir().
110  *
111  * If a matching file is found, the full absolute path is returned, else
112  * an empty string "" is returned. If the path was already absolute, it is
113  * returned immediatly.
114  *
115  * @param fname name of the find to search for.
116  *
117  * @return complete absolute path to the file if found, passed string if the given
118  * path was already absolute, or "" if the file wasn't found.
119  */
120  static string find_file (const string & fname);
121 
122  /**
123  * Finds a directory in the directories hierarchy, starting searching from
124  * game_data_dir(), then global_data_dir() and finally user_data_dir().
125  *
126  * If a matching directory is found, the full absolute path is returned, else
127  * an empty string "" is returned. If the path was already absolute, it is
128  * returned immediatly.
129  *
130  * @param fname name of the find to search for.
131  *
132  * @return complete absolute path to the directory if found, passed string if the given
133  * path was already absolute, or "" if the directory wasn't found.
134  */
135  static string find_directory (const string & dirname);
136 
137 #ifndef SWIG
138  /**
139  * Return the OS-specific directory of the given type. If the directory does
140  * not yet exist, it is also created.
141  *
142  * @param type Either CONFIG or USER_DATA
143  *
144  * @return appropriate system directory for the current user.
145  */
146  static string get_system_dir(const sys_dir_type & type);
147 
148 private:
149  static bool directory_exist (const string & dirname);
150  static bool file_exist (const string & fname);
151 #endif
152 };
153 
154 
155 #endif // GAME_H__
types.h
Declares some basic types.
game
Holds information about global settings.
Definition: game.h:53
game::user_data_dir
static string user_data_dir()
Returns the absolute path to the user data directory (usually ~/.adonthell).
Definition: game.h:80
game::set_game_data_dir
static void set_game_data_dir(string game_dir)
Specify an additional data directory containing game data.
Definition: game.cc:53
game::find_directory
static string find_directory(const string &dirname)
Finds a directory in the directories hierarchy, starting searching from game_data_dir(),...
Definition: game.cc:152
game::init
static void init(string game_dir)
Initialise the game framework.
Definition: game.cc:45
game::find_file
static string find_file(const string &fname)
Finds a file in the directories hierarchy, starting searching from game_data_dir(),...
Definition: game.cc:130
game::get_system_dir
static string get_system_dir(const sys_dir_type &type)
Return the OS-specific directory of the given type.
Definition: game.cc:58
game::game_data_dir
static string game_data_dir()
Returns the absolute path to the current game's directory (if any).
Definition: game.h:102
game::global_data_dir
static string global_data_dir()
Returns the absolute path to the global data directory.
Definition: game.h:91