James K wrote:
Guilherme Maia wrote:
> James K wrote:
> > I’ve just tried it with another file, this time a .rtf file and it’s not reaching the end of this file either!
> >
> > Is this a bug or have I missed a parameter somewhere?!
>
> I updated to latest version of cocos2d-x (cocos2d-2.1beta3-x-2.1.0) but the problem continues. The variable fileSize stores the correct file size, but not all data is retrieved by getFileData…
>
> As I’m loading from a JSON, I decided to use a c*+ string to store it while this problem is not solved, but it’s extremely counter-intuitive and will slow-down updates, but now it works for me…
>
Do you have any example code as to how your using the C*+ string?
>
I’m still struggling with this, I’ve found I can read in large text files fine, it’s just reading in the sqlite file that’s causing the issue. I’m running on iOS at the minute (though Android is the same). I suspect it’s because the sqlite file is not plain text that the issue is occuring, but I don’t know if there’s anything I can change - I’ve set the read type to binary. I’ve tried upgrading to the latest Beta version (cocos2d-2.1beta3-x-2.1.1) of cocos2dx as well, with no change.
>
[…]
My problem is slightly different from yours as I’m basically trying to load a text file holding a JSON object, not binary data, but here’s how i’m using it:
My JSON Object
static const char s_LanguagesJson[] = "{\
\"en\" : {\
\"ln\" : \"English\",\
\"language\" : \"Language\",\
\"score\" : \"Score\",\
\"timeLeftTotal\" : \"Time Left\",\
\"timeLeftRune\" : \"Rune Time Left\",\
\"totalTime\" : \"Total Time\",\
\"finish\" : \"Finished!\",\
\"gameFinished\" : \"Game Finished!\",\
\"next\" : \"Next\",\
\"restart\" : \"Restart\",\
\"clean\" : \"Clean\",\
\"accuracy\" : \"Accuracy\",\
\"exitQuestion\" : \"Do you really want to exit?\",\
\"exitTitle\" : \"Exit\",\
\"arcadeTitle\" : \"Arcade Mode\",\
\"writerTitle\" : \"Writer Mode\",\
\"optionsTitle\" : \"Options\",\
\"arcadeInfo\" : \"In Arcade Mode you have 60s to draw as many Runes as you can!\",\
\"writerInfo\" : \"In Writer Mode you must draw the runes with maximum accuracy!\",\
\"writerPassRuneInfo\" : \"Required Accuracy to change to next Rune\",\
\"yes\" : \"Yes\",\
\"no\" : \"No\",\
\"musicVolume\" : \"Music Volume\",\
\"sfxVolume\" : \"SFX Volume\",\
\"creditsTitle\" : \"Credits\",\
\"creditsInfo\" : \"Rune Maker\\nMr. Studios\\n\\nGraphics Designers\\nGyokusho (Gustavo Campedelli)\\nTakeshi (Ricardo Garcia)\\n\\nProgrammer\\nChaoseiro (Guilherme Maia)\\n\\nSound Designer\\nDip (Gabriel de Paula)\\n\\nTester\\nReddoRY (Gabriel Kiesshau)\\n\\nThanks for Playing!\",\
\"lastHighscore\" : \"Highscore\",\
\"finalScore\" : \"Final Score\",\
\"replay\" : \"Play Again\",\
\"pauseTitle\" : \"Paused\",\
\"resume\" : \"Resume\",\
\"quitMenu\" : \"Quit to Menu\"\
}\
}";
My Class which return data based on the loaded JSON:
/*
* File: LanguageClass.cpp
* Author: guilherme
*
* Created on January 23, 2013, 6:18 PM
*/
#include "LanguageClass.h"
#include "cocos2d.h"
#include "ResourcesPaths.h"
USING_NS_CC;
using namespace LikeASir;
using namespace rapidjson;
Document LanguageClass::languagesDocument;
const char* LanguageClass::s_chosenLanguage = "pt";
LanguageClass* LanguageClass::s_languageClass = 0;
void LanguageClass::getLanguages(std::vector& langs) const {
langs.clear();
for(Value::ConstMemberIterator it = languagesDocument.MemberBegin(); it != languagesDocument.MemberEnd(); ++it) {
if(DEBUG) CCLog("Pushed %s", it->name.GetString());
langs.push_back(it->name.GetString());
}
}
void LanguageClass::setLanguage(const char* newLang) {
for(Value::ConstMemberIterator it = languagesDocument.MemberBegin(); it != languagesDocument.MemberEnd(); ++it) {
if(strcasecmp(it->name.GetString(), newLang) == 0) {
LanguageClass::s_chosenLanguage = newLang;
CCUserDefault::sharedUserDefault()->setStringForKey("language", newLang);
return;
}
}
}
void LanguageClass::loadLanguages() {
if(DEBUG)
CCLog("Loading Languages file...");
std::string chosenLanguage = CCUserDefault::sharedUserDefault()->getStringForKey("language", "en");
s_chosenLanguage = chosenLanguage.c_str();
// Parse Languages Document
if(languagesDocument.Parse<0>(s_LanguagesJson).HasParseError()) {
if(DEBUG) {
CCLog(languagesDocument.GetParseError());
}
}
if(DEBUG) {
if(!languagesDocument.HasMember(chosenLanguage.c_str())) {
CCLog("Language '%s' is not supported.", chosenLanguage.c_str());
} else {
CCLog("Languages Loaded.");
}
for(Value::ConstMemberIterator it = languagesDocument.MemberBegin(); it != languagesDocument.MemberEnd(); ++it) {
CCLog(it->name.GetString());
for(Value::ConstMemberIterator it2 = it->value.MemberBegin(); it2 != it->value.MemberEnd(); ++it2) {
CCLog("%s = %s", it2->name.GetString(), it2->value.GetString());
}
}
}
}
const char* LanguageClass::getStringFromKey(const char* key) {
for(Value::ConstMemberIterator it = languagesDocument.MemberBegin(); it != languagesDocument.MemberEnd(); ++it) {
if(strcasecmp(it->name.GetString(), CCUserDefault::sharedUserDefault()->getStringForKey("language", "en").c_str()) == 0) {
for(Value::ConstMemberIterator it2 = it->value.MemberBegin(); it2 != it->value.MemberEnd(); ++it2) {
if(strcasecmp(it2->name.GetString(), key) == 0) {
return (it2->value.GetString());
}
}
}
}
return "NULL";
}
LanguageClass::LanguageClass() {
loadLanguages();
}
LanguageClass* LanguageClass::sharedLanguageClass() {
if(!s_languageClass) {
s_languageClass = new LanguageClass();
}
return s_languageClass;
}