Luanti 5.16.0-dev
Loading...
Searching...
No Matches
subgames.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include <string>
8#include <set>
9#include <unordered_map>
10#include <unordered_set>
11#include <vector>
12
13
15{
16 std::string id;
17 std::string title;
18 std::string author;
20 std::string first_mod; // "" <=> no mod
21 std::string last_mod; // "" <=> no mod
22 std::string path;
23 std::string gamemods_path;
24
28 std::unordered_map<std::string, std::string> addon_mods_paths;
29
36 std::unordered_set<std::string> aliases;
37
38 // For logging purposes
39 std::vector<const char *> deprecation_msgs;
40
41 SubgameSpec(const std::string &id = "", const std::string &path = "",
42 const std::string &gamemods_path = "",
43 const std::unordered_map<std::string, std::string> &addon_mods_paths = {},
44 const std::string &title = "",
45 const std::string &author = "", int release = 0,
46 const std::string &first_mod = "",
47 const std::string &last_mod = "",
48 const std::unordered_set<std::string> &aliases = {}) :
49 id(id),
53 path(path),
57 {
58 }
59
60 bool isValid() const { return (!id.empty() && !path.empty()); }
61 void checkAndLog() const;
62};
63
64SubgameSpec findSubgame(const std::string &id);
65SubgameSpec findWorldSubgame(const std::string &world_path);
66
67std::set<std::string> getAvailableGameIds();
68std::vector<SubgameSpec> getAvailableGames();
69// Get the list of paths to mods in the environment variable LUANTI_MOD_PATH
70std::vector<std::string> getEnvModPaths();
71
72bool getWorldExists(const std::string &world_path);
74std::string getWorldName(const std::string &world_path, const std::string &default_name);
75std::string getWorldGameId(const std::string &world_path, bool can_be_legacy = false);
76
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),
87 {
88 }
89
90 bool isValid() const
91 {
92 return (!name.empty() && !path.empty() && !gameid.empty());
93 }
94};
95
96std::vector<WorldSpec> getAvailableWorlds();
97
98// loads the subgame's config and creates world directory
99// and world.mt if they don't exist
100void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
101 const SubgameSpec &gamespec, bool create_world);
Definition subgames.h:15
std::string gamemods_path
Definition subgames.h:23
SubgameSpec(const std::string &id="", const std::string &path="", const std::string &gamemods_path="", const std::unordered_map< std::string, std::string > &addon_mods_paths={}, const std::string &title="", const std::string &author="", int release=0, const std::string &first_mod="", const std::string &last_mod="", const std::unordered_set< std::string > &aliases={})
Definition subgames.h:41
std::string title
Definition subgames.h:17
std::unordered_set< std::string > aliases
All worlds are marked with a specific gameid.
Definition subgames.h:36
std::string first_mod
Definition subgames.h:20
std::unordered_map< std::string, std::string > addon_mods_paths
Map from virtual path to mods path.
Definition subgames.h:28
void checkAndLog() const
Definition subgames.cpp:98
std::string author
Definition subgames.h:18
bool isValid() const
Definition subgames.h:60
std::string last_mod
Definition subgames.h:21
std::vector< const char * > deprecation_msgs
Definition subgames.h:39
std::string id
Definition subgames.h:16
int release
Definition subgames.h:19
std::string path
Definition subgames.h:22
bool isValid() const
Definition subgames.h:90
WorldSpec(const std::string &path="", const std::string &name="", const std::string &gameid="")
Definition subgames.h:83
std::string gameid
Definition subgames.h:81
std::string path
Definition subgames.h:79
std::string name
Definition subgames.h:80
std::vector< SubgameSpec > getAvailableGames()
Definition subgames.cpp:221
std::vector< WorldSpec > getAvailableWorlds()
Definition subgames.cpp:326
std::string getWorldGameId(const std::string &world_path, bool can_be_legacy=false)
Definition subgames.cpp:308
std::set< std::string > getAvailableGameIds()
Definition subgames.cpp:212
SubgameSpec findWorldSubgame(const std::string &world_path)
Definition subgames.cpp:274
SubgameSpec findSubgame(const std::string &id)
Definition subgames.cpp:232
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:294
void loadGameConfAndInitWorld(const std::string &path, const std::string &name, const SubgameSpec &gamespec, bool create_world)
Definition subgames.cpp:374
std::vector< std::string > getEnvModPaths()
Definition subgames.cpp:454
bool getWorldExists(const std::string &world_path)
Definition subgames.cpp:284