supertux
addon.hpp
1 // SuperTux - Add-on
2 // Copyright (C) 2007 Christoph Sommer <christoph.sommer@2007.expires.deltadevelopment.de>
3 // 2014 Ingo Ruhnke <grumbel@gmail.com>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
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 General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef HEADER_SUPERTUX_ADDON_ADDON_HPP
19 #define HEADER_SUPERTUX_ADDON_ADDON_HPP
20 
21 #include <memory>
22 #include <vector>
23 #include <string>
24 
25 class ReaderMapping;
26 
27 class Addon final
28 {
29 public:
30  static std::unique_ptr<Addon> parse(const ReaderMapping& mapping);
31  static std::unique_ptr<Addon> parse(const std::string& fname);
32 
33  enum Type { WORLD, WORLDMAP, LEVELSET, LANGUAGEPACK, RESOURCEPACK, ADDON };
34 
35  enum Format {
36  ORIGINAL = 0,
37  WITH_MOUNTPOINT = 1
38  };
39 
40 private:
41  // fields provided by the addon.zip itself
42  std::string m_id;
43  int m_version;
44  Type m_type;
45  std::string m_title;
46  std::string m_author;
47  std::string m_license;
48  int m_format;
49 
50  // additional fields provided for addons from an addon repository
51  std::string m_description;
52  std::string m_url;
53  std::string m_md5;
54  std::vector<std::string> m_screenshots;
55  std::vector<std::string> m_dependencies;
56 
57  // fields filled by the AddonManager
58  std::string m_install_filename;
59  bool m_enabled;
60 
61 private:
62  Addon();
63 
64 public:
65  const std::string& get_id() const { return m_id; }
66  int get_version() const { return m_version; }
67  int get_format() const { return m_format; }
68 
69  Type get_type() const { return m_type; }
70  const std::string& get_title() const { return m_title; }
71  const std::string& get_author() const { return m_author; }
72  const std::string& get_license() const { return m_license; }
73 
74  const std::string& get_description() const { return m_description; }
75  const std::string& get_url() const { return m_url; }
76  const std::string& get_md5() const { return m_md5; }
77  const std::vector<std::string>& get_screenshots() const { return m_screenshots; }
78  const std::vector<std::string>& get_dependencies() const { return m_dependencies; }
79 
80  std::string get_filename() const;
81  const std::string& get_install_filename() const;
82 
83  bool is_installed() const;
84  bool is_enabled() const;
85  bool is_visible() const;
86 
87  bool is_levelset() const;
88  bool overrides_data() const;
89  bool requires_restart() const;
90 
91  void set_install_filename(const std::string& absolute_filename, const std::string& md5);
92  void set_enabled(bool v);
93 
94 private:
95  Addon(const Addon&) = delete;
96  Addon& operator=(const Addon&) = delete;
97 };
98 
99 namespace addon_string_util {
100  Addon::Type addon_type_from_string(const std::string& type);
101  std::string addon_type_to_translated_string(Addon::Type type);
102  std::string generate_menu_item_text(const Addon& addon);
103  std::string get_addon_plural_form(size_t count);
104 }
105 
106 #endif
107 
108 /* EOF */
Definition: addon.cpp:32
Definition: addon.hpp:27
Definition: reader_mapping.hpp:32