huangjinghao 1 месяц назад
Родитель
Сommit
b8fcd9ed6a

+ 2 - 0
GameConfig/A_New_BuildAll.bat

@@ -1,6 +1,8 @@
 ExeclExport.exe auto
 copy /y ts\M_i18n.ts ..\..\Client\assets\Script\Config
 copy /y ts\M_test.ts ..\..\Client\assets\Script\Config
+copy /y ts\M_Global_Config.ts ..\..\Client\assets\Script\Config
+
 
 @echo off
 ::if "%nopause%" == "true" (@echo on) else (pause)

+ 1 - 0
GameConfig/CFG.check

@@ -1,3 +1,4 @@
 D:\git\newWork\FishConfig\GameConfig\M_i18n.xls:-192557145
+D:\git\newWork\FishConfig\GameConfig\M_Global_Config.xls:1026559635
 D:\git\newWork\FishConfig\GameConfig\SensitiveWordCFG.xls:-583314849
 D:\git\newWork\FishConfig\GameConfig\M_test.xls:209833058

+ 131 - 0
GameConfig/Code/Client/M_Global_Config.cpp

@@ -0,0 +1,131 @@
+#include "stdafx.h"
+#include "tinyxml2/tinyxml2.h"
+#include "LuaCfgHelper.h"
+#include <iostream>
+#include <boost/algorithm/string.hpp>
+#include "M_Global_Config.h"
+std::auto_ptr<M_Global_Config> M_Global_Config::msSingleton(nullptr);
+
+int M_Global_Config::GetCount()
+{
+	return (int)mMapData.size();
+}
+
+const M_Global_ConfigData* M_Global_Config::GetData(std::string Key)
+{
+	auto it = mMapData.find(Key);
+	if (it != mMapData.end())
+	{
+		return &it->second;
+	}
+	return NULL;
+}
+
+const std::map<std::string, M_Global_ConfigData>& M_Global_Config::GetMapData()
+{
+	return mMapData;
+}
+
+void M_Global_Config::Load()
+{
+	tinyxml2::XMLDocument xmlDoc;
+	std::string content = FileUtils::getInstance()->getStringFromFile("Config/M_Global_Config.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)
+	{
+		M_Global_ConfigData data;
+		data.mKey = element->Attribute("Key");
+		data.mIntValue = element->IntAttribute("IntValue");
+		{
+			const char* IntListValue = element->Attribute("IntListValue");
+			std::vector<std::string> vecIntListValue;
+			boost::split(vecIntListValue, IntListValue, boost::is_any_of(","));
+			int temp;
+			for (unsigned int i = 0; i < vecIntListValue.size(); i++)
+			{
+				if (tinyxml2::XMLUtil::ToInt(vecIntListValue[i].c_str(), &temp))
+				{
+					data.mIntListValue.push_back(temp);
+				}
+			}
+		}
+		data.mStrValue = element->Attribute("StrValue");
+		{
+			const char* StrListValue = element->Attribute("StrListValue");
+			std::vector<std::string> vecStrListValue;
+			boost::split(vecStrListValue, StrListValue, boost::is_any_of(","));
+			for (unsigned int i = 0; i < vecStrListValue.size(); i++)
+			{
+				data.mStrListValue.push_back(vecStrListValue[i]);
+			}
+		}
+		data.mBoolValue = element->BoolAttribute("BoolValue");
+		if (mMapData.find(data.mKey) != mMapData.end())std::cout <<"data refind:" << data.mKey << std::endl;
+		CCASSERT(mMapData.find(data.mKey) == mMapData.end(), "data.mKey is exists");
+		mMapData.insert(std::make_pair(data.mKey, data));
+		element = element->NextSiblingElement();
+	}
+	CCLOG("M_Global_Config Loaded. Load Data:%u", mMapData.size());
+}
+
+void M_Global_Config::LoadLua()
+{
+	LuaEngine::getInstance()->executeScriptFile("config/M_Global_Config");
+	lua_State* L = LuaEngine::getInstance()->getLuaStack()->getLuaState();
+	lua_getglobal(L, "M_Global_Config");
+	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");
+		M_Global_ConfigData data;
+		LuaCfgHelper::readString(L, "Key", data.mKey);
+		LuaCfgHelper::readInt(L, "IntValue", data.mIntValue);
+		LuaCfgHelper::readVectorInt(L, "IntListValue", data.mIntListValue);
+		LuaCfgHelper::readString(L, "StrValue", data.mStrValue);
+		LuaCfgHelper::readVectorString(L, "StrListValue", data.mStrListValue);
+		LuaCfgHelper::readBool(L, "BoolValue", data.mBoolValue);
+		if (mMapData.find(data.mKey) != mMapData.end())std::cout <<"data refind:" << data.mKey << std::endl;
+		CCASSERT(mMapData.find(data.mKey) == mMapData.end(), "data.mKey is exists");
+		mMapData.insert(std::make_pair(data.mKey, data));
+		lua_pop(L, 1);
+	}
+	lua_settop(L, 0);
+	CCLOG("M_Global_Config Loaded. Load Data:%u", mMapData.size());
+}
+
+void M_Global_Config::Reload()
+{
+	mMapData.clear();
+	Load();
+}
+
+M_Global_Config* M_Global_Config::GetSingleton()
+{
+	if (msSingleton.get() == nullptr)
+	{
+		msSingleton.reset(new M_Global_Config());
+	}
+	return msSingleton.get();
+}
+
+void M_Global_Config::Release()
+{
+	msSingleton.reset(nullptr);
+}

+ 35 - 0
GameConfig/Code/Client/M_Global_Config.h

@@ -0,0 +1,35 @@
+#pragma once
+#include <map>
+struct M_Global_ConfigData
+{
+	//Key
+	std::string mKey;
+	//数值
+	int mIntValue;
+	//数值列表
+	std::vector<int> mIntListValue;
+	//字符串
+	std::string mStrValue;
+	//字符串列表
+	std::vector<std::string> mStrListValue;
+	//布尔值参数
+	bool mBoolValue;
+};
+
+class M_Global_Config
+{
+public:
+private:
+	static std::auto_ptr<M_Global_Config> msSingleton;
+public:
+	int GetCount();
+	const M_Global_ConfigData* GetData(std::string Key);
+	const std::map<std::string, M_Global_ConfigData>& GetMapData();
+	void Load();
+	void LoadLua();
+	void Reload();
+	static M_Global_Config* GetSingleton();
+	static void Release();
+private:
+	std::map<std::string, M_Global_ConfigData> mMapData;
+};

+ 117 - 0
GameConfig/Code/Server/M_Global_Config.cpp

@@ -0,0 +1,117 @@
+#include "stdafx.h"
+#include <cassert>
+#include <fstream>
+#include <iostream>
+#include <iostream>
+#include <boost/smart_ptr.hpp>
+#include <boost/algorithm/string.hpp>
+#include "tinyxml2.h"
+#include "M_Global_Config.h"
+#include "FileEncrypt.h"
+std::auto_ptr<M_Global_Config> M_Global_Config::msSingleton(nullptr);
+
+int M_Global_Config::GetCount()
+{
+	return (int)mMapData.size();
+}
+
+const M_Global_ConfigData* M_Global_Config::GetData(std::string Key)
+{
+	auto it = mMapData.find(Key);
+	if (it != mMapData.end())
+	{
+		return &it->second;
+	}
+	return NULL;
+}
+
+boost::unordered_map<std::string, M_Global_ConfigData>& M_Global_Config::GetMapData()
+{
+	return mMapData;
+}
+
+void M_Global_Config::Reload()
+{
+	mMapData.clear();
+	Load();
+}
+
+void M_Global_Config::Load(const std::string& path)
+{
+	std::ifstream readStream(path, std::ios::binary);
+	if (!readStream.is_open())
+	{
+		assert(false);
+		return;
+	}
+	readStream.seekg(0, std::ios::end);
+	int fileSize = readStream.tellg();
+	boost::shared_array<char> buffer(new char[fileSize+1]);
+	buffer.get()[fileSize] = '\0';
+	readStream.seekg(0, std::ios::beg);
+	readStream.read(buffer.get(), fileSize);
+	readStream.close();
+	FileEncrypt::decryptBuffer( buffer, fileSize );
+	tinyxml2::XMLDocument xmlDoc;
+	auto result = xmlDoc.Parse(buffer.get(), fileSize);
+	if (result != tinyxml2::XML_SUCCESS)
+	{
+		assert(false);
+		return;
+	}
+	auto root = xmlDoc.RootElement();
+	if (root == NULL)
+	{
+		assert(false);
+		return;
+	}
+	auto element = root->FirstChildElement("Data");
+	while (element != NULL)
+	{
+		M_Global_ConfigData data;
+		data.mKey = element->Attribute("Key");
+		data.mIntValue = element->IntAttribute("IntValue");
+		{
+			const char* IntListValue = element->Attribute("IntListValue");
+			std::vector<std::string> vecIntListValue;
+			boost::split(vecIntListValue, IntListValue, boost::is_any_of(","));
+			int temp;
+			for (unsigned int i = 0; i < vecIntListValue.size(); i++)
+			{
+				if (tinyxml2::XMLUtil::ToInt(vecIntListValue[i].c_str(), &temp))
+				{
+					data.mIntListValue.push_back(temp);
+				}
+			}
+		}
+		data.mStrValue = element->Attribute("StrValue");
+		{
+			const char* StrListValue = element->Attribute("StrListValue");
+			std::vector<std::string> vecStrListValue;
+			boost::split(vecStrListValue, StrListValue, boost::is_any_of(","));
+			for (unsigned int i = 0; i < vecStrListValue.size(); i++)
+			{
+				data.mStrListValue.push_back(vecStrListValue[i]);
+			}
+		}
+		data.mBoolValue = element->BoolAttribute("BoolValue");
+		if (mMapData.find(data.mKey) != mMapData.end())std::cout <<"data refind:" << data.mKey << std::endl;
+		assert(mMapData.find(data.mKey) == mMapData.end());
+		mMapData.insert(std::make_pair(data.mKey, data));
+		element = element->NextSiblingElement();
+	}
+}
+
+void M_Global_Config::Load()
+{
+	Load("../Config/M_Global_Config.xml");
+}
+
+M_Global_Config* M_Global_Config::GetSingleton()
+{
+	if (msSingleton.get() == nullptr)
+	{
+		msSingleton.reset(new M_Global_Config());
+	}
+	return msSingleton.get();
+}

+ 35 - 0
GameConfig/Code/Server/M_Global_Config.h

@@ -0,0 +1,35 @@
+#pragma once
+#include <boost/unordered_map.hpp>
+#include <vector>
+struct M_Global_ConfigData
+{
+	//Key
+	std::string mKey;
+	//数值
+	int mIntValue;
+	//数值列表
+	std::vector<int> mIntListValue;
+	//字符串
+	std::string mStrValue;
+	//字符串列表
+	std::vector<std::string> mStrListValue;
+	//布尔值参数
+	bool mBoolValue;
+};
+
+class M_Global_Config
+{
+public:
+private:
+	static std::auto_ptr<M_Global_Config> msSingleton;
+public:
+	int GetCount();
+	const M_Global_ConfigData* GetData(std::string Key);
+	boost::unordered_map<std::string, M_Global_ConfigData>& GetMapData();
+	void Reload();
+	void Load(const std::string& path);
+	void Load();
+	static M_Global_Config* GetSingleton();
+private:
+	boost::unordered_map<std::string, M_Global_ConfigData> mMapData;
+};

+ 16 - 0
GameConfig/Lua/M_Global_Config.lua

@@ -0,0 +1,16 @@
+M_Global_Config = {}
+
+function M_Global_Config:getData(key)
+	if self.datas == nil then
+		return nil
+	end
+	return self.datas[key]
+end
+
+function M_Global_Config:init()
+	self.datas = {}
+	self.datas["TestKey1"] = {Key = "TestKey1", IntValue = 1, IntListValue = {2,3}, StrValue = "", StrListValue = {"lbt","lbbt"}, BoolValue = true}
+	self.datas["TestKey2"] = {Key = "TestKey2", IntValue = 2, IntListValue = {}, StrValue = "lbt", StrListValue = {}, BoolValue = false}
+end
+
+M_Global_Config:init()

BIN
GameConfig/M_Global_Config.xls


+ 5 - 0
GameConfig/Xml/M_Global_Config.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Root>
+	<Data Key="TestKey1" IntValue="1" IntListValue="2,3" StrValue="" StrListValue="lbt,lbbt" BoolValue="true" />
+	<Data Key="TestKey2" IntValue="2" IntListValue="" StrValue="lbt" StrListValue="" BoolValue="false" />
+</Root>

+ 5 - 0
GameConfig/json/M_Global_Config.json

@@ -0,0 +1,5 @@
+{"TestKey1":{"Key":"TestKey1","IntValue":1,"IntListValue":[2,3],"StrValue":"","StrListValue":["lbt","lbbt"],"BoolValue":true}
+
+,"TestKey2":{"Key":"TestKey2","IntValue":2,"IntListValue":[],"StrValue":"lbt","StrListValue":[],"BoolValue":false}
+
+}

+ 22 - 0
GameConfig/ts/M_Global_Config.ts

@@ -0,0 +1,22 @@
+// Key:Key, IntValue:数值, IntListValue:数值列表, StrValue:字符串, StrListValue:字符串列表, BoolValue:布尔值参数
+
+export default class M_Global_Config {
+  private static data =
+      {"TestKey1":{"Key":"TestKey1","IntValue":1,"IntListValue":[2,3],"StrValue":"","StrListValue":["lbt","lbbt"],"BoolValue":true}
+
+      ,"TestKey2":{"Key":"TestKey2","IntValue":2,"IntListValue":[],"StrValue":"lbt","StrListValue":[],"BoolValue":false}
+
+      }// Key:Key, IntValue:数值, IntListValue:数值列表, StrValue:字符串, StrListValue:字符串列表, BoolValue:布尔值参数
+
+
+    static getData(key: any): any {
+        if (key == null || key == undefined)
+            return null;
+        return this.data[key];
+    }
+
+    static getAllData(): any {
+        return this.data;
+    }
+
+}