|
17 | 17 |
|
18 | 18 | #include "addon/addon.hpp"
|
19 | 19 |
|
| 20 | +#include <boost/optional.hpp> |
| 21 | +#include <fmt/format.h> |
20 | 22 | #include <sstream>
|
21 | 23 |
|
| 24 | +#include "util/gettext.hpp" |
22 | 25 | #include "util/reader.hpp"
|
23 | 26 | #include "util/reader_document.hpp"
|
| 27 | +#include "util/reader_collection.hpp" |
24 | 28 | #include "util/reader_mapping.hpp"
|
25 | 29 |
|
26 |
| -namespace { |
27 |
| - |
28 | 30 | static const char* s_allowed_characters = "-_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
29 | 31 |
|
| 32 | +namespace addon_string_util { |
| 33 | + |
30 | 34 | Addon::Type addon_type_from_string(const std::string& type)
|
31 | 35 | {
|
32 | 36 | if (type == "world")
|
@@ -55,7 +59,50 @@ Addon::Type addon_type_from_string(const std::string& type)
|
55 | 59 | }
|
56 | 60 | }
|
57 | 61 |
|
58 |
| -} // namespace |
| 62 | +std::string addon_type_to_translated_string(Addon::Type type) |
| 63 | +{ |
| 64 | + switch (type) |
| 65 | + { |
| 66 | + case Addon::LEVELSET: |
| 67 | + return _("Levelset"); |
| 68 | + |
| 69 | + case Addon::WORLDMAP: |
| 70 | + return _("Worldmap"); |
| 71 | + |
| 72 | + case Addon::WORLD: |
| 73 | + return _("World"); |
| 74 | + |
| 75 | + case Addon::ADDON: |
| 76 | + return _("Add-on"); |
| 77 | + |
| 78 | + case Addon::LANGUAGEPACK: |
| 79 | + return _("Language Pack"); |
| 80 | + |
| 81 | + default: |
| 82 | + return _("Unknown"); |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +std::string generate_menu_item_text(const Addon& addon) |
| 87 | +{ |
| 88 | + std::string text; |
| 89 | + std::string type = addon_type_to_translated_string(addon.get_type()); |
| 90 | + |
| 91 | + if (!addon.get_author().empty()) |
| 92 | + { |
| 93 | + text = fmt::format(fmt::runtime(_("{} \"{}\" by \"{}\"")), |
| 94 | + type, addon.get_title(), addon.get_author()); |
| 95 | + } |
| 96 | + else |
| 97 | + { |
| 98 | + // Only addon type and name, no need for translation. |
| 99 | + text = fmt::format("{} \"{}\"", type, addon.get_title()); |
| 100 | + } |
| 101 | + |
| 102 | + return text; |
| 103 | +} |
| 104 | + |
| 105 | +} // namespace addon_string_util |
59 | 106 |
|
60 | 107 | std::unique_ptr<Addon>
|
61 | 108 | Addon::parse(const ReaderMapping& mapping)
|
@@ -83,14 +130,26 @@ Addon::parse(const ReaderMapping& mapping)
|
83 | 130 |
|
84 | 131 | std::string type;
|
85 | 132 | mapping.get("type", type);
|
86 |
| - addon->m_type = addon_type_from_string(type); |
| 133 | + addon->m_type = addon_string_util::addon_type_from_string(type); |
87 | 134 |
|
88 | 135 | mapping.get("title", addon->m_title);
|
89 | 136 | mapping.get("author", addon->m_author);
|
90 | 137 | mapping.get("license", addon->m_license);
|
| 138 | + mapping.get("description", addon->m_description); |
91 | 139 | mapping.get("url", addon->m_url);
|
92 | 140 | mapping.get("md5", addon->m_md5);
|
93 | 141 | mapping.get("format", addon->m_format);
|
| 142 | + boost::optional<ReaderCollection> reader; |
| 143 | + if (mapping.get("screenshots", reader)) |
| 144 | + { |
| 145 | + for (auto& obj : reader->get_objects()) |
| 146 | + { |
| 147 | + std::string url; |
| 148 | + auto data = obj.get_mapping(); |
| 149 | + data.get("url", url); |
| 150 | + addon->m_screenshots.push_back(url); |
| 151 | + } |
| 152 | + } |
94 | 153 |
|
95 | 154 | return addon;
|
96 | 155 | }
|
@@ -135,8 +194,10 @@ Addon::Addon() :
|
135 | 194 | m_author(),
|
136 | 195 | m_license(),
|
137 | 196 | m_format(0),
|
| 197 | + m_description(), |
138 | 198 | m_url(),
|
139 | 199 | m_md5(),
|
| 200 | + m_screenshots(), |
140 | 201 | m_install_filename(),
|
141 | 202 | m_enabled(false)
|
142 | 203 | {}
|
@@ -165,6 +226,12 @@ Addon::is_enabled() const
|
165 | 226 | return m_enabled;
|
166 | 227 | }
|
167 | 228 |
|
| 229 | +bool |
| 230 | +Addon::is_visible() const |
| 231 | +{ |
| 232 | + return true; |
| 233 | +} |
| 234 | + |
168 | 235 | void
|
169 | 236 | Addon::set_install_filename(const std::string& absolute_filename, const std::string& md5)
|
170 | 237 | {
|
|
0 commit comments