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

Method parseFramesSpecification

source/base/StarAssets.cpp:668–759  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

666}
667
668FramesSpecification Assets::parseFramesSpecification(Json const& frameConfig, String path) {
669 FramesSpecification framesSpecification;
670
671 framesSpecification.framesFile = std::move(path);
672
673 if (frameConfig.contains("frameList")) {
674 for (auto const& pair : frameConfig.get("frameList").toObject()) {
675 String frameName = pair.first;
676 RectU rect = RectU(jsonToRectI(pair.second));
677 if (rect.isEmpty())
678 throw AssetException(
679 strf("Empty rect in frame specification in image {} frame {}", framesSpecification.framesFile, frameName));
680 else
681 framesSpecification.frames[frameName] = rect;
682 }
683 }
684
685 if (frameConfig.contains("frameGrid")) {
686 auto grid = frameConfig.get("frameGrid").toObject();
687
688 Vec2U begin(jsonToVec2I(grid.value("begin", jsonFromVec2I(Vec2I()))));
689 Vec2U size(jsonToVec2I(grid.get("size")));
690 Vec2U dimensions(jsonToVec2I(grid.get("dimensions")));
691
692 if (dimensions[0] == 0 || dimensions[1] == 0)
693 throw AssetException(strf("Image {} \"dimensions\" in frameGrid cannot be zero", framesSpecification.framesFile));
694
695 if (grid.contains("names")) {
696 auto nameList = grid.get("names");
697 for (size_t y = 0; y < nameList.size(); ++y) {
698 if (y >= dimensions[1])
699 throw AssetException(strf("Image {} row {} is out of bounds for y-dimension {}",
700 framesSpecification.framesFile,
701 y + 1,
702 dimensions[1]));
703 auto rowList = nameList.get(y);
704 if (rowList.isNull())
705 continue;
706 for (unsigned x = 0; x < rowList.size(); ++x) {
707 if (x >= dimensions[0])
708 throw AssetException(strf("Image {} column {} is out of bounds for x-dimension {}",
709 framesSpecification.framesFile,
710 x + 1,
711 dimensions[0]));
712
713 auto frame = rowList.get(x);
714 if (frame.isNull())
715 continue;
716 auto frameName = frame.toString();
717 if (!frameName.empty())
718 framesSpecification.frames[frameName] =
719 RectU::withSize(Vec2U(begin[0] + x * size[0], begin[1] + y * size[1]), size);
720 }
721 }
722 } else {
723 // If "names" not specified, use auto naming algorithm
724 for (size_t y = 0; y < dimensions[1]; ++y)
725 for (size_t x = 0; x < dimensions[0]; ++x)

Callers

nothing calls this directly

Calls 15

jsonToRectIFunction · 0.85
strfFunction · 0.85
jsonToVec2IFunction · 0.85
jsonFromVec2IFunction · 0.85
toStringFunction · 0.85
toObjectMethod · 0.80
objectPtrMethod · 0.80
containsMethod · 0.45
getMethod · 0.45
isEmptyMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected