1 /* 2 * Plugins.h - a plugin manager 3 4 Copyright (C) 2009 and beyond by Gregory Smith 5 and the "Aleph One" developers. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 This license is contained in the file "COPYING", 18 which is included with this source code; it is available online at 19 http://www.gnu.org/licenses/gpl.html 20 21 */ 22 23 #ifndef PLUGINS_H 24 #define PLUGINS_H 25 26 #include "FileHandler.h" 27 #include <string> 28 #include <vector> 29 30 struct ScenarioInfo { 31 std::string name; 32 std::string scenario_id; 33 std::string version; 34 }; 35 struct ShapesPatch { 36 bool requires_opengl; 37 std::string path; 38 }; 39 40 struct Plugin { 41 DirectorySpecifier directory; 42 std::string name; 43 std::string description; 44 std::string version; 45 std::vector<std::string> mmls; 46 std::string hud_lua; 47 std::string solo_lua; 48 std::string stats_lua; 49 std::string theme; 50 std::string required_version; 51 std::vector<ShapesPatch> shapes_patches; 52 std::vector<ScenarioInfo> required_scenarios; 53 54 bool enabled; 55 bool overridden; 56 bool overridden_solo; 57 bool compatible() const; 58 bool allowed() const; 59 bool valid() const; 60 61 bool operator<(const Plugin& other) const { 62 return name < other.name; 63 } 64 }; 65 66 class Plugins { 67 friend class PluginLoader; 68 public: 69 static Plugins* instance(); 70 typedef std::vector<Plugin>::iterator iterator; 71 72 enum GameMode { kMode_Menu, kMode_Solo, kMode_Net }; 73 74 void enumerate(); invalidate()75 void invalidate() { m_validated = false; } set_mode(GameMode mode)76 void set_mode(GameMode mode) { m_mode = mode; } mode()77 GameMode mode() { return m_mode; } 78 void load_mml(); 79 80 void load_shapes_patches(bool opengl); 81 82 void disable(const std::string& path); 83 begin()84 iterator begin() { return m_plugins.begin(); } end()85 iterator end() { return m_plugins.end(); } 86 87 const Plugin* find_hud_lua(); 88 const Plugin* find_solo_lua(); 89 const Plugin* find_stats_lua(); 90 const Plugin* find_theme(); 91 private: Plugins()92 Plugins() { } add(Plugin plugin)93 void add(Plugin plugin) { m_plugins.push_back(plugin); } 94 void validate(); 95 96 std::vector<Plugin> m_plugins; 97 bool m_validated = false; 98 GameMode m_mode = kMode_Menu; 99 }; 100 101 102 #endif 103