3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
23 #include "irrlichttypes.h"
29 #include <json/json.h>
30 #include "util/cpp11_container.h"
34 #define MODNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_"
41 UNORDERED_SET<std::string> depends;
42 UNORDERED_SET<std::string> optdepends;
43 UNORDERED_SET<std::string> unsatisfied_depends;
48 std::map<std::string,ModSpec> modpack_content;
49 ModSpec(const std::string &name_="", const std::string &path_=""):
54 unsatisfied_depends(),
55 part_of_modpack(false),
61 // Retrieves depends, optdepends, is_modpack and modpack_content
62 void parseModContents(ModSpec &mod);
64 std::map<std::string,ModSpec> getModsInPath(std::string path, bool part_of_modpack = false);
66 // replaces modpack Modspecs with their content
67 std::vector<ModSpec> flattenMods(std::map<std::string,ModSpec> mods);
69 // a ModConfiguration is a subset of installed mods, expected to have
70 // all dependencies fullfilled, so it can be used as a list of mods to
71 // load when the game starts.
72 class ModConfiguration
75 // checks if all dependencies are fullfilled.
76 bool isConsistent() const
78 return m_unsatisfied_mods.empty();
81 std::vector<ModSpec> getMods()
86 const std::vector<ModSpec> &getUnsatisfiedMods() const
88 return m_unsatisfied_mods;
91 void printUnsatisfiedModsError() const;
94 ModConfiguration(const std::string &worldpath);
95 // adds all mods in the given path. used for games, modpacks
96 // and world-specific mods (worldmods-folders)
97 void addModsInPath(const std::string &path);
99 // adds all mods in the set.
100 void addMods(const std::vector<ModSpec> &new_mods);
102 void addModsFormConfig(const std::string &settings_path, const std::set<std::string> &mods);
104 void checkConflictsAndDeps();
106 // move mods from m_unsatisfied_mods to m_sorted_mods
107 // in an order that satisfies dependencies
108 void resolveDependencies();
110 // mods with unmet dependencies. Before dependencies are resolved,
111 // this is where all mods are stored. Afterwards this contains
112 // only the ones with really unsatisfied dependencies.
113 std::vector<ModSpec> m_unsatisfied_mods;
115 // list of mods sorted such that they can be loaded in the
116 // given order with all dependencies being fullfilled. I.e.,
117 // every mod in this list has only dependencies on mods which
118 // appear earlier in the vector.
119 std::vector<ModSpec> m_sorted_mods;
121 // set of mod names for which an unresolved name conflict
122 // exists. A name conflict happens when two or more mods
123 // at the same level have the same name but different paths.
124 // Levels (mods in higher levels override mods in lower levels):
125 // 1. game mod in modpack; 2. game mod;
126 // 3. world mod in modpack; 4. world mod;
127 // 5. addon mod in modpack; 6. addon mod.
128 UNORDERED_SET<std::string> m_name_conflicts;
130 // Deleted default constructor
131 ModConfiguration() {}
135 class ServerModConfiguration: public ModConfiguration
138 ServerModConfiguration(const std::string &worldpath);
143 class ClientModConfiguration: public ModConfiguration
146 ClientModConfiguration(const std::string &path);
151 Json::Value getModstoreUrl(const std::string &url);
153 inline Json::Value getModstoreUrl(const std::string &url)
155 return Json::Value();
159 struct ModLicenseInfo {
161 std::string shortinfo;
165 struct ModAuthorInfo {
167 std::string username;
173 std::string basename;
174 ModAuthorInfo author;
179 struct ModStoreCategoryInfo {
184 struct ModStoreVersionEntry {
189 //ugly version number
193 struct ModStoreTitlePic {
196 std::string description;
200 struct ModStoreModDetails {
202 std::vector<ModStoreCategoryInfo> categories;
203 ModAuthorInfo author;
204 ModLicenseInfo license;
205 ModStoreTitlePic titlepic;
208 std::string basename;
209 std::string description;
210 std::string repository;
212 std::vector<std::string> depends;
213 std::vector<std::string> softdeps;
215 std::string download_url;
216 std::string screenshot_url;
217 std::vector<ModStoreVersionEntry> versions;
221 class ModMetadata: public Metadata
224 ModMetadata(const std::string &mod_name);
227 virtual void clear();
229 bool save(const std::string &root_path);
230 bool load(const std::string &root_path);
232 bool isModified() const { return m_modified; }
233 const std::string &getModName() const { return m_mod_name; }
235 virtual bool setString(const std::string &name, const std::string &var);
237 std::string m_mod_name;