]> git.lizzy.rs Git - dragonfireclient.git/blob - src/content/subgames.h
Deprecate game.conf name, use title instead (#12030)
[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 title;
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         // For logging purposes
45         std::vector<const char *> deprecation_msgs;
46
47         SubgameSpec(const std::string &id = "", const std::string &path = "",
48                         const std::string &gamemods_path = "",
49                         const std::unordered_map<std::string, std::string> &addon_mods_paths = {},
50                         const std::string &title = "",
51                         const std::string &menuicon_path = "",
52                         const std::string &author = "", int release = 0) :
53                         id(id),
54                         title(title), author(author), release(release), path(path),
55                         gamemods_path(gamemods_path), addon_mods_paths(addon_mods_paths),
56                         menuicon_path(menuicon_path)
57         {
58         }
59
60         bool isValid() const { return (!id.empty() && !path.empty()); }
61         void checkAndLog() const;
62 };
63
64 SubgameSpec findSubgame(const std::string &id);
65 SubgameSpec findWorldSubgame(const std::string &world_path);
66
67 std::set<std::string> getAvailableGameIds();
68 std::vector<SubgameSpec> getAvailableGames();
69 // Get the list of paths to mods in the environment variable $MINETEST_MOD_PATH
70 std::vector<std::string> getEnvModPaths();
71
72 bool getWorldExists(const std::string &world_path);
73 //! Try to get the displayed name of a world
74 std::string getWorldName(const std::string &world_path, const std::string &default_name);
75 std::string getWorldGameId(const std::string &world_path, bool can_be_legacy = false);
76
77 struct WorldSpec
78 {
79         std::string path;
80         std::string name;
81         std::string gameid;
82
83         WorldSpec(const std::string &path = "", const std::string &name = "",
84                         const std::string &gameid = "") :
85                         path(path),
86                         name(name), gameid(gameid)
87         {
88         }
89
90         bool isValid() const
91         {
92                 return (!name.empty() && !path.empty() && !gameid.empty());
93         }
94 };
95
96 std::vector<WorldSpec> getAvailableWorlds();
97
98 // loads the subgame's config and creates world directory
99 // and world.mt if they don't exist
100 void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
101                 const SubgameSpec &gamespec, bool create_world);