]> git.lizzy.rs Git - dragonfireclient.git/blob - src/content/subgames.h
d36b4952fde076fd490ed6dbb17ce4f066efea30
[dragonfireclient.git] / src / content / subgames.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include <string>
23 #include <set>
24 #include <unordered_map>
25 #include <vector>
26
27 class Settings;
28
29 struct SubgameSpec
30 {
31         std::string id;
32         std::string name;
33         std::string author;
34         int release;
35         std::string path;
36         std::string gamemods_path;
37
38         /**
39          * Map from virtual path to mods path
40          */
41         std::unordered_map<std::string, std::string> addon_mods_paths;
42         std::string menuicon_path;
43
44         SubgameSpec(const std::string &id = "", const std::string &path = "",
45                         const std::string &gamemods_path = "",
46                         const std::unordered_map<std::string, std::string> &addon_mods_paths = {},
47                         const std::string &name = "",
48                         const std::string &menuicon_path = "",
49                         const std::string &author = "", int release = 0) :
50                         id(id),
51                         name(name), author(author), release(release), path(path),
52                         gamemods_path(gamemods_path), addon_mods_paths(addon_mods_paths),
53                         menuicon_path(menuicon_path)
54         {
55         }
56
57         bool isValid() const { return (!id.empty() && !path.empty()); }
58 };
59
60 SubgameSpec findSubgame(const std::string &id);
61 SubgameSpec findWorldSubgame(const std::string &world_path);
62
63 std::set<std::string> getAvailableGameIds();
64 std::vector<SubgameSpec> getAvailableGames();
65 // Get the list of paths to mods in the environment variable $MINETEST_MOD_PATH
66 std::vector<std::string> getEnvModPaths();
67
68 bool getWorldExists(const std::string &world_path);
69 //! Try to get the displayed name of a world
70 std::string getWorldName(const std::string &world_path, const std::string &default_name);
71 std::string getWorldGameId(const std::string &world_path, bool can_be_legacy = false);
72
73 struct WorldSpec
74 {
75         std::string path;
76         std::string name;
77         std::string gameid;
78
79         WorldSpec(const std::string &path = "", const std::string &name = "",
80                         const std::string &gameid = "") :
81                         path(path),
82                         name(name), gameid(gameid)
83         {
84         }
85
86         bool isValid() const
87         {
88                 return (!name.empty() && !path.empty() && !gameid.empty());
89         }
90 };
91
92 std::vector<WorldSpec> getAvailableWorlds();
93
94 // loads the subgame's config and creates world directory
95 // and world.mt if they don't exist
96 void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
97                 const SubgameSpec &gamespec, bool create_world);