fix about and changelog on server mods (though server doesn't give the data yet)

This commit is contained in:
HJfod 2024-03-25 11:57:38 +02:00
parent bdd8698e54
commit 54b66868fb
3 changed files with 26 additions and 11 deletions

View file

@ -613,7 +613,7 @@ void ModPopup::loadTab(ModPopup::Tab tab) {
switch (tab) {
case Tab::Details: {
m_currentTabPage = MDTextArea::create(
m_source.getMetadata().getDetails().value_or("No description provided"),
m_source.getAbout().value_or("No description provided"),
size / mdScale
);
m_currentTabPage->setScale(mdScale);
@ -621,7 +621,7 @@ void ModPopup::loadTab(ModPopup::Tab tab) {
case Tab::Changelog: {
m_currentTabPage = MDTextArea::create(
m_source.getMetadata().getChangelog().value_or("No changelog provided"),
m_source.getChangelog().value_or("No changelog provided"),
size / mdScale
);
m_currentTabPage->setScale(mdScale);

View file

@ -15,6 +15,28 @@ ModMetadata ModSource::getMetadata() const {
}
}, m_value);
}
std::optional<std::string> ModSource::getAbout() const {
return std::visit(makeVisitor {
[](Mod* mod) {
return mod->getMetadata().getDetails();
},
[](server::ServerModMetadata const& metadata) {
// Versions should be guaranteed to have at least one item
return metadata.about;
}
}, m_value);
}
std::optional<std::string> ModSource::getChangelog() const {
return std::visit(makeVisitor {
[](Mod* mod) {
return mod->getMetadata().getChangelog();
},
[](server::ServerModMetadata const& metadata) {
// Versions should be guaranteed to have at least one item
return metadata.changelog;
}
}, m_value);
}
CCNode* ModSource::createModLogo() const {
return std::visit(makeVisitor {
[](Mod* mod) {

View file

@ -15,6 +15,8 @@ public:
ModSource(server::ServerModMetadata&& metadata);
ModMetadata getMetadata() const;
std::optional<std::string> getAbout() const;
std::optional<std::string> getChangelog() const;
CCNode* createModLogo() const;
bool wantsRestart() const;
@ -25,15 +27,6 @@ public:
Mod* asMod() const;
server::ServerModMetadata const* asServer() const;
/**
* Fetches the server info for this mod source. If the mod source already
* is the `ServerModMetadata` variant, then it just immediately resolves to
* that. Otherwise, it uses the mod ID to fetch the server info.
*
* In other words, this does NOT mean that the ModSource is converted to
* `ServerModMetadata` or that it only works for that, or that it's required
* for that
*/
server::ServerPromise<server::ServerModMetadata> fetchServerInfo() const;
server::ServerPromise<std::unordered_set<std::string>> fetchValidTags() const;
};