MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / Assets

Method Assets

source/base/StarAssets.cpp:113–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113Assets::Assets(Settings settings, StringList assetSources) {
114 const char* AssetsPatchSuffix = ".patch";
115 const char* AssetsPatchListSuffix = ".patchlist";
116 const char* AssetsLuaPatchSuffix = ".patch.lua";
117
118 m_settings = std::move(settings);
119 m_stopThreads = false;
120 m_assetSources = std::move(assetSources);
121
122 auto luaEngine = LuaEngine::create();
123 m_luaEngine = luaEngine;
124 auto pushGlobalContext = [&luaEngine](String const& name, LuaCallbacks && callbacks) {
125 auto table = luaEngine->createTable();
126 for (auto const& p : callbacks.callbacks())
127 table.set(p.first, luaEngine->createWrappedFunction(p.second));
128 luaEngine->setGlobal(name, table);
129 };
130
131 auto makeBaseAssetCallbacks = [this]() {
132 LuaCallbacks callbacks;
133 callbacks.registerCallbackWithSignature<StringSet, String>("byExtension", bind(&Assets::scanExtension, this, _1));
134 callbacks.registerCallbackWithSignature<Json, String>("json", bind(&Assets::json, this, _1));
135 callbacks.registerCallbackWithSignature<bool, String>("exists", bind(&Assets::assetExists, this, _1));
136
137 callbacks.registerCallback("sourcePaths", [this](LuaEngine& engine, Maybe<bool> withMetaData) -> LuaTable {
138 auto assetSources = this->assetSources();
139 auto table = engine.createTable(assetSources.size(), 0);
140 if (withMetaData.value()) {
141 for (auto& assetSource : assetSources)
142 table.set(assetSource, this->assetSourceMetadata(assetSource));
143 }
144 else {
145 size_t i = 0;
146 for (auto& assetSource : assetSources)
147 table.set(++i, assetSource);
148 }
149 return table;
150 });
151
152 callbacks.registerCallback("sourceMetadata", [this](String const& sourcePath) -> Maybe<JsonObject> {
153 if (auto assetSource = m_assetSourcePaths.rightPtr(sourcePath))
154 return (*assetSource)->metadata();
155 return {};
156 });
157
158 callbacks.registerCallback("origin", [this](String const& path) -> Maybe<String> {
159 if (auto descriptor = this->assetDescriptor(path))
160 return this->assetSourcePath(descriptor->source);
161 return {};
162 });
163
164 callbacks.registerCallback("bytes", [this](String const& path) -> String {
165 auto assetBytes = bytes(path);
166 return String(assetBytes->ptr(), assetBytes->size());
167 });
168
169 callbacks.registerCallback("image", [this](String const& path) -> Image {
170 auto assetImage = image(path);

Callers

nothing calls this directly

Calls 15

assetSourcesMethod · 0.95
assetSourceMetadataMethod · 0.95
assetDescriptorMethod · 0.95
assetSourcePathMethod · 0.95
bytesClass · 0.85
StringClass · 0.85
JsonClass · 0.85
ByteArrayClass · 0.85
inputUtf8JsonFunction · 0.85
strfFunction · 0.85
toStringFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected