ILInt64 VBTime(ILInt64 hour, ILInt64 minute, ILInt64 second, int ampm) { /* Validate the parameters */ if(ampm == VB_TIME_UNSPEC) { if(hour < 0 || hour > 23) { CCError(_("invalid hour value")); hour = 0; } } else if(ampm == VB_TIME_AM) { if(hour < 1 || hour > 12) { CCError(_("invalid hour value")); hour = 0; } else if(hour == 12) { hour = 0; } } else { if(hour < 1 || hour > 12) { CCError(_("invalid hour value")); hour = 12; } else if(hour != 12) { hour += 12; } } if(minute < 0 || minute > 59) { CCError(_("invalid minute value")); minute = 0; } if(second < 0 || second > 59) { CCError(_("invalid second value")); second = 0; } /* Build the final tick value */ return (hour * 3600 + minute * 60 + second) * TicksPerSecond; }
bool StoryDataCenter::SplitPosFromContent(std::string content,float &posx,float &posy) { if (content == "") { return false; } int startPos = content.find("("); int midPos = content.find(","); int endPos = content.find(")"); if (std::string::npos == startPos || std::string::npos == midPos || std::string::npos == endPos ) { CCError("StoryDataCenter::SplitPosFromContent() %s format error ",content.c_str()); return false; } std::string posx_content = content.substr(startPos+1,midPos-startPos-1); posx = atof(posx_content.c_str()); posx = posx*16; std::string posy_content = content.substr(midPos+1,endPos-midPos-1); posy = atof(posy_content.c_str()); posy = posy*16; return true; }
bool LuaTinkerManager::checkAnyLoadFile(string filePath) { if (loadedFiles.find(filePath) == loadedFiles.end()) { const char *path = GameResourceManager::sharedManager()->storedFullPathFromRelativePath(filePath.c_str()); unsigned long fileSize = 0; unsigned char* buffer = CCFileUtils::sharedFileUtils()->getFileData(path, "rt", &fileSize); //int ret = luaL_dostringEx(this->curLuaState, (char*)buffer,fileSize); int ret = (luaL_loadbuffer(this->curLuaState, (char*)buffer, fileSize, (char*)buffer) || lua_pcall(this->curLuaState, 0, LUA_MULTRET, 0)); delete(buffer); if (ret != 0) { CCError("load %s file error: %s", filePath.c_str(), lua_tostring(this->curLuaState, -1)); lua_pop(this->curLuaState, 1); return false; } loadedFiles.insert(filePath); return true; } return true; }
bool GameConfigFromLuaManager::checkCommonDefineContent() { if (!this->m_isLoadCommonDefineData) { const char *path = GameResourceManager::sharedManager() ->storedFullPathFromRelativePath("Script/CommonDefine.lua"); //#ifndef ANDROID // int ret = luaL_dofile(this->m_configLuaState, path); //#else unsigned long fileSize = 0; unsigned char* buffer = CCFileUtils::sharedFileUtils()->getFileData(path, "rt", &fileSize); int ret = luaL_dostringEx(this->m_configLuaState, (char*)buffer, fileSize); //#endif if (ret != 0) { CCError("load checkCommonDefineContent name config file error:%s", lua_tostring(this->m_configLuaState, -1)); lua_pop(this->m_configLuaState, 1); return false; } #ifndef RELOAD_LUA_FILES this->m_isLoadCommonDefineData = true; #endif return true; } return true; }
ILInt64 VBDate(ILInt64 month, ILInt64 day, ILInt64 year, int yearDigits) { ILInt64 result; /* Validate the parameters */ if(year >= 0 && year < 100 && yearDigits <= 2) { if(year < 30) { year += 2000; } else { year += 1900; } } if(year < 1 || year > 9999) { CCError(_("invalid year value")); year = 1; } if(month < 1 || month > 12) { CCError(_("invalid month value")); month = 1; } if(day < 1 || day > DaysInMonth(year, month)) { CCError(_("invalid day value")); day = 1; } /* Build the final tick value */ result = YearToDays(year); result += daysBeforeMonth[(int)(month - 1)]; if(month > 2 && IsLeapYear(year)) { ++result; } return (result + (day - 1)) * TicksPerDay; }
BloodBar* SpriteDecorationBatchNode::CreateBloodBar(CCNode* pNode) { BloodBar* pBloodBar = NULL; if (pNode) { std::map<CCNode*,BloodBar*>::iterator iter = m_playerBloodBars.find(pNode); if (iter == m_playerBloodBars.end()) { SpriteHeroBase* pHeroNode = dynamic_cast<SpriteHeroBase*>(pNode); if (pHeroNode) { pBloodBar = new BloodBar(); pBloodBar->m_bgFrame = CCSprite::createWithSpriteFrameName("monster_blood_frame.png"); pBloodBar->m_frFrame = CCSprite::createWithSpriteFrameName("monster_blood_piece.png"); if (pBloodBar->m_bgFrame && pBloodBar->m_frFrame) { m_batchNode->addChild(pBloodBar->m_bgFrame); m_batchNode->addChild(pBloodBar->m_frFrame); if (pHeroNode->GetBattleSide() == SpriteHeroBase::LEFT) { pBloodBar->m_frFrame->setAnchorPoint(ccp(0,0.5)); } else { pBloodBar->m_frFrame->setAnchorPoint(ccp(1,0.5)); } CCSize bgFrameSize = pBloodBar->m_bgFrame->getContentSize(); CCSize frFrameSize = pBloodBar->m_frFrame->getContentSize(); pBloodBar->m_fDefaultXScale = bgFrameSize.width / frFrameSize.width; pBloodBar->m_frFrame->setScaleX(pBloodBar->m_fDefaultXScale); pBloodBar->m_frFrame->setScaleY(bgFrameSize.height / frFrameSize.height); m_playerBloodBars.insert(std::make_pair(pNode,pBloodBar)); } else { CC_SAFE_DELETE(pBloodBar); } } } else { CCError("SpriteDecorationBatchNode::CreateOneBloodBar repeat key"); } } return pBloodBar; }
CCSprite* SpriteDecorationBatchNode::CreateShadow(CCNode* pNode) { CCSprite* pShadowSprite = NULL; if (pNode) { std::map<CCNode*,CCSprite*>::iterator iter = m_playerShadows.find(pNode); if (iter == m_playerShadows.end()) { pShadowSprite = CCSprite::createWithSpriteFrameName("shadow.png"); if (pShadowSprite) { m_shadowBatchNode->addChild(pShadowSprite); m_playerShadows.insert(std::make_pair(pNode,pShadowSprite)); } } else { CCError("SpriteDecorationBatchNode::CreateShadow repeat key"); } } return pShadowSprite; }
void CLexUsingDirective(const char *text) { int endquote, len; char *filename; while(*text != '\0' && *text != '"' && *text != '<') { ++text; } if(*text == '"') { endquote = '"'; } else if(*text == '<') { endquote = '>'; } else { return; } ++text; len = 0; while(text[len] != '\0' && text[len] != endquote) { ++len; } filename = ILDupNString(text, len); if(!filename) { CCOutOfMemory(); } if(!CCLoadLibrary(filename)) { CCError(_("could not load the assembly `%s'"), filename); } ILFree(filename); }
bool StoryDataCenter::ReadOneXmlItem(TiXmlElement* pElement) { if (pElement == 0) { return false; } unsigned int taskID = 0; StroyData storyData; // Note: Parse TaskID TiXmlAttribute* pAttribute = pElement->FirstAttribute(); while(pAttribute) { std::string strName(pAttribute->Name()); std::string content = pElement->Attribute(strName.c_str()); if (strName == "task_ID") { unsigned int task_id = atoi(content.c_str()); taskID = task_id; storyData.setTaskId(task_id); } else if (strName == "instance_ID") { unsigned int task_id = atoi(content.c_str()); taskID = task_id; storyData.setTaskId(task_id); } else if (strName == "map_ID") { unsigned int map_id = atoi(content.c_str()); storyData.setMapId(map_id); } else if (strName == "camera") { float posx = 0; float posy = 0; if (SplitPosFromContent(content,posx,posy)) { storyData.setCameraPos(ccp(posx,posy)); } } else if (strName == "end_frame") { int endFrame = atoi(content.c_str()); storyData.setEndFrame(endFrame); } else if (strName == "when") { int nWhen = atoi(content.c_str()); storyData.setHappendAtWhen(nWhen); } else if (std::string::npos != strName.find("set_role_position_")) { unsigned int roleIndex = 0; if (SplitRoleID(strName,roleIndex)) { std::vector<std::string> vecContent; SplitContent(content,vecContent); size_t vecSize = vecContent.size(); for (size_t index = 0;index<vecSize;index++) { unsigned int frameIndex = 0; float posx = 0; float posy = 0; if(SplitFrameAndPosFromContent(vecContent[index],frameIndex,posx,posy)) { storyData.InsertRolePosAtFrame(roleIndex,frameIndex,ccp(posx,posy)); } } } } else if (std::string::npos != strName.find("set_role_act_")) { unsigned int roleIndex = 0; if (SplitRoleID(strName,roleIndex)) { std::vector<std::string> vecContent; SplitContent(content,vecContent); size_t vecSize = vecContent.size(); for (size_t index = 0;index<vecSize;index++) { unsigned int frameIndex = 0; int actorId = 0; if (SplitFrameAndActorIdFromContent(vecContent[index],frameIndex,actorId)) { storyData.InsertRoleActorAtFrame(roleIndex,frameIndex,actorId); } } } } else if (std::string::npos != strName.find("role_dialog_")) { unsigned int roleIndex = 0; if (SplitRoleID(strName,roleIndex)) { std::vector<unsigned int> vecFrameIndex; std::vector<std::string> vecTextId; if (SplitFrameAndTextIdFromContent(content,vecFrameIndex,vecTextId)) { size_t count = vecFrameIndex.size(); for (size_t index = 0;index<count;index++) { storyData.InsertDialogTextIdAtFrame(roleIndex,vecFrameIndex[index],vecTextId[index]); } } } } else if (std::string::npos != strName.find("set_role_flip_")) { unsigned int roleIndex = 0; if (SplitRoleID(strName,roleIndex)) { std::vector<std::string> vecContent; SplitContent(content,vecContent); size_t vecSize = vecContent.size(); for (size_t index = 0;index<vecSize;index++) { unsigned int nFrame = 0; int nFlip = 0; if (SplitFrameAndActorIdFromContent(vecContent[index],nFrame,nFlip)) { storyData.InsertIsFlipAtFrame(roleIndex,nFrame,nFlip); } } } } else if (std::string::npos != strName.find("set_role_icon_")) { unsigned int roleIndex = 0; if (SplitRoleID(strName,roleIndex)) { storyData.SetRoleLeftIcon(roleIndex,content); } } else if (std::string::npos != strName.find("role_")) { unsigned int roleIndex = 0; if (SplitRoleID(strName,roleIndex)) { unsigned int roleId = 0; roleId = atoi(content.c_str()); //if (roleId == 0) //{ // roleId = UserData::Get()->getUserId(); //} storyData.SetRoleIdAtIndex(roleIndex,roleId); } } else { CCError("StoryDataCenter::ReadOneXmlItem() %s attribute undefined ",strName.c_str()); } pAttribute = pAttribute->Next(); } if (taskID != 0) { mVecTaskIdAndStoryData.push_back(storyData); //bool bHasSameId = false; //for (std::vector<StroyData>::iterator iter = mVecTaskIdAndStoryData.begin(); // iter != mVecTaskIdAndStoryData.end(); iter++) //{ // unsigned int id = (*iter).getTaskId(); // if (id == taskID) // { // bHasSameId = true; // break; // } //} //if (false == bHasSameId) //{ // mVecTaskIdAndStoryData.push_back(storyData); //} //else //{ // CCError("ERROR: mVecTaskIdAndStoryData repeat key %d",taskID); //} } return true; }