示例#1
0
void SkillsInfo::initWithSkillId(int skillId){
    CSJson::Reader reader;
    CSJson::Value root;
    CCString  * str= CCString::createWithContentsOfFile(SKILLJSONNAME);
    CCLOG("%s",str->getCString());
    if (reader.parse(str->getCString(), root)) {
        CSJson::Value data=root["data"];
        CSJson::Value row=data["row"];
        char skillname[20]="";
        sprintf(skillname, "%d",skillId);
        CSJson::Value skilldata=data[skillname];
        m_skillTypeId=skilldata[SKILLTYPE].asInt();
        m_skillCrp=skilldata[SKILLCRP].asInt();
        m_skillCri=skilldata[SKILLCRI].asInt();
        m_skillScript=skilldata[SKILLSCRIPT].asString().c_str();
        m_skillBuffid=skilldata[SKILLBUFFID].asInt();
        gold=skilldata[SKILLGOLD].asInt();
        nextid=skilldata[SKILLNEXTID].asInt();
        moveeffect=skilldata[SKILLMOVEEFFECT].asInt();
        m_skillTimes=skilldata[SKILLTIMES].asFloat();
        m_skillRange=skilldata[SKILLRANGES].asInt();
        CCLog("%d",m_skillRange);
        attackeffect=skilldata[SKILLATTACKEFFECT].asInt();
        passiveeffect=skilldata[SKILLPASSIVEEFFECT].asInt();
        m_skillCounts=skilldata[SKILLCOUNTS].asInt();
        m_skillName=skilldata[SKILLNAME].asString().c_str();
    }
}
示例#2
0
void LoginScene::recvLoginData()
{
    Message * msg= (Message *)GameData::shareGameData()->dic->objectForKey(1001);
    if(msg){
        this->unschedule(schedule_selector(LoginScene::recvLoginData));
        GameData::shareGameData()->dic->removeObjectForKey(1001);
        CSJson::Reader reader;
        CSJson::Value root;
        if (reader.parse(msg->getContent(), root))
        {
            int uid = root["uid"].asInt();
            if (uid > 0)
            {
                GameData::shareGameData()->userID=uid;
                CCScene * scene= MainLayer::scene();
                //  this->addChild(scene,10);
                CCDirector::sharedDirector()->replaceScene(scene);
            }
            else
            {
                CCMessageBox(UiLanguage::shareLanguage()->get("password_error"), UiLanguage::shareLanguage()->get("msgbox_notice"));
            }
        }
    }

}
示例#3
0
void shop::initBag(){
    CSJson::Reader reader;
    CSJson::Value root;
    if (reader.parse(GameData::shareGameData()->bagData, root)) {
        bool result=root["result"].asBool();
        if (result) {
            CSJson::Value data;
            data=root["data"];
            for (int i=0; i<data.size(); i++) {
                CCLog("%d",data[i].asInt());
                if (i<12) {
                    buySkill[i]=data[i].asInt();
                    arrTag=i;
                    UIButton * btn= dynamic_cast<UIButton *>(layer->getWidgetByTag(9+i));
                    btn->addPushDownEvent(this, coco_pushselector(shop::touchBeganEvent0));
                    btn->addMoveEvent(this, coco_moveselector(shop::touchMovedEvent0));
                    btn->addReleaseEvent(this, coco_moveselector(shop::touchEndedEvent0));
                    
                    char name[20]="";
                    sprintf(name, "skill-%02d.png",i+1);
                    btn->loadTextures(name, name, name);
                    btn->setVisible(true);
                }
            }
        }
    }
}
示例#4
0
void CJsonPacker::readDescription(const char *pszDescription)
{
    CSJson::Reader cReader;
    if (pszDescription && *pszDescription)
    {
        std::string strValue = pszDescription;
        cReader.parse(strValue, m_cValue, false);
    }
}
bool CJsonHelper::getJsonFromString(const char* pszData,CSJson::Value& Val)
{
	CSJson::Reader reader;  
	CSJson::Value jsValue;
	//这里将pBuffer的值付给jsValue值
	bool parseRet = reader.parse(pszData, jsValue, false);
	Val = jsValue;
	//CCAssert(parseRet, "Read JsonData Error~!!!!!!!!!");
	return parseRet; 
}
示例#6
0
void CommonHttpResponseCallBack::onResponseJsonNoCache(CAHttpClient* client, CAHttpResponse* response)
{
    CommonHttpManager::getInstance()->stopActivityIndicatorView();
    
    CC_RETURN_IF(!m_pSelectorJson);
    if (response->isSucceed())
    {
        std::string data(response->getResponseData()->begin(), response->getResponseData()->end());
        if (!data.empty())
        {
            if (CAViewController* viewController = dynamic_cast<CAViewController*>(m_pTarget))
            {
                CC_RETURN_IF(viewController->isViewRunning() == false);
            }
            
            CCLog("\n \n \n---------HttpResponse--json---------\n<<<\n%s\n>>>\n--------------END--------------\n \n \n",data.c_str());
            
            CSJson::Reader read;
            CSJson::Value root;
            bool succ = read.parse(data, root);
            if (succ == false)
            {
                CCLog("GetParseError \n");
            }
            
            if (m_pTarget)
            {
                (m_pTarget->*m_pSelectorJson)(HttpResponseSucceed, root);
            }
        }
        else
        {
            CSJson::Value root;
            if (m_pTarget)
            {
                (m_pTarget->*m_pSelectorJson)(HttpResponseFaild, root);
            }
        }
        
    }
    else
    {
        CSJson::Value root;
        if (m_pTarget)
        {
            (m_pTarget->*m_pSelectorJson)(HttpResponseFaild, root);
        }
    }
}
示例#7
0
vector<CAAddressBookRecord> getAddressBook()
{
    if (_addressBookArr.size() > 0 )
    {
        return _addressBookArr;
    }
    
    CSJson::Reader read;
    CSJson::Value root;
    
    if (read.parse(ShowAddress(), root))
    {
        CSJson::Value personlist;
        personlist = root["person"];
        
        for (int i=0; i<personlist.size(); i++)
        {
            CSJson::Value person;
            person = personlist[i];
            CAAddressBookRecord addrec;
            
            addrec.fullname = person["name"].asString();
            
            CSJson::Value phonelist = person["phone"];
            
            for (int i=0; i<1; i++)
            {
                addrec.phoneNumber = phonelist[i].asString();
            }
            
            addrec.email = person["email"].asString();
            
            addrec.street = person["address_street"].asString();
            
            addrec.province = person["address_region"].asString();
            
            addrec.city = person["address_city"].asString();
            
            addrec.nickname = person["nickname"].asString();
            
            addrec.zip = person["address_postCode"].asString();
            
            _addressBookArr.push_back(addrec);
            
        }
    }

    return _addressBookArr;
}
示例#8
0
CCDictionary* CAUIHelper::createCAWidgetWithJsonFile(const char *filename)
{
    std::string fullpath= CCFileUtils::sharedFileUtils()->fullPathForFilename(filename);
    CCLog("%s",fullpath.c_str());
    unsigned long size = 0;
    char *des = (char*) CCFileUtils::sharedFileUtils()->getFileData(filename, "r", &size);
    CSJson::Reader reader;
    CSJson::Value root;
    CSJson::Value description;
    CSJson::Value rect;
    CCObject *ui = new CCObject();
    
    if (!reader.parse(des, root))
    {
        CCLog("error");
        return NULL;
    }
    CCLog("%s",des);
    for (int i = 0; i<root.size(); i++)
    {
        description = root[i];
        CAType type = (CAType)description["typeMode"].asInt();
        rect = description["rect"];
        std::string name = description["name"].asString();
        float width = rect["width"].asFloat();
        float height = rect["height"].asFloat();
        float x = rect["x"].asFloat();
        float y = rect ["y"].asFloat();
        CCRect uirect = CCRectMake(x, y, width, height);
        // ui=CAButton::createWithFrame(CCRectMake(x, y, width, height));
        if (type == CATypeButton)
        {
            ui = addButton(description, uirect);
        }
        else if(type == CATypeLabel)
        {
            ui = addLabel(description, uirect);
        }
        else if(type == CATypeImage)
        {
            
        }
        m_UIDictionary->setObject(ui, name.c_str());
        
    }
    ui->release();
    return m_UIDictionary;
}
示例#9
0
void GameOver::setData(const char *data){
    CCLog("%s",data);
    CSJson::Reader reader;
    CSJson::Value root;
    if(reader.parse(data, root)){
        CSJson::Value sData;
        sData=root["data"];
        CCLog("%d",sData["battleResult"].asInt());
        CSJson::Value setData;
        setData=sData["setData"];
        int star=setData["star"].asInt();
        char starnum[10]="";
        sprintf(starnum, "星级为:%d",star);
        //label1->setString(starnum);
    }
}
示例#10
0
void CAAddressManager::releaseJson(const char* json)
{
    CSJson::Reader read;
    CSJson::Value root;
    if (read.parse(json, root))
    {
        CSJson::Value personlist;
        
        personlist = root["person"];
        for (int i=0; i<personlist.size(); i++)
        {
            CSJson::Value person;
            person = personlist[i];
            CAAddressBookRecord *addrec = new CAAddressBookRecord();

            addrec->fullname = person["name"].asString();
            
            CSJson::Value phonelist = person["phone"];
            for (int i=0; i<1; i++) {
                

                    addrec->phoneNumber = phonelist[i].asString();
                    
                
            }

            addrec->email = person["email"].asString();

            addrec->street = person["address_street"].asString();

            addrec->province = person["address_region"].asString();

            addrec->city = person["address_city"].asString();

            addrec->nickname = person["nickname"].asString();
            
            addrec->zip = person["address_postCode"].asString();

            _addressBookArr.push_back(addrec);

        }
    }
}
示例#11
0
文件: user.cpp 项目: f17qh/crazyass
int RemoteUser::Load(const char *path) {
  char buf[512];
  memset(buf, 0, sizeof(buf));
  CAReadFile("userdata", buf, 512);
  if (strlen(buf) == 0) {
    CCLOG("read userdata faild.");
    return -1;
  }

  CSJson::Reader reader;
  CSJson::Value value;
  if (!reader.parse(std::string((char *)buf), value, false)) {
    CCLOG("parse %s error", path);
    return -1;
  }

  userid_ = value.get("userid", "").asString();
  CCLOG("userid %s", userid_.c_str());
  return 0;
}
示例#12
0
bool TouchGrabber::load(const std::string &filename)
{
    std::string doc = Assets::readTextFile(filename,false);
    CSJson::Reader reader;
    CSJson::Value root;
    if (reader.parse(doc, root) == false) {
        CCLOGERROR("ERROR: can't parse JSON touch data file %s",filename.c_str());
        return false;
    }
    mTouchesRecVector.clear();
    for (const CSJson::Value &value : root) {
        TouchRecord rec;
        rec.x = value["x"].asFloat();
        rec.y = value["y"].asFloat();
        rec.event = (TouchEvent)value["event"].asInt();
        rec.time = value["time"].asFloat();
        mTouchesRecVector.push_back(rec);
    }
    return true;
}
示例#13
0
void shop::initLoadSkill(){
    CSJson::Reader reader;
    CSJson::Value root;
    if (reader.parse(GameData::shareGameData()->szData, root)) {
        CSJson::Value data;
        
        data=root["data"];
        int skill1=data["skill_1"].asInt();
        int skill2=data["skill_2"].asInt();
        if (skill1!=0) {
            UIButton * btn= dynamic_cast<UIButton *>(layer->getWidgetByTag(33));
            btn->loadTextures("skill-01.png", "skill-01.png", "skill-01.png");
            btn->setVisible(true);
            
        }else if(skill2!=0){
            UIButton * btn= dynamic_cast<UIButton *>(layer->getWidgetByTag(34));
            btn->loadTextures("skill-02.png", "skill-02.png", "skill-02.png");
        }
        
       // CCLog()
    }
}
void OnlineController::_onLeaderboardLoaded(CCHttpClient* client, CCHttpResponse* response)
{
    if (response->isSucceed())
    {
        CCLog("== leaderboard loading succseeded");
        m_leaderboardEntries.clear();

        CSJson::Reader reader;
        std::vector<char>* data = response->getResponseData();
        CSJson::Value value;
        const char* begin = &(*data)[0];
        const char* end = begin + data->size();
        reader.parse(begin, end, value, false);
        if (value.isArray())
        {
            for (CSJson::ArrayIndex i = 0; i < value.size(); ++i)
            {
                const CSJson::Value jsonEntry = value[i];
                LeaderboardEntry entry;
                entry.name = jsonEntry.get("display_name", "").asCString();
                entry.score = atoi(jsonEntry.get("score", "0").asCString());
                entry.rank = atoi(jsonEntry.get("rank", "0").asCString());
                m_leaderboardEntries.push_back(entry);
            }
        }
        SharedEventController::Instance().onLeaderboardLoaded();
        // schedule refresh
        CCDirector::sharedDirector()->getScheduler()->
            scheduleSelector(SEL_SCHEDULE(&OnlineController::_loadLeaderboard), this, s_leaderboardRefreshInterval, 0, 0, false);
    }
    else
    {
        CCLog("== leaderboard loading failed. Error: %s", response->getErrorBuffer());
        // schedule retry
        CCDirector::sharedDirector()->getScheduler()->
            scheduleSelector(SEL_SCHEDULE(&OnlineController::_loadLeaderboard), this, s_leaderboardRetryInterval, 0, 0, false);
    }
}
示例#15
0
文件: user.cpp 项目: f17qh/crazyass
int LocalUser::Load(const char *path) {
  CSJson::Reader reader;
  path_ = path;

  if (!CCFileUtils::sharedFileUtils()->isFileExist(std::string(path))) {
    return AddUser();
  }

  unsigned long size = 4096;
  unsigned char *buf = CCFileUtils::sharedFileUtils()->getFileData(path, "rb", &size);

  if (!reader.parse(std::string((char *)buf), root_, false)) {
    CCLOG("parse %s error", path);
    return -1;
  }

  stageid_ = root_.get("stage", 0).asInt();
  heart_ = root_.get("heart", 0).asInt();
  eventlock_ = root_["eventlock"];
  CCLOG("Tset %d %d", stageid_, heart_);
  delete buf;
  return 0;
}
示例#16
0
void CommonHttpResponseCallBack::onResponseJson(CAHttpClient* client, CAHttpResponse* response)
{
    CommonHttpManager::getInstance()->stopActivityIndicatorView();
    
    CC_RETURN_IF(!m_pSelectorJson);
    if (response->isSucceed())
    {
        std::string data(response->getResponseData()->begin(), response->getResponseData()->end());
        if (!data.empty())
        {
            localStorageSetItem(MD5(m_sUrl).md5().c_str(), data.c_str());
            
            if (CAViewController* viewController = dynamic_cast<CAViewController*>(m_pTarget))
            {
                CC_RETURN_IF(viewController->isViewRunning() == false);
            }
            
            //CCLog("\n \n \n---------HttpResponse--json---------\n<<<\n%s\n>>>\n--------------END--------------\n \n \n",data.c_str());
            
            CSJson::Reader read;
            CSJson::Value root;
            bool succ = read.parse(data, root);
            if (succ == false)
            {
                CCLog("GetParseError \n");
            }
            
            if (m_pTarget)
            {
                (m_pTarget->*m_pSelectorJson)(HttpResponseSucceed, root);
            }
        }
        else
        {
            if (CAViewController* viewController = dynamic_cast<CAViewController*>(m_pTarget))
            {
                CC_RETURN_IF(viewController->isViewRunning() == false);
            }
            
            CSJson::Value root;
            if (m_pTarget)
            {
                (m_pTarget->*m_pSelectorJson)(HttpResponseFaild, root);
            }
        }
        
    }
    else
    {
        if (CAViewController* viewController = dynamic_cast<CAViewController*>(m_pTarget))
        {
            CC_RETURN_IF(viewController->isViewRunning() == false);
        }
        
        const char* data = localStorageGetItem(MD5(m_sUrl).md5().c_str());

        do
        {
            CC_BREAK_IF(data == NULL);
            CSJson::Reader read;
            CSJson::Value root;
            bool succ = read.parse(data, root);
            if (succ == false)
            {
                CCLog("GetParseError \n");
                break;
            }
            
            if (m_pTarget)
            {
                (m_pTarget->*m_pSelectorJson)(HttpResponseSucceed, root);
            }
            return;
        }
        while (0);
        
        CSJson::Value root;
        if (m_pTarget)
        {
            (m_pTarget->*m_pSelectorJson)(HttpResponseFaild, root);
        }
    }
}
示例#17
0
std::string 
Reader::getFormattedErrorMessages() const
{
   std::string formattedMessage;
   for ( Errors::const_iterator itError = errors_.begin();
         itError != errors_.end();
         ++itError )
   {
      const ErrorInfo &error = *itError;
      formattedMessage += "* " + getLocationLineAndColumn( error.token_.start_ ) + "\n";
      formattedMessage += "  " + error.message_ + "\n";
      if ( error.extra_ )
         formattedMessage += "See " + getLocationLineAndColumn( error.extra_ ) + " for detail.\n";
   }
   return formattedMessage;
}


std::istream& operator>>( std::istream &sin, Value &root )
{
    CSJson::Reader reader;
    bool ok = reader.parse(sin, root, true);
    //JSON_ASSERT( ok );
    if (!ok) throw std::runtime_error(reader.getFormattedErrorMessages());
    return sin;
}


} // namespace CSJson