mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
Compare commits
7 commits
e472259c3a
...
61bf340664
Author | SHA1 | Date | |
---|---|---|---|
|
61bf340664 | ||
|
13b30e591a | ||
|
893b03e313 | ||
|
7c4e06d20c | ||
|
e881dc5ef2 | ||
|
4a40835f71 | ||
|
74d0924bcb |
29 changed files with 463 additions and 172 deletions
11
CHANGELOG.md
11
CHANGELOG.md
|
@ -1,5 +1,16 @@
|
|||
# Geode Changelog
|
||||
|
||||
## v4.0.0-alpha.2
|
||||
* Button to manually install mods from files (e881dc5)
|
||||
* Add `ModRequestedAction::Update` (e881dc5)
|
||||
* Add `ModMetadata::checkGeodeVersion` and `ModMetadata::checkTargetVersions` (e881dc5)
|
||||
* Add `geode::createModLogo` for creating a logo from a `.geode` package (e881dc5)
|
||||
* Tags now use names provided by the server (893b03e)
|
||||
* Fix `Task::chain` using the wrong type in the impl (22a11b9)
|
||||
* Fix installing mods not checking the current version (#1148)
|
||||
* Fix crash when checking tags (01807fe)
|
||||
* Fix 'Outdated' label being visible while updating (6679a69)
|
||||
|
||||
## v4.0.0-alpha.1
|
||||
* Support for the 2.2074 update
|
||||
* Developers, see [this page for a migration guide](https://docs.geode-sdk.org/tutorials/migrate-v4)
|
||||
|
|
|
@ -164,7 +164,27 @@ function(setup_geode_mod proname)
|
|||
set(HAS_HEADERS Off)
|
||||
endif()
|
||||
|
||||
if (HAS_HEADERS AND WIN32)
|
||||
if (GEODE_BUNDLE_PDB AND WIN32 AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
|
||||
if (HAS_HEADERS)
|
||||
add_custom_target(${proname}_PACKAGE ALL
|
||||
DEPENDS ${proname} ${CMAKE_CURRENT_SOURCE_DIR}/mod.json
|
||||
COMMAND ${GEODE_CLI} package new ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
--binary $<TARGET_FILE:${proname}> $<TARGET_LINKER_FILE:${proname}> $<TARGET_PDB_FILE:${proname}>
|
||||
--output ${CMAKE_CURRENT_BINARY_DIR}/${MOD_ID}.geode
|
||||
${INSTALL_ARG} ${PDB_ARG}
|
||||
VERBATIM USES_TERMINAL
|
||||
)
|
||||
else()
|
||||
add_custom_target(${proname}_PACKAGE ALL
|
||||
DEPENDS ${proname} ${CMAKE_CURRENT_SOURCE_DIR}/mod.json
|
||||
COMMAND ${GEODE_CLI} package new ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
--binary $<TARGET_FILE:${proname}> $<TARGET_PDB_FILE:${proname}>
|
||||
--output ${CMAKE_CURRENT_BINARY_DIR}/${MOD_ID}.geode
|
||||
${INSTALL_ARG} ${PDB_ARG}
|
||||
VERBATIM USES_TERMINAL
|
||||
)
|
||||
endif()
|
||||
elseif (HAS_HEADERS AND WIN32)
|
||||
# this adds the .lib file on windows, which is needed for linking with the headers
|
||||
add_custom_target(${proname}_PACKAGE ALL
|
||||
DEPENDS ${proname} ${CMAKE_CURRENT_SOURCE_DIR}/mod.json
|
||||
|
|
|
@ -41,7 +41,8 @@ namespace geode {
|
|||
Enable,
|
||||
Disable,
|
||||
Uninstall,
|
||||
UninstallWithSaveData
|
||||
UninstallWithSaveData,
|
||||
Update
|
||||
};
|
||||
|
||||
static constexpr bool modRequestedActionIsToggle(ModRequestedAction action) {
|
||||
|
|
|
@ -198,9 +198,19 @@ namespace geode {
|
|||
|
||||
/**
|
||||
* Checks if mod can be installed on the current GD version.
|
||||
* Returns Ok() if it can, Err otherwise.
|
||||
* Returns Ok() if it can, Err explaining why not otherwise.
|
||||
*/
|
||||
Result<> checkGameVersion() const;
|
||||
/**
|
||||
* Checks if mod can be installed on the current Geode version.
|
||||
* Returns Ok() if it can, Err explaining why not otherwise.
|
||||
*/
|
||||
Result<> checkGeodeVersion() const;
|
||||
/**
|
||||
* Checks if mod can be installed on the current GD & Geode version.
|
||||
* Returns Ok() if it can, Err explaining why not otherwise.
|
||||
*/
|
||||
Result<> checkTargetVersions() const;
|
||||
|
||||
#if defined(GEODE_EXPOSE_SECRET_INTERNALS_IN_HEADERS_DO_NOT_DEFINE_PLEASE)
|
||||
void setPath(std::filesystem::path const& value);
|
||||
|
|
|
@ -155,6 +155,10 @@ namespace geode {
|
|||
* Create a logo sprite for a mod
|
||||
*/
|
||||
GEODE_DLL cocos2d::CCNode* createModLogo(Mod* mod);
|
||||
/**
|
||||
* Create a logo sprite for a mod from a .geode file
|
||||
*/
|
||||
GEODE_DLL cocos2d::CCNode* createModLogo(std::filesystem::path const& geodePackage);
|
||||
/**
|
||||
* Create a logo sprite for a mod downloaded from the Geode servers. The
|
||||
* logo is initially a loading circle, with the actual sprite downloaded
|
||||
|
|
BIN
loader/resources/file-add.png
Normal file
BIN
loader/resources/file-add.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
|
@ -29,6 +29,9 @@
|
|||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <server/DownloadManager.hpp>
|
||||
#include <Geode/ui/Popup.hpp>
|
||||
|
||||
using namespace geode::prelude;
|
||||
|
||||
Loader::Impl* LoaderImpl::get() {
|
||||
|
@ -405,17 +408,16 @@ void Loader::Impl::loadModGraph(Mod* node, bool early) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!this->isModVersionSupported(node->getMetadata().getGeodeVersion())) {
|
||||
auto geodeVerRes = node->getMetadata().checkGeodeVersion();
|
||||
if (!geodeVerRes) {
|
||||
this->addProblem({
|
||||
node->getMetadata().getGeodeVersion() > this->getVersion() ? LoadProblem::Type::NeedsNewerGeodeVersion : LoadProblem::Type::UnsupportedGeodeVersion,
|
||||
node->getMetadata().getGeodeVersion() > this->getVersion() ?
|
||||
LoadProblem::Type::NeedsNewerGeodeVersion :
|
||||
LoadProblem::Type::UnsupportedGeodeVersion,
|
||||
node,
|
||||
fmt::format(
|
||||
"Geode version {}\nis required to run this mod\n(installed: {})",
|
||||
node->getMetadata().getGeodeVersion().toVString(),
|
||||
this->getVersion().toVString()
|
||||
)
|
||||
geodeVerRes.unwrapErr()
|
||||
});
|
||||
log::error("Unsupported Geode version: {}", node->getMetadata().getGeodeVersion());
|
||||
log::error("{}", geodeVerRes.unwrapErr());
|
||||
log::popNest();
|
||||
return;
|
||||
}
|
||||
|
@ -978,3 +980,170 @@ bool Loader::Impl::isSafeMode() const {
|
|||
void Loader::Impl::forceSafeMode() {
|
||||
m_forceSafeMode = true;
|
||||
}
|
||||
|
||||
void Loader::Impl::installModManuallyFromFile(std::filesystem::path const& path, std::function<void()> after) {
|
||||
auto res = ModMetadata::createFromGeodeFile(path);
|
||||
if (!res) {
|
||||
FLAlertLayer::create(
|
||||
"Invalid File",
|
||||
fmt::format(
|
||||
"The path <cy>'{}'</c> is not a valid Geode mod: {}",
|
||||
path.string(),
|
||||
res.unwrapErr()
|
||||
),
|
||||
"OK"
|
||||
)->show();
|
||||
return;
|
||||
}
|
||||
auto meta = res.unwrap();
|
||||
|
||||
auto check = meta.checkTargetVersions();
|
||||
if (!check) {
|
||||
FLAlertLayer::create(
|
||||
"Invalid Mod Version",
|
||||
fmt::format(
|
||||
"The mod <cy>{}</c> can not be installed: {}",
|
||||
meta.getID(),
|
||||
check.unwrapErr()
|
||||
),
|
||||
"OK"
|
||||
)->show();
|
||||
}
|
||||
|
||||
auto doInstallModFromFile = [this, path, meta, after]() {
|
||||
std::error_code ec;
|
||||
|
||||
static size_t MAX_ATTEMPTS = 10;
|
||||
|
||||
// Figure out a free path to install to
|
||||
auto installTo = dirs::getModsDir() / fmt::format("{}.geode", meta.getID());
|
||||
size_t counter = 0;
|
||||
while (std::filesystem::exists(installTo, ec) && counter < MAX_ATTEMPTS) {
|
||||
installTo = dirs::getModsDir() / fmt::format("{}-{}.geode", meta.getID(), counter);
|
||||
counter += 1;
|
||||
}
|
||||
|
||||
// This is incredibly unlikely but theoretically possible
|
||||
if (counter >= MAX_ATTEMPTS) {
|
||||
FLAlertLayer::create(
|
||||
"Unable to Install",
|
||||
fmt::format(
|
||||
"Unable to install mod <co>{}</c>: Can't find a free filename!",
|
||||
meta.getID()
|
||||
),
|
||||
"OK"
|
||||
)->show();
|
||||
return;
|
||||
}
|
||||
|
||||
// Actually copy the file over to the install directory
|
||||
std::filesystem::copy_file(path, installTo, ec);
|
||||
if (ec) {
|
||||
FLAlertLayer::create(
|
||||
"Unable to Install",
|
||||
fmt::format(
|
||||
"Unable to install mod <co>{}</c>: {} (Error code <cr>{}</c>)",
|
||||
meta.getID(), ec.message(), ec.value()
|
||||
),
|
||||
"OK"
|
||||
)->show();
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark an updated mod as updated or add to the mods list
|
||||
if (m_mods.contains(meta.getID())) {
|
||||
m_mods.at(meta.getID())->m_impl->m_requestedAction = ModRequestedAction::Update;
|
||||
}
|
||||
// Otherwise add a new Mod
|
||||
// This should be safe as all of the scary stuff in setup() is only relevant
|
||||
// for mods that are actually running
|
||||
else {
|
||||
auto mod = new Mod(meta);
|
||||
auto res = mod->m_impl->setup();
|
||||
if (!res) {
|
||||
log::error("Unable to set up manually installed mod: {}", res.unwrapErr());
|
||||
}
|
||||
(void)mod->enable();
|
||||
m_mods.insert({ meta.getID(), mod });
|
||||
}
|
||||
|
||||
if (after) after();
|
||||
|
||||
// No need for the user to go and manually clean up the file
|
||||
createQuickPopup(
|
||||
"Mod Installed",
|
||||
fmt::format(
|
||||
"Mod <co>{}</c> has been succesfully installed from file! "
|
||||
"<cy>Do you want to delete the original file?</c>",
|
||||
meta.getName()
|
||||
),
|
||||
"OK", "Delete File",
|
||||
[path](auto, bool btn2) {
|
||||
if (btn2) {
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(path, ec);
|
||||
if (ec) {
|
||||
FLAlertLayer::create(
|
||||
"Unable to Delete",
|
||||
fmt::format(
|
||||
"Unable to delete <cy>{}</c>: {} (Error code <cr>{}</c>)",
|
||||
path, ec.message(), ec.value()
|
||||
),
|
||||
"OK"
|
||||
)->show();
|
||||
}
|
||||
// No need to show a confirmation popup if succesful since that's
|
||||
// to be assumed via pressing the button on the previous popup
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
if (auto existing = Loader::get()->getInstalledMod(meta.getID())) {
|
||||
createQuickPopup(
|
||||
"Already Installed",
|
||||
fmt::format(
|
||||
"The mod <cy>{}</c> <cj>v{}</c> has already been installed "
|
||||
"as version <cl>{}</c>. Do you want to <co>replace the "
|
||||
"installed version with the file</c>?",
|
||||
meta.getID(), meta.getVersion(),
|
||||
existing->getVersion()
|
||||
),
|
||||
"Cancel", "Replace",
|
||||
[doInstallModFromFile, path, existing, meta](auto, bool btn2) mutable {
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(existing->getPackagePath(), ec);
|
||||
if (ec) {
|
||||
FLAlertLayer::create(
|
||||
"Unable to Uninstall",
|
||||
fmt::format(
|
||||
"Unable to uninstall <cy>{}</c>: {} (Error code <cr>{}</c>)",
|
||||
existing->getID(), ec.message(), ec.value()
|
||||
),
|
||||
"OK"
|
||||
)->show();
|
||||
return;
|
||||
}
|
||||
doInstallModFromFile();
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
doInstallModFromFile();
|
||||
}
|
||||
|
||||
bool Loader::Impl::isRestartRequired() const {
|
||||
for (auto mod : Loader::get()->getAllMods()) {
|
||||
if (mod->getRequestedAction() != ModRequestedAction::None) {
|
||||
return true;
|
||||
}
|
||||
if (ModSettingsManager::from(mod)->restartRequired()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (server::ModDownloadManager::get()->wantsRestart()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -138,6 +138,12 @@ namespace geode {
|
|||
bool isSafeMode() const;
|
||||
// enables safe mode, even if the launch arg wasnt provided
|
||||
void forceSafeMode();
|
||||
|
||||
// This will potentially start a whole sequence of popups that guide the
|
||||
// user through installing the specific .geode file
|
||||
void installModManuallyFromFile(std::filesystem::path const& path, std::function<void()> after);
|
||||
|
||||
bool isRestartRequired() const;
|
||||
};
|
||||
|
||||
class LoaderImpl : public Loader::Impl {
|
||||
|
|
|
@ -30,6 +30,7 @@ static constexpr const char* humanReadableDescForAction(ModRequestedAction actio
|
|||
case ModRequestedAction::Disable: return "Mod has been disabled";
|
||||
case ModRequestedAction::Uninstall: return "Mod has been uninstalled";
|
||||
case ModRequestedAction::UninstallWithSaveData: return "Mod has been uninstalled";
|
||||
case ModRequestedAction::Update: return "Mod has been updated";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -572,6 +572,29 @@ Result<> ModMetadata::checkGameVersion() const {
|
|||
}
|
||||
return Ok();
|
||||
}
|
||||
Result<> ModMetadata::checkGeodeVersion() const {
|
||||
if (!LoaderImpl::get()->isModVersionSupported(m_impl->m_geodeVersion)) {
|
||||
auto current = LoaderImpl::get()->getVersion();
|
||||
if (m_impl->m_geodeVersion > current) {
|
||||
return Err(
|
||||
"This mod was made for a newer version of Geode ({}). You currently have version {}.",
|
||||
m_impl->m_geodeVersion, current
|
||||
);
|
||||
}
|
||||
else {
|
||||
return Err(
|
||||
"This mod was made for an older version of Geode ({}). You currently have version {}.",
|
||||
m_impl->m_geodeVersion, current
|
||||
);
|
||||
}
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
Result<> ModMetadata::checkTargetVersions() const {
|
||||
GEODE_UNWRAP(this->checkGameVersion());
|
||||
GEODE_UNWRAP(this->checkGeodeVersion());
|
||||
return Ok();
|
||||
}
|
||||
|
||||
#if defined(GEODE_EXPOSE_SECRET_INTERNALS_IN_HEADERS_DO_NOT_DEFINE_PLEASE)
|
||||
void ModMetadata::setPath(std::filesystem::path const& value) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <Geode/utils/map.hpp>
|
||||
#include <optional>
|
||||
#include <hash/hash.hpp>
|
||||
#include <loader/ModImpl.hpp>
|
||||
|
||||
using namespace server;
|
||||
|
||||
|
@ -124,6 +125,8 @@ public:
|
|||
.details = fmt::format("Unable to delete existing .geode package (code {})", ec),
|
||||
};
|
||||
}
|
||||
// Mark mod as updated
|
||||
ModImpl::getImpl(mod)->m_requestedAction = ModRequestedAction::Update;
|
||||
}
|
||||
// If this was an update, delete the old file first
|
||||
if (!removingInstalledWasError) {
|
||||
|
|
|
@ -246,6 +246,31 @@ std::string ServerDateTime::toAgoString() const {
|
|||
return fmt::format("{:%b %d %Y}", value);
|
||||
}
|
||||
|
||||
Result<ServerTag> ServerTag::parse(matjson::Value const& raw) {
|
||||
auto root = checkJson(raw, "ServerTag");
|
||||
auto res = ServerTag();
|
||||
|
||||
root.needs("id").into(res.id);
|
||||
root.needs("name").into(res.name);
|
||||
root.needs("display_name").into(res.displayName);
|
||||
|
||||
return root.ok(res);
|
||||
}
|
||||
Result<std::vector<ServerTag>> ServerTag::parseList(matjson::Value const& raw) {
|
||||
auto payload = checkJson(raw, "ServerTagsList");
|
||||
std::vector<ServerTag> list {};
|
||||
for (auto& item : payload.items()) {
|
||||
auto mod = ServerTag::parse(item.json());
|
||||
if (mod) {
|
||||
list.push_back(mod.unwrap());
|
||||
}
|
||||
else {
|
||||
log::error("Unable to parse tag from the server: {}", mod.unwrapErr());
|
||||
}
|
||||
}
|
||||
return payload.ok(list);
|
||||
}
|
||||
|
||||
Result<ServerDateTime> ServerDateTime::parse(std::string const& str) {
|
||||
std::stringstream ss(str);
|
||||
date::sys_seconds seconds;
|
||||
|
@ -690,33 +715,25 @@ ServerRequest<ByteVector> server::getModLogo(std::string const& id, bool useCach
|
|||
);
|
||||
}
|
||||
|
||||
ServerRequest<std::unordered_set<std::string>> server::getTags(bool useCache) {
|
||||
ServerRequest<std::vector<ServerTag>> server::getTags(bool useCache) {
|
||||
if (useCache) {
|
||||
return getCache<getTags>().get();
|
||||
}
|
||||
auto req = web::WebRequest();
|
||||
req.userAgent(getServerUserAgent());
|
||||
return req.get(formatServerURL("/tags")).map(
|
||||
[](web::WebResponse* response) -> Result<std::unordered_set<std::string>, ServerError> {
|
||||
return req.get(formatServerURL("/detailed-tags")).map(
|
||||
[](web::WebResponse* response) -> Result<std::vector<ServerTag>, ServerError> {
|
||||
if (response->ok()) {
|
||||
// Parse payload
|
||||
auto payload = parseServerPayload(*response);
|
||||
if (!payload) {
|
||||
return Err(payload.unwrapErr());
|
||||
}
|
||||
matjson::Value json = payload.unwrap();
|
||||
if (!json.isArray()) {
|
||||
return Err(ServerError(response->code(), "Expected a string array"));
|
||||
auto list = ServerTag::parseList(payload.unwrap());
|
||||
if (!list) {
|
||||
return Err(ServerError(response->code(), "Unable to parse response: {}", list.unwrapErr()));
|
||||
}
|
||||
|
||||
std::unordered_set<std::string> tags;
|
||||
for (auto item : json) {
|
||||
if (!item.isString()) {
|
||||
return Err(ServerError(response->code(), "Expected a string array"));
|
||||
}
|
||||
tags.insert(item.asString().unwrap());
|
||||
}
|
||||
return Ok(tags);
|
||||
return Ok(list.unwrap());
|
||||
}
|
||||
return Err(parseServerError(*response));
|
||||
},
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
using namespace geode::prelude;
|
||||
|
||||
namespace server {
|
||||
// todo: replace parse()s with Serialize::fromJson now that it uses Results
|
||||
|
||||
struct ServerDateTime final {
|
||||
using Clock = std::chrono::system_clock;
|
||||
using Value = std::chrono::time_point<Clock>;
|
||||
|
@ -21,6 +23,15 @@ namespace server {
|
|||
static Result<ServerDateTime> parse(std::string const& str);
|
||||
};
|
||||
|
||||
struct ServerTag final {
|
||||
size_t id;
|
||||
std::string name;
|
||||
std::string displayName;
|
||||
|
||||
static Result<ServerTag> parse(matjson::Value const& json);
|
||||
static Result<std::vector<ServerTag>> parseList(matjson::Value const& json);
|
||||
};
|
||||
|
||||
struct ServerDeveloper final {
|
||||
std::string username;
|
||||
std::string displayName;
|
||||
|
@ -147,7 +158,7 @@ namespace server {
|
|||
ServerRequest<ServerModMetadata> getMod(std::string const& id, bool useCache = true);
|
||||
ServerRequest<ServerModVersion> getModVersion(std::string const& id, ModVersion const& version = ModVersionLatest(), bool useCache = true);
|
||||
ServerRequest<ByteVector> getModLogo(std::string const& id, bool useCache = true);
|
||||
ServerRequest<std::unordered_set<std::string>> getTags(bool useCache = true);
|
||||
ServerRequest<std::vector<ServerTag>> getTags(bool useCache = true);
|
||||
|
||||
ServerRequest<std::optional<ServerModUpdate>> checkUpdates(Mod const* mod);
|
||||
|
||||
|
|
|
@ -166,40 +166,55 @@ Popup<Mod*>* geode::openSettingsPopup(Mod* mod, bool disableGeodeTheme) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
using ModLogoSrc = std::variant<Mod*, std::string, std::filesystem::path>;
|
||||
|
||||
class ModLogoSprite : public CCNode {
|
||||
protected:
|
||||
std::string m_modID;
|
||||
CCNode* m_sprite = nullptr;
|
||||
EventListener<server::ServerRequest<ByteVector>> m_listener;
|
||||
|
||||
bool init(std::string const& id, bool fetch) {
|
||||
bool init(ModLogoSrc&& src) {
|
||||
if (!CCNode::init())
|
||||
return false;
|
||||
|
||||
this->setAnchorPoint({ .5f, .5f });
|
||||
this->setContentSize({ 50, 50 });
|
||||
|
||||
// This is a default ID, nothing should ever rely on the ID of any ModLogoSprite being this
|
||||
this->setID(std::string(Mod::get()->expandSpriteName(fmt::format("sprite-{}", id))));
|
||||
|
||||
m_modID = id;
|
||||
m_listener.bind(this, &ModLogoSprite::onFetch);
|
||||
|
||||
// Load from Resources
|
||||
if (!fetch) {
|
||||
this->setSprite(id == "geode.loader" ?
|
||||
CCSprite::createWithSpriteFrameName("geode-logo.png"_spr) :
|
||||
CCSprite::create(fmt::format("{}/logo.png", id).c_str()),
|
||||
false
|
||||
);
|
||||
}
|
||||
// Asynchronously fetch from server
|
||||
else {
|
||||
this->setSprite(createLoadingCircle(25), false);
|
||||
m_listener.setFilter(server::getModLogo(id));
|
||||
}
|
||||
std::visit(makeVisitor {
|
||||
[this](Mod* mod) {
|
||||
m_modID = mod->getID();
|
||||
|
||||
ModLogoUIEvent(std::make_unique<ModLogoUIEvent::Impl>(this, id)).post();
|
||||
// Load from Resources
|
||||
this->setSprite(mod->isInternal() ?
|
||||
CCSprite::createWithSpriteFrameName("geode-logo.png"_spr) :
|
||||
CCSprite::create(fmt::format("{}/logo.png", mod->getID()).c_str()),
|
||||
false
|
||||
);
|
||||
},
|
||||
[this](std::string const& id) {
|
||||
m_modID = id;
|
||||
|
||||
// Asynchronously fetch from server
|
||||
this->setSprite(createLoadingCircle(25), false);
|
||||
m_listener.setFilter(server::getModLogo(id));
|
||||
},
|
||||
[this](std::filesystem::path const& path) {
|
||||
this->setSprite(nullptr, false);
|
||||
if (auto unzip = file::Unzip::create(path)) {
|
||||
if (auto logo = unzip.unwrap().extract("logo.png")) {
|
||||
this->setSprite(std::move(logo.unwrap()), false);
|
||||
}
|
||||
}
|
||||
},
|
||||
}, src);
|
||||
|
||||
// This is a default ID, nothing should ever rely on the ID of any ModLogoSprite being this
|
||||
this->setID(std::string(Mod::get()->expandSpriteName(fmt::format("sprite-{}", m_modID))));
|
||||
|
||||
ModLogoUIEvent(std::make_unique<ModLogoUIEvent::Impl>(this, m_modID)).post();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -224,6 +239,13 @@ protected:
|
|||
ModLogoUIEvent(std::make_unique<ModLogoUIEvent::Impl>(this, m_modID)).post();
|
||||
}
|
||||
}
|
||||
void setSprite(ByteVector&& data, bool postEvent) {
|
||||
auto image = Ref(new CCImage());
|
||||
image->initWithImageData(data.data(), data.size());
|
||||
|
||||
auto texture = CCTextureCache::get()->addUIImage(image, m_modID.c_str());
|
||||
this->setSprite(CCSprite::createWithTexture(texture), postEvent);
|
||||
}
|
||||
|
||||
void onFetch(server::ServerRequest<ByteVector>::Event* event) {
|
||||
if (auto result = event->getValue()) {
|
||||
|
@ -233,12 +255,7 @@ protected:
|
|||
}
|
||||
// Otherwise load downloaded sprite to memory
|
||||
else {
|
||||
auto data = result->unwrap();
|
||||
auto image = Ref(new CCImage());
|
||||
image->initWithImageData(data.data(), data.size());
|
||||
|
||||
auto texture = CCTextureCache::get()->addUIImage(image, m_modID.c_str());
|
||||
this->setSprite(CCSprite::createWithTexture(texture), true);
|
||||
this->setSprite(std::move(result->unwrap()), true);
|
||||
}
|
||||
}
|
||||
else if (event->isCancelled()) {
|
||||
|
@ -247,9 +264,9 @@ protected:
|
|||
}
|
||||
|
||||
public:
|
||||
static ModLogoSprite* create(std::string const& id, bool fetch = false) {
|
||||
static ModLogoSprite* create(ModLogoSrc&& src) {
|
||||
auto ret = new ModLogoSprite();
|
||||
if (ret->init(id, fetch)) {
|
||||
if (ret->init(std::move(src))) {
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
@ -259,13 +276,17 @@ public:
|
|||
};
|
||||
|
||||
CCNode* geode::createDefaultLogo() {
|
||||
return ModLogoSprite::create("");
|
||||
return ModLogoSprite::create(ModLogoSrc(nullptr));
|
||||
}
|
||||
|
||||
CCNode* geode::createModLogo(Mod* mod) {
|
||||
return ModLogoSprite::create(mod->getID());
|
||||
return ModLogoSprite::create(ModLogoSrc(mod));
|
||||
}
|
||||
|
||||
CCNode* geode::createModLogo(std::filesystem::path const& geodePackage) {
|
||||
return ModLogoSprite::create(ModLogoSrc(geodePackage));
|
||||
}
|
||||
|
||||
CCNode* geode::createServerModLogo(std::string const& id) {
|
||||
return ModLogoSprite::create(id, true);
|
||||
return ModLogoSprite::create(ModLogoSrc(id));
|
||||
}
|
||||
|
|
|
@ -196,10 +196,10 @@ ButtonSprite* createTagLabel(std::string const& text, std::pair<ccColor3B, ccCol
|
|||
label->m_BGSprite->setColor(color.second);
|
||||
return label;
|
||||
}
|
||||
ButtonSprite* createGeodeTagLabel(std::string_view tag) {
|
||||
return createTagLabel(geodeTagName(tag), geodeTagColors(tag));
|
||||
ButtonSprite* createGeodeTagLabel(server::ServerTag const& tag) {
|
||||
return createTagLabel(tag.displayName, geodeTagColors(tag));
|
||||
}
|
||||
std::pair<ccColor3B, ccColor3B> geodeTagColors(std::string_view tag) {
|
||||
std::pair<ccColor3B, ccColor3B> geodeTagColors(server::ServerTag const& tag) {
|
||||
static std::array TAG_COLORS {
|
||||
std::make_pair(ccc3(240, 233, 255), ccc3(130, 123, 163)),
|
||||
std::make_pair(ccc3(234, 255, 245), ccc3(123, 163, 136)),
|
||||
|
@ -207,20 +207,10 @@ std::pair<ccColor3B, ccColor3B> geodeTagColors(std::string_view tag) {
|
|||
std::make_pair(ccc3(255, 253, 240), ccc3(163, 157, 123)),
|
||||
std::make_pair(ccc3(255, 242, 240), ccc3(163, 128, 123)),
|
||||
};
|
||||
if (tag == "modtober24") {
|
||||
if (tag.name == "modtober24") {
|
||||
return std::make_pair(ccc3(225, 236, 245), ccc3(82, 139, 201));
|
||||
}
|
||||
return TAG_COLORS[hash(tag) % 5932 % TAG_COLORS.size()];
|
||||
}
|
||||
std::string geodeTagName(std::string_view tag) {
|
||||
// todo in v4: rework tags to use a server-provided display name instead
|
||||
if (tag == "modtober24") {
|
||||
return "Modtober 2024";
|
||||
}
|
||||
// Everything else just capitalize and that's it
|
||||
auto readable = std::string(tag);
|
||||
readable[0] = std::toupper(readable[0]);
|
||||
return readable;
|
||||
return TAG_COLORS[hash(tag.name) % 5932 % TAG_COLORS.size()];
|
||||
}
|
||||
|
||||
ListBorders* createGeodeListBorders(CCSize const& size, bool forceDisableTheme) {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <Geode/ui/BasedButtonSprite.hpp>
|
||||
#include <Geode/ui/Popup.hpp>
|
||||
#include <Geode/loader/Mod.hpp>
|
||||
#include <server/Server.hpp>
|
||||
|
||||
using namespace geode::prelude;
|
||||
|
||||
|
@ -87,9 +88,8 @@ ButtonSprite* createGeodeButton(std::string const& text, bool gold = false, Geod
|
|||
CircleButtonSprite* createGeodeCircleButton(CCSprite* top, float scale = 1.f, CircleBaseSize size = CircleBaseSize::Medium, bool altColor = false, bool forceDisableTheme = false);
|
||||
|
||||
ButtonSprite* createTagLabel(std::string const& text, std::pair<ccColor3B, ccColor3B> const& color);
|
||||
ButtonSprite* createGeodeTagLabel(std::string_view tag);
|
||||
std::pair<ccColor3B, ccColor3B> geodeTagColors(std::string_view tag);
|
||||
std::string geodeTagName(std::string_view tag);
|
||||
ButtonSprite* createGeodeTagLabel(server::ServerTag const& tag);
|
||||
std::pair<ccColor3B, ccColor3B> geodeTagColors(server::ServerTag const& tag);
|
||||
|
||||
ListBorders* createGeodeListBorders(CCSize const& size, bool forceDisableTheme = false);
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ void ModsStatusNode::updateState() {
|
|||
switch (state) {
|
||||
// If there are no downloads happening, just show the restart button if needed
|
||||
case DownloadState::None: {
|
||||
m_restartBtn->setVisible(ModListSource::isRestartRequired());
|
||||
m_restartBtn->setVisible(LoaderImpl::get()->isRestartRequired());
|
||||
} break;
|
||||
|
||||
// If some downloads were cancelled, show the restart button normally
|
||||
|
@ -154,7 +154,7 @@ void ModsStatusNode::updateState() {
|
|||
m_status->setColor(ccWHITE);
|
||||
m_status->setVisible(true);
|
||||
|
||||
m_restartBtn->setVisible(ModListSource::isRestartRequired());
|
||||
m_restartBtn->setVisible(LoaderImpl::get()->isRestartRequired());
|
||||
} break;
|
||||
|
||||
// If all downloads were finished, show the restart button normally
|
||||
|
@ -170,7 +170,7 @@ void ModsStatusNode::updateState() {
|
|||
m_status->setVisible(true);
|
||||
m_statusBG->setVisible(true);
|
||||
|
||||
m_restartBtn->setVisible(ModListSource::isRestartRequired());
|
||||
m_restartBtn->setVisible(LoaderImpl::get()->isRestartRequired());
|
||||
} break;
|
||||
|
||||
case DownloadState::SomeErrored: {
|
||||
|
@ -274,6 +274,39 @@ void ModsLayer::onOpenModsFolder(CCObject*) {
|
|||
file::openFolder(dirs::getModsDir());
|
||||
}
|
||||
|
||||
void ModsLayer::onAddModFromFile(CCObject*) {
|
||||
if (!Mod::get()->setSavedValue("shown-manual-install-info", true)) {
|
||||
return FLAlertLayer::create(
|
||||
nullptr,
|
||||
"Manually Installing Mods",
|
||||
"You can <cg>manually install mods</c> by selecting their <cd>.geode</c> files. "
|
||||
"Do note that manually installed mods <co>are not verified to be safe and stable</c>!\n"
|
||||
"<cr>Proceed at your own risk!</c>",
|
||||
"OK", nullptr,
|
||||
350
|
||||
)->show();
|
||||
}
|
||||
file::pick(file::PickMode::OpenFile, file::FilePickOptions {
|
||||
.filters = { file::FilePickOptions::Filter {
|
||||
.description = "Geode Mods",
|
||||
.files = { "*.geode" },
|
||||
}}
|
||||
}).listen([](Result<std::filesystem::path>* path) {
|
||||
if (*path) {
|
||||
LoaderImpl::get()->installModManuallyFromFile(path->unwrap(), []() {
|
||||
InstalledModListSource::get(InstalledModListType::All)->clearCache();
|
||||
});
|
||||
}
|
||||
else {
|
||||
FLAlertLayer::create(
|
||||
"Unable to Select File",
|
||||
path->unwrapErr(),
|
||||
"OK"
|
||||
)->show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void ModsStatusNode::onRestart(CCObject*) {
|
||||
// Update button state to let user know it's restarting but it might take a bit
|
||||
m_restartBtn->setEnabled(false);
|
||||
|
@ -380,6 +413,20 @@ bool ModsLayer::init() {
|
|||
folderBtn->setID("mods-folder-button");
|
||||
actionsMenu->addChild(folderBtn);
|
||||
|
||||
auto addSpr = createGeodeCircleButton(
|
||||
CCSprite::createWithSpriteFrameName("file-add.png"_spr), 1.f,
|
||||
CircleBaseSize::Medium
|
||||
);
|
||||
addSpr->setScale(.8f);
|
||||
addSpr->setTopRelativeScale(.8f);
|
||||
auto addBtn = CCMenuItemSpriteExtra::create(
|
||||
addSpr,
|
||||
this,
|
||||
menu_selector(ModsLayer::onAddModFromFile)
|
||||
);
|
||||
addBtn->setID("mods-add-button");
|
||||
actionsMenu->addChild(addBtn);
|
||||
|
||||
actionsMenu->setLayout(
|
||||
ColumnLayout::create()
|
||||
->setAxisAlignment(AxisAlignment::Start)
|
||||
|
|
|
@ -76,6 +76,7 @@ protected:
|
|||
|
||||
void onTab(CCObject* sender);
|
||||
void onOpenModsFolder(CCObject*);
|
||||
void onAddModFromFile(CCObject*);
|
||||
void onBigView(CCObject*);
|
||||
void onSearch(CCObject*);
|
||||
void onGoToPage(CCObject*);
|
||||
|
|
|
@ -64,11 +64,6 @@ bool ModDeveloperList::init(DevListPopup* popup, ModSource const& source, CCSize
|
|||
m_list->m_contentLayer->addChild(ModDeveloperItem::create(popup, dev.username, itemSize, dev.displayName));
|
||||
}
|
||||
},
|
||||
[this, popup, itemSize](ModSuggestion const& suggestion) {
|
||||
for (std::string& dev : suggestion.suggestion.getDevelopers()) {
|
||||
m_list->m_contentLayer->addChild(ModDeveloperItem::create(popup, dev, itemSize, std::nullopt, false));
|
||||
}
|
||||
},
|
||||
});
|
||||
m_list->m_contentLayer->updateLayout();
|
||||
m_list->scrollToTop();
|
||||
|
|
|
@ -285,7 +285,7 @@ bool ModItem::init(ModSource&& source) {
|
|||
m_recommendedBy->addChild(nameLabel);
|
||||
|
||||
m_recommendedBy->setLayout(
|
||||
RowLayout::create()
|
||||
RowLayout::create()
|
||||
->setDefaultScaleLimits(.1f, 1.f)
|
||||
->setAxisAlignment(AxisAlignment::Start)
|
||||
);
|
||||
|
@ -392,10 +392,6 @@ void ModItem::updateState() {
|
|||
m_bg->setColor("mod-list-featured-color"_cc3b);
|
||||
m_bg->setOpacity(65);
|
||||
}
|
||||
},
|
||||
[this](ModSuggestion const& suggestion) {
|
||||
m_bg->setColor("mod-list-recommended-bg"_cc3b);
|
||||
m_bg->setOpacity(isGeodeTheme() ? 25 : 90);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ bool FiltersPopup::setup(ModListSource* src) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void FiltersPopup::onLoadTags(typename server::ServerRequest<std::unordered_set<std::string>>::Event* event) {
|
||||
void FiltersPopup::onLoadTags(typename server::ServerRequest<std::vector<server::ServerTag>>::Event* event) {
|
||||
if (event->getValue() && event->getValue()->isOk()) {
|
||||
auto tags = event->getValue()->unwrap();
|
||||
m_tagsMenu->removeAllChildren();
|
||||
|
@ -157,7 +157,7 @@ void FiltersPopup::onLoadTags(typename server::ServerRequest<std::unordered_set<
|
|||
offSpr, onSpr, this, menu_selector(FiltersPopup::onSelectTag)
|
||||
);
|
||||
btn->m_notClickable = true;
|
||||
btn->setUserObject("tag", CCString::create(tag));
|
||||
btn->setUserObject("tag", CCString::create(tag.name));
|
||||
m_tagsMenu->addChild(btn);
|
||||
}
|
||||
m_tagsMenu->updateLayout();
|
||||
|
|
|
@ -13,14 +13,14 @@ protected:
|
|||
ModListSource* m_source;
|
||||
CCMenu* m_tagsMenu;
|
||||
std::unordered_set<std::string> m_selectedTags;
|
||||
EventListener<server::ServerRequest<std::unordered_set<std::string>>> m_tagsListener;
|
||||
EventListener<server::ServerRequest<std::vector<server::ServerTag>>> m_tagsListener;
|
||||
CCMenuItemToggler* m_enabledModsOnly = nullptr;
|
||||
TextInput* m_developerNameInput = nullptr;
|
||||
|
||||
bool setup(ModListSource* src) override;
|
||||
void updateTags();
|
||||
|
||||
void onLoadTags(typename server::ServerRequest<std::unordered_set<std::string>>::Event* event);
|
||||
void onLoadTags(typename server::ServerRequest<std::vector<server::ServerTag>>::Event* event);
|
||||
void onResetTags(CCObject*);
|
||||
void onResetDevName(CCObject*);
|
||||
void onSelectTag(CCObject* sender);
|
||||
|
|
|
@ -885,7 +885,7 @@ void ModPopup::onCheckUpdates(typename server::ServerRequest<std::optional<serve
|
|||
}
|
||||
}
|
||||
|
||||
void ModPopup::onLoadTags(typename server::ServerRequest<std::unordered_set<std::string>>::Event* event) {
|
||||
void ModPopup::onLoadTags(typename server::ServerRequest<std::vector<server::ServerTag>>::Event* event) {
|
||||
if (event->getValue() && event->getValue()->isOk()) {
|
||||
auto data = event->getValue()->unwrap();
|
||||
m_tags->removeAllChildren();
|
||||
|
@ -904,7 +904,7 @@ void ModPopup::onLoadTags(typename server::ServerRequest<std::unordered_set<std:
|
|||
// If the build times from the cool popup become too long then we can
|
||||
// probably move that to a normal FLAlert that explains "Modtober was
|
||||
// this contest blah blah this mod was made for it"
|
||||
else if (data.contains("modtober24")) {
|
||||
else if (ranges::contains(data, [](auto const& tag) { return tag.name == "modtober24"; })) {
|
||||
auto menu = CCMenu::create();
|
||||
menu->setID("modtober-banner");
|
||||
menu->ignoreAnchorPointForPosition(false);
|
||||
|
|
|
@ -38,7 +38,7 @@ protected:
|
|||
CCNode* m_modtoberBanner = nullptr;
|
||||
std::unordered_map<Tab, std::pair<GeodeTabSprite*, Ref<CCNode>>> m_tabs;
|
||||
EventListener<server::ServerRequest<server::ServerModMetadata>> m_statsListener;
|
||||
EventListener<server::ServerRequest<std::unordered_set<std::string>>> m_tagsListener;
|
||||
EventListener<server::ServerRequest<std::vector<server::ServerTag>>> m_tagsListener;
|
||||
EventListener<server::ServerRequest<std::optional<server::ServerModUpdate>>> m_checkUpdateListener;
|
||||
EventListener<UpdateModListStateFilter> m_updateStateListener;
|
||||
EventListener<server::ModDownloadFilter> m_downloadListener;
|
||||
|
@ -52,7 +52,7 @@ protected:
|
|||
void setStatValue(CCNode* stat, std::optional<std::string> const& value);
|
||||
|
||||
void onLoadServerInfo(typename server::ServerRequest<server::ServerModMetadata>::Event* event);
|
||||
void onLoadTags(typename server::ServerRequest<std::unordered_set<std::string>>::Event* event);
|
||||
void onLoadTags(typename server::ServerRequest<std::vector<server::ServerTag>>::Event* event);
|
||||
void onCheckUpdates(typename server::ServerRequest<std::optional<server::ServerModUpdate>>::Event* event);
|
||||
|
||||
void onTab(CCObject* sender);
|
||||
|
|
|
@ -13,10 +13,10 @@ bool InstalledModsQuery::preCheck(ModSource const& src) const {
|
|||
}
|
||||
// If only errors requested, only show mods with errors (duh)
|
||||
if (type == InstalledModListType::OnlyOutdated) {
|
||||
return src.asMod()->targetsOutdatedVersion().has_value();
|
||||
return src.asMod() && src.asMod()->targetsOutdatedVersion().has_value();
|
||||
}
|
||||
if (type == InstalledModListType::OnlyErrors) {
|
||||
return src.asMod()->hasLoadProblems();
|
||||
return src.asMod() && src.asMod()->hasLoadProblems();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "ModListSource.hpp"
|
||||
#include <server/DownloadManager.hpp>
|
||||
#include <Geode/loader/ModSettingsManager.hpp>
|
||||
#include <loader/LoaderImpl.hpp>
|
||||
|
||||
#define FTS_FUZZY_MATCH_IMPLEMENTATION
|
||||
#include <Geode/external/fts/fts_fuzzy_match.h>
|
||||
|
@ -88,20 +89,6 @@ void ModListSource::clearAllCaches() {
|
|||
src->clearCache();
|
||||
}
|
||||
}
|
||||
bool ModListSource::isRestartRequired() {
|
||||
for (auto mod : Loader::get()->getAllMods()) {
|
||||
if (mod->getRequestedAction() != ModRequestedAction::None) {
|
||||
return true;
|
||||
}
|
||||
if (ModSettingsManager::from(mod)->restartRequired()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (server::ModDownloadManager::get()->wantsRestart()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool weightedFuzzyMatch(std::string const& str, std::string const& kw, double weight, double& out) {
|
||||
int score;
|
||||
|
|
|
@ -79,7 +79,6 @@ public:
|
|||
void setPageSize(size_t size);
|
||||
|
||||
static void clearAllCaches();
|
||||
static bool isRestartRequired();
|
||||
};
|
||||
|
||||
template <class T>
|
||||
|
@ -231,8 +230,8 @@ void filterModsWithLocalQuery(ModListSource::ProvidedMods& mods, Query const& qu
|
|||
return a.second > b.second;
|
||||
}
|
||||
// Make sure outdated mods are always last by default
|
||||
auto aIsOutdated = a.first.getMetadata().checkGameVersion().isErr();
|
||||
auto bIsOutdated = b.first.getMetadata().checkGameVersion().isErr();
|
||||
auto aIsOutdated = a.first.getMetadata().checkTargetVersions().isErr();
|
||||
auto bIsOutdated = b.first.getMetadata().checkTargetVersions().isErr();
|
||||
if (aIsOutdated != bIsOutdated) {
|
||||
return !aIsOutdated;
|
||||
}
|
||||
|
|
|
@ -52,9 +52,6 @@ std::string ModSource::getID() const {
|
|||
[](server::ServerModMetadata const& metadata) {
|
||||
return metadata.id;
|
||||
},
|
||||
[](ModSuggestion const& suggestion) {
|
||||
return suggestion.suggestion.getID();
|
||||
},
|
||||
}, m_value);
|
||||
}
|
||||
ModMetadata ModSource::getMetadata() const {
|
||||
|
@ -66,9 +63,6 @@ ModMetadata ModSource::getMetadata() const {
|
|||
// Versions should be guaranteed to have at least one item
|
||||
return metadata.versions.front().metadata;
|
||||
},
|
||||
[](ModSuggestion const& suggestion) {
|
||||
return suggestion.suggestion;
|
||||
},
|
||||
}, m_value);
|
||||
}
|
||||
|
||||
|
@ -81,9 +75,6 @@ std::string ModSource::formatDevelopers() const {
|
|||
// Versions should be guaranteed to have at least one item
|
||||
return metadata.formatDevelopersToString();
|
||||
},
|
||||
[](ModSuggestion const& suggestion) {
|
||||
return ModMetadata::formatDeveloperDisplayString(suggestion.suggestion.getDevelopers());
|
||||
},
|
||||
}, m_value);
|
||||
}
|
||||
|
||||
|
@ -95,9 +86,6 @@ CCNode* ModSource::createModLogo() const {
|
|||
[](server::ServerModMetadata const& metadata) {
|
||||
return createServerModLogo(metadata.id);
|
||||
},
|
||||
[](ModSuggestion const& suggestion) {
|
||||
return createServerModLogo(suggestion.suggestion.getID());
|
||||
},
|
||||
}, m_value);
|
||||
}
|
||||
bool ModSource::wantsRestart() const {
|
||||
|
@ -114,9 +102,6 @@ bool ModSource::wantsRestart() const {
|
|||
[](server::ServerModMetadata const& metdata) {
|
||||
return false;
|
||||
},
|
||||
[](ModSuggestion const& suggestion) {
|
||||
return false;
|
||||
},
|
||||
}, m_value);
|
||||
}
|
||||
std::optional<server::ServerModUpdate> ModSource::hasUpdates() const {
|
||||
|
@ -134,9 +119,6 @@ ModSource ModSource::convertForPopup() const {
|
|||
}
|
||||
return ModSource(server::ServerModMetadata(metadata));
|
||||
},
|
||||
[](ModSuggestion const& suggestion) {
|
||||
return ModSource(ModSuggestion(suggestion));
|
||||
},
|
||||
}, m_value);
|
||||
}
|
||||
|
||||
|
@ -149,6 +131,7 @@ server::ServerModMetadata const* ModSource::asServer() const {
|
|||
}
|
||||
|
||||
server::ServerRequest<std::optional<std::string>> ModSource::fetchAbout() const {
|
||||
// todo: write as visit
|
||||
if (auto mod = this->asMod()) {
|
||||
return server::ServerRequest<std::optional<std::string>>::immediate(Ok(mod->getMetadata().getDetails()));
|
||||
}
|
||||
|
@ -180,41 +163,41 @@ server::ServerRequest<server::ServerModMetadata> ModSource::fetchServerInfo() co
|
|||
// should deal with performance issues
|
||||
return server::getMod(this->getID());
|
||||
}
|
||||
server::ServerRequest<std::unordered_set<std::string>> ModSource::fetchValidTags() const {
|
||||
return std::visit(makeVisitor {
|
||||
[](Mod* mod) {
|
||||
return server::getTags().map(
|
||||
[mod](Result<std::unordered_set<std::string>, server::ServerError>* result)
|
||||
-> Result<std::unordered_set<std::string>, server::ServerError> {
|
||||
std::unordered_set<std::string> finalTags;
|
||||
auto modTags = mod->getMetadata().getTags();
|
||||
|
||||
if (result->isOk()) {
|
||||
std::unordered_set<std::string> fetched = result->unwrap();
|
||||
// Filter out invalid tags
|
||||
for (std::string const& tag : modTags) {
|
||||
if (fetched.contains(tag)) {
|
||||
finalTags.insert(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(finalTags);
|
||||
},
|
||||
[](server::ServerProgress* progress) {
|
||||
return *progress;
|
||||
}
|
||||
);
|
||||
server::ServerRequest<std::vector<server::ServerTag>> ModSource::fetchValidTags() const {
|
||||
std::unordered_set<std::string> modTags;
|
||||
std::visit(makeVisitor {
|
||||
[&](Mod* mod) {
|
||||
modTags = mod->getMetadata().getTags();
|
||||
},
|
||||
[](server::ServerModMetadata const& metadata) {
|
||||
// Server info tags are always certain to be valid since the server has already validated them
|
||||
return server::ServerRequest<std::unordered_set<std::string>>::immediate(Ok(metadata.tags));
|
||||
},
|
||||
[](ModSuggestion const& suggestion) {
|
||||
// Suggestions are also guaranteed to be valid since they come from the server
|
||||
return server::ServerRequest<std::unordered_set<std::string>>::immediate(Ok(suggestion.suggestion.getTags()));
|
||||
[&](server::ServerModMetadata const& metadata) {
|
||||
modTags = metadata.tags;
|
||||
},
|
||||
}, m_value);
|
||||
|
||||
// This does two things:
|
||||
// 1. For installed mods, it filters out invalid tags
|
||||
// 2. For everything else, it gets the rest of the tag info (display name) from the server
|
||||
return server::getTags().map(
|
||||
[modTags = std::move(modTags)](auto* result) -> Result<std::vector<server::ServerTag>, server::ServerError> {
|
||||
auto finalTags = std::vector<server::ServerTag>();
|
||||
if (result->isOk()) {
|
||||
auto fetched = result->unwrap();
|
||||
// Filter out invalid tags
|
||||
for (auto& tag : modTags) {
|
||||
auto stag = ranges::find(fetched, [&tag](server::ServerTag const& stag) {
|
||||
return stag.name == tag;
|
||||
});
|
||||
if (stag) {
|
||||
finalTags.push_back(*stag);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(finalTags);
|
||||
},
|
||||
[](server::ServerProgress* progress) {
|
||||
return *progress;
|
||||
}
|
||||
);
|
||||
}
|
||||
server::ServerRequest<std::optional<server::ServerModUpdate>> ModSource::checkUpdates() {
|
||||
m_availableUpdate = std::nullopt;
|
||||
|
@ -234,10 +217,6 @@ server::ServerRequest<std::optional<server::ServerModUpdate>> ModSource::checkUp
|
|||
// Server mods aren't installed so you can't install updates for them
|
||||
return server::ServerRequest<std::optional<server::ServerModUpdate>>::immediate(Ok(std::nullopt));
|
||||
},
|
||||
[](ModSuggestion const& suggestion) {
|
||||
// Suggestions also aren't installed so you can't install updates for them
|
||||
return server::ServerRequest<std::optional<server::ServerModUpdate>>::immediate(Ok(std::nullopt));
|
||||
},
|
||||
}, m_value);
|
||||
}
|
||||
void ModSource::startInstall() {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <Geode/loader/Mod.hpp>
|
||||
#include <server/Server.hpp>
|
||||
#include <loader/LoaderImpl.hpp>
|
||||
|
||||
using namespace geode::prelude;
|
||||
|
||||
|
@ -23,7 +24,6 @@ public:
|
|||
ModSource() = default;
|
||||
ModSource(Mod* mod);
|
||||
ModSource(server::ServerModMetadata&& metadata);
|
||||
ModSource(ModSuggestion&& suggestion);
|
||||
|
||||
std::string getID() const;
|
||||
ModMetadata getMetadata() const;
|
||||
|
@ -47,7 +47,7 @@ public:
|
|||
server::ServerRequest<server::ServerModMetadata> fetchServerInfo() const;
|
||||
server::ServerRequest<std::optional<std::string>> fetchAbout() const;
|
||||
server::ServerRequest<std::optional<std::string>> fetchChangelog() const;
|
||||
server::ServerRequest<std::unordered_set<std::string>> fetchValidTags() const;
|
||||
server::ServerRequest<std::vector<server::ServerTag>> fetchValidTags() const;
|
||||
server::ServerRequest<std::optional<server::ServerModUpdate>> checkUpdates();
|
||||
void startInstall();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue