diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2025-02-24 09:36:58 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-24 09:36:58 +1100 |
commit | 7a14ad34c6bfedfe2ffdb13bd6ea6482fc0b560f (patch) | |
tree | 7fc9b120efda129c09e522fc08af2d28e52d3eb6 /source/base/StarAssets.cpp | |
parent | 5dda9f47306a6eea5eb4e676c68f81b8285d9dfe (diff) | |
parent | 0245e639ecc51d948f0256eb4a773d42fbb8ade5 (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.cpp | 21 |
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()); |