Problem loading plist with array of arrays

Problem loading plist with array of arrays
0.0 0


Hi all,

I’m continuing my prototype using cocos2d-x airplay (cocos2d-0.99.5-x-0.8.2) and I’m currently trying to port the loading of the data from the excellent PhysicsEditor to make work with Box2D even easier.

I load a plist using the following code:

const char pszPath = CCFileUtils::fullPathFromRelativePath;
CCDictionary<std::string, CCObject
* dictionary = CCFileUtils::dictionaryWithContentsOfFile(pszPath);

but it fails in CCFileUtils_airplay.cpp - endElement CCAssert(m_bInArray, "The plist file is wrong!"); because the data from PhysicsEditor has an array of arrays in it but the plist parsing uses a single m_pArray variable and doesn’t stack them like the dict’s.

The plist at the point it fails looks like this:


            { 0.000,40.000 }
            { 0.000,0.000 }
            { 256.000,-2.000 }
            { 255.000,33.000 }

            { 20.000,80.000 }
            { 20.000,20.000 }
            { 266.000,-5.000 }
            { 265.000,67.000 }

Does anybody know if this is likely to be fixed any time soon?

Thanks in advance



Hi James,

I’m facing the same problem. As a cocos2d-iPhone and iOS deveoper before, I expected the CCFileUtils::dictionaryWithContentsOfFile(const char *) func behaves the same as NSDictionary’s dictionaryWithContentsOfFile method in iOS platform.

It’s a pity that coco2s-x’s plist parsing cannot do this. So my suggestion is:
If you need to make a series of complicated webservice, you have to implemented the parsing job yourself using libxml2.
If you just want to load some configuration files, consider changing the file format, otherwise you have to do the parsing job.

I have requested to @walzer informally in our QQ group, but it seams to be not in the recent roadmap.



You can convert the plist file into other format such as csv, each line represents a single pologon, and write a simple reader for that format.

0.000, 40.000, 0.000, 0.000, 256.000, ~~2.000, 256.000,~~2.000, 255.000, 33.000 /* The 1st pologon*/
20.000, 80.000, 20.000, 20.000, 266.000, –5.000, 265.000, 67.000 /
* The 2nd pologon*/

If you can’t change the plist configuration tool, you can convert the plist format to csv(or other formats you like) by adding a RunScript build phase in Xcode.

I think a simple python or bash script could handle it. (I recommend python plistlib)