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

Method loadJson

source/base/StarAssets.cpp:1198–1225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1196}
1197
1198shared_ptr<Assets::AssetData> Assets::loadJson(AssetPath const& path) const {
1199 Json json;
1200
1201 if (path.subPath) {
1202 auto topJson =
1203 as<JsonData>(loadAsset(AssetId{AssetType::Json, {path.basePath, {}, {}}}));
1204 if (!topJson)
1205 return {};
1206
1207 try {
1208 auto newData = make_shared<JsonData>();
1209 newData->json = topJson->json.query(*path.subPath);
1210 return newData;
1211 } catch (StarException const& e) {
1212 throw AssetException(strf("Could not read JSON value {}", path), e);
1213 }
1214 } else {
1215 return unlockDuring([&]() {
1216 try {
1217 auto newData = make_shared<JsonData>();
1218 newData->json = readJson(path.basePath);
1219 return newData;
1220 } catch (StarException const& e) {
1221 throw AssetException(strf("Could not read JSON asset {}", path), e);
1222 }
1223 });
1224 }
1225}
1226
1227shared_ptr<Assets::AssetData> Assets::loadImage(AssetPath const& path) const {
1228 validatePath(path, true, true);

Callers 2

FuelWidgetMethod · 0.45
applicationInitMethod · 0.45

Calls 2

strfFunction · 0.85
queryMethod · 0.45

Tested by

no test coverage detected