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"
33 class ModError : public std::exception
36 ModError(const std::string &s)
41 virtual ~ModError() throw()
43 virtual const char * what() const throw()
55 std::set<std::string> depends;
56 std::set<std::string> unsatisfied_depends;
60 std::map<std::string,ModSpec> modpack_content;
61 ModSpec(const std::string name_="", const std::string path_="",
62 const std::set<std::string> depends_=std::set<std::string>()):
66 unsatisfied_depends(depends_),
72 std::map<std::string,ModSpec> getModsInPath(std::string path);
74 // expands modpack contents, but does not replace them.
75 std::map<std::string, ModSpec> flattenModTree(std::map<std::string, ModSpec> mods);
77 // replaces modpack Modspecs with their content
78 std::vector<ModSpec> flattenMods(std::map<std::string,ModSpec> mods);
80 // removes Mods mentioned in exclude_mod_names
81 std::vector<ModSpec> filterMods(std::vector<ModSpec> mods,
82 std::set<std::string> exclude_mod_names);
84 // a ModConfiguration is a subset of installed mods, expected to have
85 // all dependencies fullfilled, so it can be used as a list of mods to
86 // load when the game starts.
87 class ModConfiguration
96 ModConfiguration(std::string worldpath);
98 // adds all mods in the given path. used for games, modpacks
99 // and world-specific mods (worldmods-folders)
100 void addModsInPath(std::string path)
102 addMods(flattenMods(getModsInPath(path)));
105 // adds all mods in the given path whose name does not appear
106 // in the exclude_mods set.
107 void addModsInPathFiltered(std::string path, std::set<std::string> exclude_mods);
109 // adds all mods in the set.
110 void addMods(std::vector<ModSpec> mods);
112 // checks if all dependencies are fullfilled.
115 return m_unsatisfied_mods.empty();
118 std::vector<ModSpec> getMods()
120 return m_sorted_mods;
123 std::list<ModSpec> getUnsatisfiedMods()
125 return m_unsatisfied_mods;
130 // mods with unmet dependencies. This is a list and not a
131 // vector because we want easy removal of elements at every
133 std::list<ModSpec> m_unsatisfied_mods;
135 // list of mods sorted such that they can be loaded in the
136 // given order with all dependencies being fullfilled. I.e.,
137 // every mod in this list has only dependencies on mods which
138 // appear earlier in the vector.
139 std::vector<ModSpec> m_sorted_mods;