123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- #include "stdafx.h"
- #include "tinyxml2/tinyxml2.h"
- #include "LuaCfgHelper.h"
- #include <iostream>
- #include <boost/algorithm/string.hpp>
- #include "Fish_FishCFG.h"
- std::auto_ptr<Fish_FishCFG> Fish_FishCFG::msSingleton(nullptr);
- int Fish_FishCFG::GetCount()
- {
- return (int)mMapData.size();
- }
- const Fish_FishCFGData* Fish_FishCFG::GetData(int ID)
- {
- auto it = mMapData.find(ID);
- if (it != mMapData.end())
- {
- return &it->second;
- }
- return NULL;
- }
- const std::map<int, Fish_FishCFGData>& Fish_FishCFG::GetMapData()
- {
- return mMapData;
- }
- void Fish_FishCFG::Load()
- {
- tinyxml2::XMLDocument xmlDoc;
- std::string content = FileUtils::getInstance()->getStringFromFile("Config/Fish_FishCFG.xml");
- auto result = xmlDoc.Parse(content.c_str(), content.length());
- if (result != tinyxml2::XML_SUCCESS)
- {
- CCLOGERROR("Result:%d", result);
- CCASSERT(false, "result != tinyxml2::XML_SUCCESS");
- return;
- }
- auto root = xmlDoc.RootElement();
- if (root == NULL)
- {
- CCASSERT(false, "root == NULL");
- return;
- }
- auto element = root->FirstChildElement("Data");
- while (element != NULL)
- {
- Fish_FishCFGData data;
- data.mID = element->IntAttribute("ID");
- data.mFishName = element->Attribute("FishName");
- data.mModelID = element->IntAttribute("ModelID");
- data.mScore = element->IntAttribute("Score");
- data.mFishPoints = element->IntAttribute("FishPoints");
- {
- const char* Dimensity = element->Attribute("Dimensity");
- std::vector<std::string> vecDimensity;
- boost::split(vecDimensity, Dimensity, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecDimensity.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecDimensity[i].c_str(), &temp))
- {
- data.mDimensity.push_back(temp);
- }
- }
- }
- data.mType = element->IntAttribute("Type");
- data.mDropGem = element->IntAttribute("DropGem");
- data.mShowRadius = element->IntAttribute("ShowRadius");
- data.mLayer = element->IntAttribute("Layer");
- data.mCanNetHit = element->BoolAttribute("CanNetHit");
- {
- const char* ServerDieParam = element->Attribute("ServerDieParam");
- std::vector<std::string> vecServerDieParam;
- boost::split(vecServerDieParam, ServerDieParam, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecServerDieParam.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecServerDieParam[i].c_str(), &temp))
- {
- data.mServerDieParam.push_back(temp);
- }
- }
- }
- {
- const char* DieEffectParam = element->Attribute("DieEffectParam");
- std::vector<std::string> vecDieEffectParam;
- boost::split(vecDieEffectParam, DieEffectParam, boost::is_any_of(","));
- float temp;
- for (unsigned int i = 0; i < vecDieEffectParam.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToFloat(vecDieEffectParam[i].c_str(), &temp))
- {
- data.mDieEffectParam.push_back(temp);
- }
- }
- }
- data.mDieEffect = element->IntAttribute("DieEffect");
- data.mShockScreen = element->BoolAttribute("ShockScreen");
- data.mDropGold = element->IntAttribute("DropGold");
- data.mEffectType = element->IntAttribute("EffectType");
- data.mGoldPlate = element->IntAttribute("GoldPlate");
- data.mScreenPlate = element->IntAttribute("ScreenPlate");
- {
- const char* DieSoundID = element->Attribute("DieSoundID");
- std::vector<std::string> vecDieSoundID;
- boost::split(vecDieSoundID, DieSoundID, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecDieSoundID.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecDieSoundID[i].c_str(), &temp))
- {
- data.mDieSoundID.push_back(temp);
- }
- }
- }
- data.mShowBook = element->BoolAttribute("ShowBook");
- data.mBookIcon = element->Attribute("BookIcon");
- data.mBookScale = element->FloatAttribute("BookScale");
- data.mBookName = element->Attribute("BookName");
- data.mBookInfo = element->Attribute("BookInfo");
- data.mIsBOSS = element->BoolAttribute("IsBOSS");
- data.mIsFrozen = element->BoolAttribute("IsFrozen");
- data.mIsLottery = element->BoolAttribute("IsLottery");
- data.mShowStar = element->BoolAttribute("ShowStar");
- data.mRadius = element->FloatAttribute("Radius");
- data.mDisplayItem = element->IntAttribute("DisplayItem");
- {
- const char* ItemBubble = element->Attribute("ItemBubble");
- std::vector<std::string> vecItemBubble;
- boost::split(vecItemBubble, ItemBubble, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecItemBubble.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecItemBubble[i].c_str(), &temp))
- {
- data.mItemBubble.push_back(temp);
- }
- }
- }
- {
- const char* ChatBubble = element->Attribute("ChatBubble");
- std::vector<std::string> vecChatBubble;
- boost::split(vecChatBubble, ChatBubble, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecChatBubble.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecChatBubble[i].c_str(), &temp))
- {
- data.mChatBubble.push_back(temp);
- }
- }
- }
- {
- const char* ChatOffset = element->Attribute("ChatOffset");
- std::vector<std::string> vecChatOffset;
- boost::split(vecChatOffset, ChatOffset, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecChatOffset.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecChatOffset[i].c_str(), &temp))
- {
- data.mChatOffset.push_back(temp);
- }
- }
- }
- data.mItemBubbleScale = element->FloatAttribute("ItemBubbleScale");
- data.mCanBomb = element->BoolAttribute("CanBomb");
- data.mShowIndex = element->IntAttribute("ShowIndex");
- data.mShowType = element->IntAttribute("ShowType");
- data.mShowScore = element->Attribute("ShowScore");
- data.mBombRange = element->IntAttribute("BombRange");
- data.mCanHitByBulletHead = element->Attribute("CanHitByBulletHead");
- data.mScoreType = element->IntAttribute("ScoreType");
- {
- const char* TimesRange = element->Attribute("TimesRange");
- std::vector<std::string> vecTimesRange;
- boost::split(vecTimesRange, TimesRange, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecTimesRange.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecTimesRange[i].c_str(), &temp))
- {
- data.mTimesRange.push_back(temp);
- }
- }
- }
- data.mKillAndSendScore = element->IntAttribute("KillAndSendScore");
- if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
- CCASSERT(mMapData.find(data.mID) == mMapData.end(), "data.mID is exists");
- mMapData.insert(std::make_pair(data.mID, data));
- element = element->NextSiblingElement();
- }
- CCLOG("Fish_FishCFG Loaded. Load Data:%u", mMapData.size());
- }
- void Fish_FishCFG::LoadLua()
- {
- LuaEngine::getInstance()->executeScriptFile("config/Fish_FishCFG");
- lua_State* L = LuaEngine::getInstance()->getLuaStack()->getLuaState();
- lua_getglobal(L, "Fish_FishCFG");
- CCASSERT(lua_istable(L, -1) == 1, "is not table");
- lua_pushstring(L, "datas");
- lua_gettable(L, -2);
- CCASSERT(lua_istable(L, -1) == 1, "is not table");
- lua_pushnil(L);
- while(lua_next(L, 2))
- {
- CCASSERT(lua_istable(L, -1) == 1, "is not table");
- Fish_FishCFGData data;
- LuaCfgHelper::readInt(L, "ID", data.mID);
- LuaCfgHelper::readString(L, "FishName", data.mFishName);
- LuaCfgHelper::readInt(L, "ModelID", data.mModelID);
- LuaCfgHelper::readInt(L, "Score", data.mScore);
- LuaCfgHelper::readInt(L, "FishPoints", data.mFishPoints);
- LuaCfgHelper::readVectorInt(L, "Dimensity", data.mDimensity);
- LuaCfgHelper::readInt(L, "Type", data.mType);
- LuaCfgHelper::readInt(L, "DropGem", data.mDropGem);
- LuaCfgHelper::readInt(L, "ShowRadius", data.mShowRadius);
- LuaCfgHelper::readInt(L, "Layer", data.mLayer);
- LuaCfgHelper::readBool(L, "CanNetHit", data.mCanNetHit);
- LuaCfgHelper::readVectorInt(L, "ServerDieParam", data.mServerDieParam);
- LuaCfgHelper::readVectorFloat(L, "DieEffectParam", data.mDieEffectParam);
- LuaCfgHelper::readInt(L, "DieEffect", data.mDieEffect);
- LuaCfgHelper::readBool(L, "ShockScreen", data.mShockScreen);
- LuaCfgHelper::readInt(L, "DropGold", data.mDropGold);
- LuaCfgHelper::readInt(L, "EffectType", data.mEffectType);
- LuaCfgHelper::readInt(L, "GoldPlate", data.mGoldPlate);
- LuaCfgHelper::readInt(L, "ScreenPlate", data.mScreenPlate);
- LuaCfgHelper::readVectorInt(L, "DieSoundID", data.mDieSoundID);
- LuaCfgHelper::readBool(L, "ShowBook", data.mShowBook);
- LuaCfgHelper::readString(L, "BookIcon", data.mBookIcon);
- LuaCfgHelper::readFloat(L, "BookScale", data.mBookScale);
- LuaCfgHelper::readString(L, "BookName", data.mBookName);
- LuaCfgHelper::readString(L, "BookInfo", data.mBookInfo);
- LuaCfgHelper::readBool(L, "IsBOSS", data.mIsBOSS);
- LuaCfgHelper::readBool(L, "IsFrozen", data.mIsFrozen);
- LuaCfgHelper::readBool(L, "IsLottery", data.mIsLottery);
- LuaCfgHelper::readBool(L, "ShowStar", data.mShowStar);
- LuaCfgHelper::readFloat(L, "Radius", data.mRadius);
- LuaCfgHelper::readInt(L, "DisplayItem", data.mDisplayItem);
- LuaCfgHelper::readVectorInt(L, "ItemBubble", data.mItemBubble);
- LuaCfgHelper::readVectorInt(L, "ChatBubble", data.mChatBubble);
- LuaCfgHelper::readVectorInt(L, "ChatOffset", data.mChatOffset);
- LuaCfgHelper::readFloat(L, "ItemBubbleScale", data.mItemBubbleScale);
- LuaCfgHelper::readBool(L, "CanBomb", data.mCanBomb);
- LuaCfgHelper::readInt(L, "ShowIndex", data.mShowIndex);
- LuaCfgHelper::readInt(L, "ShowType", data.mShowType);
- LuaCfgHelper::readString(L, "ShowScore", data.mShowScore);
- LuaCfgHelper::readInt(L, "BombRange", data.mBombRange);
- LuaCfgHelper::readString(L, "CanHitByBulletHead", data.mCanHitByBulletHead);
- LuaCfgHelper::readInt(L, "ScoreType", data.mScoreType);
- LuaCfgHelper::readVectorInt(L, "TimesRange", data.mTimesRange);
- LuaCfgHelper::readInt(L, "KillAndSendScore", data.mKillAndSendScore);
- if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
- CCASSERT(mMapData.find(data.mID) == mMapData.end(), "data.mID is exists");
- mMapData.insert(std::make_pair(data.mID, data));
- lua_pop(L, 1);
- }
- lua_settop(L, 0);
- CCLOG("Fish_FishCFG Loaded. Load Data:%u", mMapData.size());
- }
- void Fish_FishCFG::Reload()
- {
- mMapData.clear();
- Load();
- }
- Fish_FishCFG* Fish_FishCFG::GetSingleton()
- {
- if (msSingleton.get() == nullptr)
- {
- msSingleton.reset(new Fish_FishCFG());
- }
- return msSingleton.get();
- }
- void Fish_FishCFG::Release()
- {
- msSingleton.reset(nullptr);
- }
|