Minetest  5.4.0
subgames.h
Go to the documentation of this file.
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 <vector>
25 
26 class Settings;
27 
29 {
30  std::string id;
31  std::string name;
32  std::string author;
33  int release;
34  std::string path;
35  std::string gamemods_path;
36  std::set<std::string> addon_mods_paths;
37  std::string menuicon_path;
38 
39  SubgameSpec(const std::string &id = "", const std::string &path = "",
40  const std::string &gamemods_path = "",
41  const std::set<std::string> &addon_mods_paths =
42  std::set<std::string>(),
43  const std::string &name = "",
44  const std::string &menuicon_path = "",
45  const std::string &author = "", int release = 0) :
46  id(id),
50  {
51  }
52 
53  bool isValid() const { return (!id.empty() && !path.empty()); }
54 };
55 
56 SubgameSpec findSubgame(const std::string &id);
57 SubgameSpec findWorldSubgame(const std::string &world_path);
58 
59 std::set<std::string> getAvailableGameIds();
60 std::vector<SubgameSpec> getAvailableGames();
61 
62 bool getWorldExists(const std::string &world_path);
64 std::string getWorldName(const std::string &world_path, const std::string &default_name);
65 std::string getWorldGameId(const std::string &world_path, bool can_be_legacy = false);
66 
67 struct WorldSpec
68 {
69  std::string path;
70  std::string name;
71  std::string gameid;
72 
73  WorldSpec(const std::string &path = "", const std::string &name = "",
74  const std::string &gameid = "") :
75  path(path),
77  {
78  }
79 
80  bool isValid() const
81  {
82  return (!name.empty() && !path.empty() && !gameid.empty());
83  }
84 };
85 
86 std::vector<WorldSpec> getAvailableWorlds();
87 
88 // loads the subgame's config and creates world directory
89 // and world.mt if they don't exist
90 void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
91  const SubgameSpec &gamespec, bool create_world);
Definition: settings.h:101
Definition: subgames.h:29
std::set< std::string > addon_mods_paths
Definition: subgames.h:36
std::string gamemods_path
Definition: subgames.h:35
SubgameSpec(const std::string &id="", const std::string &path="", const std::string &gamemods_path="", const std::set< std::string > &addon_mods_paths=std::set< std::string >(), const std::string &name="", const std::string &menuicon_path="", const std::string &author="", int release=0)
Definition: subgames.h:39
std::string name
Definition: subgames.h:31
std::string menuicon_path
Definition: subgames.h:37
std::string author
Definition: subgames.h:32
bool isValid() const
Definition: subgames.h:53
std::string id
Definition: subgames.h:30
int release
Definition: subgames.h:33
std::string path
Definition: subgames.h:34
Definition: subgames.h:68
bool isValid() const
Definition: subgames.h:80
WorldSpec(const std::string &path="", const std::string &name="", const std::string &gameid="")
Definition: subgames.h:73
std::string gameid
Definition: subgames.h:71
std::string path
Definition: subgames.h:69
std::string name
Definition: subgames.h:70
std::set< std::string > getAvailableGameIds()
Definition: subgames.cpp:169
std::vector< WorldSpec > getAvailableWorlds()
Definition: subgames.cpp:266
std::string getWorldGameId(const std::string &world_path, bool can_be_legacy=false)
Definition: subgames.cpp:239
SubgameSpec findWorldSubgame(const std::string &world_path)
Definition: subgames.cpp:144
SubgameSpec findSubgame(const std::string &id)
Definition: subgames.cpp:64
std::string getWorldName(const std::string &world_path, const std::string &default_name)
Try to get the displayed name of a world.
Definition: subgames.cpp:225
std::vector< SubgameSpec > getAvailableGames()
Definition: subgames.cpp:206
void loadGameConfAndInitWorld(const std::string &path, const std::string &name, const SubgameSpec &gamespec, bool create_world)
Definition: subgames.cpp:314
bool getWorldExists(const std::string &world_path)
Definition: subgames.cpp:218