Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
mods.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 "irrlichttypes.h"
8#include <list>
9#include <set>
10#include <vector>
11#include <string>
12#include <map>
13#include "json-forwards.h"
14#include <unordered_set>
15#include "util/basic_macros.h"
16#include "config.h"
17#include "metadata.h"
18#include "subgames.h"
19
21
22#define MODNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_"
23
24struct ModSpec
25{
26 std::string name;
27 std::string author;
28 std::string path;
29 std::string desc;
30 int release = 0;
31
32 // if normal mod:
33 std::unordered_set<std::string> depends;
34 std::unordered_set<std::string> optdepends;
35 std::unordered_set<std::string> unsatisfied_depends;
36
37 bool part_of_modpack = false;
38 bool is_modpack = false;
39
56 std::string virtual_path;
57
58 // For logging purposes
59 std::vector<const char *> deprecation_msgs;
60
61 // if modpack:
62 std::map<std::string, ModSpec> modpack_content;
63
65 {
66 }
67
68 ModSpec(const std::string &name, const std::string &path, bool part_of_modpack, const std::string &virtual_path) :
70 {
71 }
72
73 void checkAndLog() const;
74};
75
81bool parseModContents(ModSpec &mod);
82
91std::map<std::string, ModSpec> getModsInPath(const std::string &path,
92 const std::string &virtual_path, bool part_of_modpack = false);
93
94// replaces modpack Modspecs with their content
95std::vector<ModSpec> flattenMods(const std::map<std::string, ModSpec> &mods);
96
97
98class ModStorage : public IMetadata
99{
100public:
101 ModStorage() = delete;
102 ModStorage(const std::string &mod_name, ModStorageDatabase *database);
103 ~ModStorage() = default;
104
105 const std::string &getModName() const { return m_mod_name; }
106
107 void clear() override;
108
109 bool contains(const std::string &name) const override;
110
111 bool setString(const std::string &name, std::string_view var) override;
112
113 const StringMap &getStrings(StringMap *place) const override;
114
115 const std::vector<std::string> &getKeys(std::vector<std::string> *place) const override;
116
117protected:
118 const std::string *getStringRaw(const std::string &name,
119 std::string *place) const override;
120
121private:
122 std::string m_mod_name;
124};
Definition metadata.h:14
Definition database.h:74
Definition mods.h:99
const std::string * getStringRaw(const std::string &name, std::string *place) const override
Definition mods.cpp:238
ModStorage()=delete
bool contains(const std::string &name) const override
Definition mods.cpp:211
ModStorageDatabase * m_database
Definition mods.h:123
const std::string & getModName() const
Definition mods.h:105
const StringMap & getStrings(StringMap *place) const override
Definition mods.cpp:224
bool setString(const std::string &name, std::string_view var) override
Definition mods.cpp:216
std::string m_mod_name
Definition mods.h:122
~ModStorage()=default
void clear() override
Definition mods.cpp:206
const std::vector< std::string > & getKeys(std::vector< std::string > *place) const override
Definition mods.cpp:231
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:148
std::vector< ModSpec > flattenMods(const std::map< std::string, ModSpec > &mods)
Definition mods.cpp:182
bool parseModContents(ModSpec &mod)
Retrieves depends, optdepends, is_modpack and modpack_content.
Definition mods.cpp:57
std::unordered_map< std::string, std::string > StringMap
Definition string.h:65
Definition mods.h:25
std::string path
Definition mods.h:28
bool is_modpack
Definition mods.h:38
std::unordered_set< std::string > unsatisfied_depends
Definition mods.h:35
std::vector< const char * > deprecation_msgs
Definition mods.h:59
std::string desc
Definition mods.h:29
std::map< std::string, ModSpec > modpack_content
Definition mods.h:62
ModSpec()
Definition mods.h:64
int release
Definition mods.h:30
std::string virtual_path
A constructed canonical path to represent this mod's location.
Definition mods.h:56
ModSpec(const std::string &name, const std::string &path, bool part_of_modpack, const std::string &virtual_path)
Definition mods.h:68
void checkAndLog() const
Definition mods.cpp:19
std::string author
Definition mods.h:27
bool part_of_modpack
Definition mods.h:37
std::unordered_set< std::string > optdepends
Definition mods.h:34
std::string name
Definition mods.h:26
std::unordered_set< std::string > depends
Definition mods.h:33