mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
Show invalid mods on mod search (#1065)
Some checks are pending
Build Binaries / Build Windows (push) Waiting to run
Build Binaries / Build macOS (push) Waiting to run
Build Binaries / Build Android (64-bit) (push) Waiting to run
Build Binaries / Build Android (32-bit) (push) Waiting to run
Build Binaries / Publish (push) Blocked by required conditions
Some checks are pending
Build Binaries / Build Windows (push) Waiting to run
Build Binaries / Build macOS (push) Waiting to run
Build Binaries / Build Android (64-bit) (push) Waiting to run
Build Binaries / Build Android (32-bit) (push) Waiting to run
Build Binaries / Publish (push) Blocked by required conditions
* invalid server mod parsing * show message for invalid mod * show invalid on explicit search
This commit is contained in:
parent
f6ed9c8f70
commit
18cf751eb3
5 changed files with 68 additions and 24 deletions
|
@ -236,6 +236,8 @@ namespace geode {
|
|||
void setTags(std::unordered_set<std::string> const& value);
|
||||
void setNeedsEarlyLoad(bool const& value);
|
||||
void setIsAPI(bool const& value);
|
||||
void setGameVersion(std::string const& value);
|
||||
void setGeodeVersion(VersionInfo const& value);
|
||||
ModMetadataLinks& getLinksMut();
|
||||
#endif
|
||||
|
||||
|
|
|
@ -654,6 +654,12 @@ void ModMetadata::setNeedsEarlyLoad(bool const& value) {
|
|||
void ModMetadata::setIsAPI(bool const& value) {
|
||||
m_impl->m_isAPI = value;
|
||||
}
|
||||
void ModMetadata::setGameVersion(std::string const& value) {
|
||||
m_impl->m_gdVersion = value;
|
||||
}
|
||||
void ModMetadata::setGeodeVersion(VersionInfo const& value) {
|
||||
m_impl->m_geodeVersion = value;
|
||||
}
|
||||
ModMetadataLinks& ModMetadata::getLinksMut() {
|
||||
return m_impl->m_links;
|
||||
}
|
||||
|
|
|
@ -264,22 +264,17 @@ Result<ServerModVersion> ServerModVersion::parse(matjson::Value const& raw) {
|
|||
|
||||
auto res = ServerModVersion();
|
||||
|
||||
// Verify target Geode version
|
||||
auto version = root.needs("geode").template get<VersionInfo>();
|
||||
if (!semverCompare(Loader::get()->getVersion(), version)) {
|
||||
return Err(
|
||||
"Mod targets version {} but Geode is version {}",
|
||||
version, Loader::get()->getVersion()
|
||||
);
|
||||
}
|
||||
res.metadata.setGeodeVersion(root.needs("geode").template get<VersionInfo>());
|
||||
|
||||
// Verify target GD version
|
||||
auto gd = root.needs("gd").obj().needs(GEODE_PLATFORM_SHORT_IDENTIFIER).template get<std::string>();
|
||||
if (gd != GEODE_GD_VERSION_STR && gd != "*") {
|
||||
return Err(
|
||||
"Mod targets GD version {} but current is version {}",
|
||||
gd, GEODE_GD_VERSION_STR
|
||||
);
|
||||
auto gd_obj = root.needs("gd").obj();
|
||||
std::string gd = "0.000";
|
||||
if (gd_obj.has(GEODE_PLATFORM_SHORT_IDENTIFIER)) {
|
||||
gd = gd_obj.has(GEODE_PLATFORM_SHORT_IDENTIFIER).template get<std::string>();
|
||||
}
|
||||
|
||||
if (gd != "*") {
|
||||
res.metadata.setGameVersion(gd);
|
||||
}
|
||||
|
||||
// Get server info
|
||||
|
@ -571,14 +566,15 @@ ServerRequest<ServerModsList> server::getMods(ModsQuery const& query, bool useCa
|
|||
auto req = web::WebRequest();
|
||||
req.userAgent(getServerUserAgent());
|
||||
|
||||
// Always target current GD version and Loader version
|
||||
req.param("gd", GEODE_GD_VERSION_STR);
|
||||
req.param("geode", Loader::get()->getVersion().toNonVString());
|
||||
|
||||
// Add search params
|
||||
if (query.query) {
|
||||
req.param("query", *query.query);
|
||||
} else {
|
||||
// Target current GD version and Loader version when query is not set
|
||||
req.param("gd", GEODE_GD_VERSION_STR);
|
||||
req.param("geode", Loader::get()->getVersion().toNonVString());
|
||||
}
|
||||
|
||||
if (query.platforms.size()) {
|
||||
std::string plats = "";
|
||||
bool first = true;
|
||||
|
|
|
@ -134,12 +134,27 @@ bool ModItem::init(ModSource&& source) {
|
|||
m_viewMenu->setAnchorPoint({ 1.f, .5f });
|
||||
m_viewMenu->setScale(.55f);
|
||||
|
||||
ButtonSprite* spr;
|
||||
ButtonSprite* spr = nullptr;
|
||||
if (auto serverMod = m_source.asServer(); serverMod != nullptr) {
|
||||
auto version = serverMod->latestVersion();
|
||||
|
||||
auto geodeValid = Loader::get()->isModVersionSupported(version.getGeodeVersion());
|
||||
auto gameVersion = version.getGameVersion();
|
||||
auto gdValid = gameVersion == "*" || gameVersion == GEODE_STR(GEODE_GD_VERSION);
|
||||
|
||||
if (!geodeValid || !gdValid) {
|
||||
spr = createGeodeButton("NA", 50, false, true, GeodeButtonSprite::Default);
|
||||
}
|
||||
}
|
||||
|
||||
if (!spr) {
|
||||
if (Loader::get()->isModInstalled(m_source.getID())) {
|
||||
spr = createGeodeButton("View", 50, false, true);
|
||||
} else {
|
||||
spr = createGeodeButton("Get", 50, false, true, GeodeButtonSprite::Install);
|
||||
}
|
||||
}
|
||||
|
||||
auto viewBtn = CCMenuItemSpriteExtra::create(
|
||||
spr,
|
||||
this, menu_selector(ModItem::onView)
|
||||
|
@ -473,6 +488,25 @@ void ModItem::onView(CCObject*) {
|
|||
)->show();
|
||||
}
|
||||
|
||||
if (auto serverMod = m_source.asServer(); serverMod != nullptr) {
|
||||
auto version = serverMod->latestVersion();
|
||||
auto geodeVersion = version.getGeodeVersion();
|
||||
auto geodeValid = Loader::get()->isModVersionSupported(geodeVersion);
|
||||
|
||||
if (auto res = version.checkGameVersion(); !res) {
|
||||
FLAlertLayer::create(nullptr, "Unavailable", res.unwrapErr(), "Close", nullptr)->show();
|
||||
return;
|
||||
} else if (!geodeValid) {
|
||||
auto msg = fmt::format(
|
||||
"Geode {} is required to view this mod. You currently have {}.",
|
||||
geodeVersion.toVString(),
|
||||
Loader::get()->getVersion().toVString()
|
||||
);
|
||||
FLAlertLayer::create(nullptr, "Unavailable", msg, "Close", nullptr)->show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Always open up the popup for the installed mod page if that is possible
|
||||
ModPopup::create(m_source.convertForPopup())->show();
|
||||
}
|
||||
|
|
|
@ -80,7 +80,13 @@ ServerModListSource* ServerModListSource::get(ServerModListType type) {
|
|||
}
|
||||
|
||||
void ServerModListSource::setSearchQuery(std::string const& query) {
|
||||
m_query.query = query.size() ? std::optional(query) : std::nullopt;
|
||||
if (query.empty()) {
|
||||
m_query.query = std::nullopt;
|
||||
m_query.platforms = { GEODE_PLATFORM_TARGET };
|
||||
} else {
|
||||
m_query.query = std::optional(query);
|
||||
m_query.platforms = {};
|
||||
}
|
||||
}
|
||||
|
||||
std::unordered_set<std::string> ServerModListSource::getModTags() const {
|
||||
|
|
Loading…
Reference in a new issue