1 /* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
22 #include "scriptinterface/ScriptForward.h"
26 #define g_Mods (Mod::Instance())
32 // Singleton-like interface.
33 static Mod
& Instance();
36 * Parsed mod.json data for C++ usage.
37 * Note that converting to/from JS is lossy.
41 // 'Folder name' of the mod, e.g. 'public' for the main 0 A.D. mod.
43 // "name" property in the mod.json
47 std::vector
<CStr
> m_Dependencies
;
48 // If true, the mod is assumed to be 'GUI-only', i.e. ignored for MP or replay compatibility checks.
49 bool m_IgnoreInCompatibilityChecks
;
51 // For convenience when exporting to JS, keep a record of the full file.
55 const std::vector
<CStr
>& GetEnabledMods() const;
56 const std::vector
<CStr
>& GetIncompatibleMods() const;
57 const std::vector
<ModData
>& GetAvailableMods() const;
60 * Fetches available mods and stores some metadata about them.
61 * This may open the zipped mod archives, depending on the situation,
62 * and/or try to write files to the user mod folder,
63 * which can be quite slow, so should be run rarely.
64 * TODO: if this did not need the scriptInterface to parse JSON,
65 * we could run it in different contexts and possibly cleaner.
67 void UpdateAvailableMods(const ScriptInterface
& scriptInterface
);
70 * Enables specified mods (& mods required by the engine).
71 * @param addPublic - if true, enable the public mod.
72 * @return whether the mods were enabled successfully. This can fail if e.g. mods are incompatible.
73 * If true, GetEnabledMods() should be non-empty, GetIncompatibleMods() empty. Otherwise, GetIncompatibleMods() is non-empty.
75 bool EnableMods(const std::vector
<CStr
>& mods
, const bool addPublic
);
78 * Get data for the given mod.
79 * @param the mod path name (e.g. 'public')
80 * @return the mod data or nullptr if unavailable.
81 * TODO: switch to std::optional or something related.
83 const ModData
* GetModData(const CStr
& mod
) const;
86 * Get a list of the enabled mod's data (intended for compatibility checks).
87 * "user" mod and "mod" mod are ignored as they are irrelevant for compatibility checks.
89 const std::vector
<const Mod::ModData
*> GetEnabledModsData() const;
92 * @return whether the two lists are compatible for replaying / MP play.
94 static bool AreModsPlayCompatible(const std::vector
<const Mod::ModData
*>& modsA
, const std::vector
<const Mod::ModData
*>& modsB
);
98 * Checks a list of @a mods and returns the incompatible mods, if any.
100 std::vector
<CStr
> CheckForIncompatibleMods(const std::vector
<CStr
>& mods
) const;
101 bool CompareVersionStrings(const CStr
& required
, const CStr
& op
, const CStr
& version
) const;
103 std::vector
<CStr
> m_EnabledMods
;
104 // Of the currently loaded mods, these are the incompatible with the engine and cannot be loaded.
105 std::vector
<CStr
> m_IncompatibleMods
;
107 std::vector
<ModData
> m_AvailableMods
;
110 #endif // INCLUDED_MOD