How to check whether the atlas file is standardized, for example, whether it is missing a certain part of the atlas.
UI colleagues in our company always commit Incorrect atlas file,Pictures always seem to be missing from the gallery。
I want use C runtime to check this,but i didn't find the most correct way.
How to check whether the atlas file is standardized?
To check whether an atlas file is standardized and not missing any parts in the C runtime, you can follow a two-step approach based on the provided contexts and the spine-c runtime documentation:
Load the Atlas: Use the
spAtlas_createFromFile
function to load the atlas from a file. This function will return0
if loading the atlas failed, which can be an initial indication of issues with the atlas file.spAtlas* atlas = spAtlas_createFromFile("myatlas.atlas", 0); if (atlas == 0) { // Handle error: Atlas file could not be loaded }
Check for Missing Regions: After loading the atlas, you can attempt to find specific regions using
spAtlas_findRegion
. If a region that is expected to be in the atlas cannot be found, it indicates that the atlas file might be missing parts or is not correctly formatted.spAtlasRegion* region = spAtlas_findRegion(atlas, "expectedRegionName"); if (region == NULL) { // Handle error: Expected region is missing from the atlas }
This approach allows you to programmatically check for the presence of expected regions in the atlas, helping to identify issues with incorrect or incomplete atlas files. Remember to replace "myatlas.atlas"
and "expectedRegionName"
with the actual file name and region names relevant to your project.
You can not do that in the .skel file, as it's a binary stream, which can only be read sequentially, plus it has a dependency on the atlas as you found out.
The same is kinda true for .json files, as you first have to load the entire file content, then parse it into a JSON in-memory structure, and traverse that to get the slots. However, you can do that without spSkeletonJson
, as it's just a run off the mill .json file. So, by reading the .json file, and then traversing the slots JSON nodes, you could achieve what you want.
That said, attachment information is not just contained in the slots, it's also contained in skins, so you'd have to traverse those as well.
What specific problem are you running into? From what I gather, you are trying to read a .skel file and that fails due to missing regions in the atlas? And you want to check that before actually loading a .skel? How do you create the .atlas files?
It doesn't (or should not crash). spSpineSkeleton_create()
will return an error with the description, which you can output in your "checker tool" that you can integrate with a Git hook.
If you just need a list of slots, you could use eg:
spine -u 4.2 -i project.spine
This isn't enough to validate the atlas has all regions though, as Mario mentioned.
Your tool that uses the runtimes to do it is a good solution.