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

Method checkPatchArray

source/base/StarAssets.cpp:1010–1040  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1008
1009
1010Json Assets::checkPatchArray(String const& path, AssetSourcePtr const& source, Json const result, JsonArray const patchData, Maybe<Json> const external) const {
1011 auto externalRef = external.value();
1012 auto newResult = result;
1013 for (auto const& patch : patchData) {
1014 switch(patch.type()) {
1015 case Json::Type::Array: // if the patch is an array, go down recursively until we get objects
1016 try {
1017 newResult = checkPatchArray(path, source, newResult, patch.toArray(), externalRef);
1018 } catch (JsonPatchTestFail const& e) {
1019 Logger::debug("Patch test failure from file {} in source: '{}' at '{}'. Caused by: {}", path, source->metadata().value("name", ""), m_assetSourcePaths.getLeft(source), e.what());
1020 } catch (JsonPatchException const& e) {
1021 Logger::error("Could not apply patch from file {} in source: '{}' at '{}'. Caused by: {}", path, source->metadata().value("name", ""), m_assetSourcePaths.getLeft(source), e.what());
1022 }
1023 break;
1024 case Json::Type::Object: // if its an object, check for operations, or for if an external file is needed for patches to reference
1025 newResult = JsonPatching::applyOperation(newResult, patch, externalRef);
1026 break;
1027 case Json::Type::String:
1028 try {
1029 externalRef = json(patch.toString());
1030 } catch (...) {
1031 throw JsonPatchTestFail(strf("Unable to load reference asset: {}", patch.toString()));
1032 }
1033 break;
1034 default:
1035 throw JsonPatchException(strf("Patch data is wrong type: {}", Json::typeName(patch.type())));
1036 break;
1037 }
1038 }
1039 return newResult;
1040}
1041
1042Json Assets::readJson(String const& path) const {
1043 ByteArray streamData = read(path);

Callers

nothing calls this directly

Calls 9

errorFunction · 0.85
applyOperationFunction · 0.85
strfFunction · 0.85
toArrayMethod · 0.80
valueMethod · 0.45
typeMethod · 0.45
metadataMethod · 0.45
whatMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected