-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add optional event based api to fetch loaded packs
- Loading branch information
Showing
5 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#pragma once | ||
|
||
#include <Geode/loader/Dispatch.hpp> | ||
|
||
#include <filesystem> | ||
#include <vector> | ||
#include <string> | ||
|
||
namespace geode::texture_loader { | ||
|
||
inline bool isLoaded() { | ||
return geode::Loader::get()->isModLoaded("geode.texture-loader"); | ||
} | ||
|
||
struct Pack { | ||
std::string id; | ||
std::string name; | ||
VersionInfo version; | ||
std::vector<std::string> authors; | ||
|
||
/// Path from where the pack originates from. May be a file (apk, zip) or a folder | ||
std::filesystem::path path; | ||
/// Path where the resources are located. This is what is added to the search path | ||
std::filesystem::path resourcesPath; | ||
}; | ||
|
||
namespace impl { | ||
using EventGetAvailablePacks = geode::DispatchEvent<std::vector<Pack>*>; | ||
using EventGetAppliedPacks = geode::DispatchEvent<std::vector<Pack>*>; | ||
} | ||
|
||
inline std::vector<Pack> getAvailablePacks() { | ||
std::vector<Pack> result; | ||
log::debug("sending event!"); | ||
impl::EventGetAvailablePacks("geode.texture-loader/v1/get-available-packs", &result).post(); | ||
log::debug("ok sent event!"); | ||
return result; | ||
} | ||
|
||
inline std::vector<Pack> getAppliedPacks() { | ||
std::vector<Pack> result; | ||
impl::EventGetAppliedPacks("geode.texture-loader/v1/get-applied-packs", &result).post(); | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "../include/TextureLoader.hpp" | ||
|
||
#include "PackManager.hpp" | ||
|
||
using namespace geode; | ||
|
||
namespace ext = geode::texture_loader; | ||
|
||
template <class> | ||
struct ToFilterImpl; | ||
|
||
template <class... Args> | ||
struct ToFilterImpl<geode::DispatchEvent<Args...>> { | ||
using type = geode::DispatchFilter<Args...>; | ||
}; | ||
|
||
template <class T> | ||
using ToFilter = typename ToFilterImpl<T>::type; | ||
|
||
ext::Pack convertPack(std::shared_ptr<Pack> const& pack) { | ||
ext::Pack res; | ||
res.id = pack->getID(); | ||
res.name = pack->getDisplayName(); | ||
res.path = pack->getOriginPath(); | ||
res.resourcesPath = pack->getResourcesPath(); | ||
// if the pack has a mod.json | ||
if (auto opt = pack->getInfo()) { | ||
auto info = opt.value(); | ||
res.version = info.m_version; | ||
res.authors = info.m_authors; | ||
} | ||
return res; | ||
} | ||
|
||
$execute { | ||
new EventListener(+[](std::vector<ext::Pack>* res) { | ||
log::debug("received event!"); | ||
*res = utils::ranges::map<std::vector<ext::Pack>>(PackManager::get()->getAvailablePacks(), convertPack); | ||
return ListenerResult::Stop; | ||
}, ToFilter<ext::impl::EventGetAvailablePacks>("geode.texture-loader/v1/get-available-packs")); | ||
|
||
new EventListener(+[](std::vector<ext::Pack>* res) { | ||
*res = utils::ranges::map<std::vector<ext::Pack>>(PackManager::get()->getAppliedPacks(), convertPack); | ||
return ListenerResult::Stop; | ||
}, ToFilter<ext::impl::EventGetAppliedPacks>("geode.texture-loader/v1/get-applied-packs")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters