Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/base/StarAssets.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2025-02-24 09:36:58 +1100
committerGitHub <noreply@github.com>2025-02-24 09:36:58 +1100
commit7a14ad34c6bfedfe2ffdb13bd6ea6482fc0b560f (patch)
tree7fc9b120efda129c09e522fc08af2d28e52d3eb6 /source/base/StarAssets.cpp
parent5dda9f47306a6eea5eb4e676c68f81b8285d9dfe (diff)
parent0245e639ecc51d948f0256eb4a773d42fbb8ade5 (diff)
Merge pull request #195 from WereTech/main
Add "sourcePaths" and "origin" callbacks to assets
Diffstat (limited to 'source/base/StarAssets.cpp')
-rw-r--r--source/base/StarAssets.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/source/base/StarAssets.cpp b/source/base/StarAssets.cpp
index 7db8efe..8471a0c 100644
--- a/source/base/StarAssets.cpp
+++ b/source/base/StarAssets.cpp
@@ -134,6 +134,27 @@ Assets::Assets(Settings settings, StringList assetSources) {
callbacks.registerCallbackWithSignature<Json, String>("json", bind(&Assets::json, this, _1));
callbacks.registerCallbackWithSignature<bool, String>("exists", bind(&Assets::assetExists, this, _1));
+ callbacks.registerCallback("sourcePaths", [this](LuaEngine& engine, Maybe<bool> withMetaData) -> LuaTable {
+ auto assetSources = this->assetSources();
+ auto table = engine.createTable(assetSources.size(), 0);
+ if (withMetaData.value()) {
+ for (auto& assetSource : assetSources)
+ table.set(assetSource, this->assetSourceMetadata(assetSource));
+ }
+ else {
+ size_t i = 0;
+ for (auto& assetSource : assetSources)
+ table.set(++i, assetSource);
+ }
+ return table;
+ });
+
+ callbacks.registerCallback("origin", [this](String const& path) -> Maybe<String> {
+ if (auto descriptor = this->assetDescriptor(path))
+ return this->assetSourcePath(descriptor->source);
+ return {};
+ });
+
callbacks.registerCallback("bytes", [this](String const& path) -> String {
auto assetBytes = bytes(path);
return String(assetBytes->ptr(), assetBytes->size());