Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
mods.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include "irrlichttypes.h"
23#include <list>
24#include <set>
25#include <vector>
26#include <string>
27#include <map>
28#include "json-forwards.h"
29#include <unordered_set>
30#include "util/basic_macros.h"
31#include "config.h"
32#include "metadata.h"
33#include "subgames.h"
34
36
37#define MODNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_"
38
39struct ModSpec
40{
41 std::string name;
42 std::string author;
43 std::string path;
44 std::string desc;
45 int release = 0;
46
47 // if normal mod:
48 std::unordered_set<std::string> depends;
49 std::unordered_set<std::string> optdepends;
50 std::unordered_set<std::string> unsatisfied_depends;
51
52 bool part_of_modpack = false;
53 bool is_modpack = false;
54
71 std::string virtual_path;
72
73 // For logging purposes
74 std::vector<const char *> deprecation_msgs;
75
76 // if modpack:
77 std::map<std::string, ModSpec> modpack_content;
78
80 {
81 }
82
83 ModSpec(const std::string &name, const std::string &path, bool part_of_modpack, const std::string &virtual_path) :
85 {
86 }
87
88 void checkAndLog() const;
89};
90
96bool parseModContents(ModSpec &mod);
97
106std::map<std::string, ModSpec> getModsInPath(const std::string &path,
107 const std::string &virtual_path, bool part_of_modpack = false);
108
109// replaces modpack Modspecs with their content
110std::vector<ModSpec> flattenMods(const std::map<std::string, ModSpec> &mods);
111
112
113class ModStorage : public IMetadata
114{
115public:
116 ModStorage() = delete;
117 ModStorage(const std::string &mod_name, ModStorageDatabase *database);
118 ~ModStorage() = default;
119
120 const std::string &getModName() const { return m_mod_name; }
121
122 void clear() override;
123
124 bool contains(const std::string &name) const override;
125
126 bool setString(const std::string &name, std::string_view var) override;
127
128 const StringMap &getStrings(StringMap *place) const override;
129
130 const std::vector<std::string> &getKeys(std::vector<std::string> *place) const override;
131
132protected:
133 const std::string *getStringRaw(const std::string &name,
134 std::string *place) const override;
135
136private:
137 std::string m_mod_name;
139};
Definition: metadata.h:29
Definition: database.h:89
Definition: mods.h:114
const std::string * getStringRaw(const std::string &name, std::string *place) const override
Definition: mods.cpp:253
ModStorage()=delete
bool contains(const std::string &name) const override
Definition: mods.cpp:226
ModStorageDatabase * m_database
Definition: mods.h:138
const std::string & getModName() const
Definition: mods.h:120
const StringMap & getStrings(StringMap *place) const override
Definition: mods.cpp:239
bool setString(const std::string &name, std::string_view var) override
Definition: mods.cpp:231
std::string m_mod_name
Definition: mods.h:137
~ModStorage()=default
void clear() override
Definition: mods.cpp:221
const std::vector< std::string > & getKeys(std::vector< std::string > *place) const override
Definition: mods.cpp:246
std::map< std::string, ModSpec > getModsInPath(const std::string &path, const std::string &virtual_path, bool part_of_modpack=false)
Gets a list of all mods and modpacks in path.
Definition: mods.cpp:163
std::vector< ModSpec > flattenMods(const std::map< std::string, ModSpec > &mods)
Definition: mods.cpp:197
bool parseModContents(ModSpec &mod)
Retrieves depends, optdepends, is_modpack and modpack_content.
Definition: mods.cpp:72
std::unordered_map< std::string, std::string > StringMap
Definition: string.h:78
Definition: mods.h:40
std::string path
Definition: mods.h:43
bool is_modpack
Definition: mods.h:53
std::unordered_set< std::string > unsatisfied_depends
Definition: mods.h:50
std::vector< const char * > deprecation_msgs
Definition: mods.h:74
std::string desc
Definition: mods.h:44
std::map< std::string, ModSpec > modpack_content
Definition: mods.h:77
ModSpec()
Definition: mods.h:79
int release
Definition: mods.h:45
std::string virtual_path
A constructed canonical path to represent this mod's location.
Definition: mods.h:71
ModSpec(const std::string &name, const std::string &path, bool part_of_modpack, const std::string &virtual_path)
Definition: mods.h:83
void checkAndLog() const
Definition: mods.cpp:34
std::string author
Definition: mods.h:42
bool part_of_modpack
Definition: mods.h:52
std::unordered_set< std::string > optdepends
Definition: mods.h:49
std::string name
Definition: mods.h:41
std::unordered_set< std::string > depends
Definition: mods.h:48