/// <summary> /// C# 将解析到的xml生成string,并赋值到sb /// 这个类 是 唯一的 特殊性太强 直接写 /// </summary> void sWriteCSFileContent(StringBuilder sb, AllBaseCmdFileData fileData) { List <string> declareStringList = new List <string>(); List <string> packStringList = new List <string>(); List <string> unpackStringList = new List <string>(); for (int i = 0; i < fileData.mAllBaseCmdList.Count; ++i) { ParamDataOutString outString = CmdParserComUitls.CmdParamParserDeclare_CS(fileData.mAllBaseCmdList[i], fileData.mClassName, true); //将ParamData转为string declareStringList.AddRange(outString.mOutDeclareString.ToArray()); //赋值 声明string packStringList.AddRange(outString.mOutPackString.ToArray()); //赋值 写入string unpackStringList.AddRange(outString.mOutUnpackString.ToArray()); //赋值 读取string } sb.AppendLine("public class " + fileData.mClassName + " : " + fileData.mFatherName); sb.AppendLine("{"); //声明 for (int j = 0; j < declareStringList.Count; ++j) { sb.AppendLine("\t" + declareStringList[j]); } sb.AppendLine(); //写声明消息值 sb.AppendLine("\tpublic const byte " + fileData.mGsCmd + " = " + fileData.mNum + ";"); sb.AppendLine(""); sb.AppendLine("\tpublic " + fileData.mClassName + "()"); sb.AppendLine("\t{"); sb.AppendLine("\t\tgsCmd = " + fileData.mGsCmd + ";"); sb.AppendLine("\t}"); sb.AppendLine(""); //写打包 sb.AppendLine("\tpublic override void Pack()"); sb.AppendLine("\t{"); sb.AppendLine("\t\tbase.Pack();"); for (int k = 0; k < packStringList.Count; ++k) { sb.AppendLine("\t\t" + packStringList[k]); } sb.AppendLine("\t}"); sb.AppendLine(""); //写解包 sb.AppendLine("\tpublic override void UnPack(byte[] msg)"); sb.AppendLine("\t{"); sb.AppendLine("\t\tbase.UnPack(msg);"); for (int m = 0; m < unpackStringList.Count; ++m) { sb.AppendLine("\t\t" + unpackStringList[m]); } sb.AppendLine("\t}"); sb.AppendLine("}"); }
/// <summary> /// Lua 将解析到的xml生成string,并赋值到sb /// </summary> void sWriteLuaFileContent(StringBuilder sb, DataStructFileData fileData) { List <string> declareStringList = new List <string>(); List <string> ctorStringList = new List <string>(); List <string> packStringList = new List <string>(); List <string> unpackStringList = new List <string>(); for (int i = 0; i < fileData.mParamList.Count; ++i) { ParamDataOutString outString = CmdParserComUitls.CmdParamParserDeclare_Lua(fileData.mParamList[i], fileData.mClassName); declareStringList.AddRange(outString.mOutDeclareString.ToArray()); ctorStringList.AddRange(outString.mOutCtorString.ToArray()); packStringList.AddRange(outString.mOutPackString.ToArray()); unpackStringList.AddRange(outString.mOutUnpackString.ToArray()); } if (fileData.mFather == "NULL" || fileData.mFather == null) { sb.AppendLine(fileData.mClassName + " = class(\"" + fileData.mClassName + "\");"); } else { sb.AppendLine(fileData.mClassName + " = class(\"" + fileData.mClassName + "\"," + fileData.mFather + ");"); } sb.AppendLine(); //声明 for (int j = 0; j < declareStringList.Count; ++j) { sb.AppendLine("\t" + declareStringList[j].Replace("self", fileData.mClassName)); } sb.AppendLine(); //ctor sb.Append("function " + fileData.mClassName + ":ctor()"); sb.AppendLine(); for (int i = 0; i < ctorStringList.Count; i++) { sb.Append("\n" + ctorStringList[i]); } sb.Append("\nend\n"); sb.AppendLine(); //PackData 打包 sb.AppendLine("function " + fileData.mClassName + ":PackData(byteBuffer)"); if (fileData.mFather != "NULL" & fileData.mFather != null) { sb.AppendLine("\t " + fileData.mClassName + ".super:PackData(byteBuffer);"); } for (int k = 0; k < packStringList.Count; ++k) { sb.AppendLine("\t\t" + packStringList[k].Replace("self.byteBuffer", "byteBuffer")); } sb.Append("end"); sb.AppendLine(); //UnPackData sb.AppendLine("function " + fileData.mClassName + ":UnPackData(byteBuffer)"); if (fileData.mFather != "NULL" & fileData.mFather != null) { sb.AppendLine("\t " + fileData.mClassName + ".super.UnPackData(self,byteBuffer);"); } for (int m = 0; m < unpackStringList.Count; ++m) { sb.AppendLine("\t\t" + unpackStringList[m].Replace("self.byteBuffer", "byteBuffer")); } sb.Append("\nend\n"); sb.AppendLine(); }
/// <summary> /// C# 将解析到的xml生成string,并赋值到sb /// </summary> void sWriteCSFileContent(StringBuilder sb, DataStructFileData fileData) { List <string> declareStringList = new List <string>(); List <string> packStringList = new List <string>(); List <string> unpackStringList = new List <string>(); for (int i = 0; i < fileData.mParamList.Count; ++i) { ParamDataOutString outString = CmdParserComUitls.CmdParamParserDeclare_CS(fileData.mParamList[i], fileData.mClassName); //将ParamData转为string declareStringList.AddRange(outString.mOutDeclareString.ToArray()); //赋值 声明string packStringList.AddRange(outString.mOutPackString.ToArray()); //赋值 写入string unpackStringList.AddRange(outString.mOutUnpackString.ToArray()); //赋值 读取string } if (fileData.mFather == "NULL" || fileData.mFather == null) { sb.AppendLine("public class " + fileData.mClassName); } else { sb.AppendLine("public class " + fileData.mClassName + " : " + fileData.mFather); } sb.AppendLine("{"); //声明变量 for (int j = 0; j < declareStringList.Count; ++j) { sb.AppendLine("\t" + declareStringList[j]); } sb.AppendLine(); //PackData 写数据 if (fileData.mFather != "NULL" & fileData.mFather != null) { sb.AppendLine("\tpublic override void PackData(ByteBuffer byteBuffer)"); sb.AppendLine("\t{"); sb.AppendLine("\t\tbase.PackData(byteBuffer);"); } else { sb.AppendLine("\tpublic virtual void PackData(ByteBuffer byteBuffer)"); sb.AppendLine("\t{"); } for (int k = 0; k < packStringList.Count; ++k) { sb.AppendLine("\t\t" + packStringList[k]); } sb.AppendLine("\t}"); sb.AppendLine(); //UnPackData 读数据 if (fileData.mFather != "NULL" & fileData.mFather != null) { sb.AppendLine("\tpublic override void UnPackData(ByteBuffer byteBuffer)"); sb.AppendLine("\t{"); sb.AppendLine("\t\tbase.UnPackData(byteBuffer);"); } else { sb.AppendLine("\tpublic virtual void UnPackData(ByteBuffer byteBuffer)"); sb.AppendLine("\t{"); } for (int m = 0; m < unpackStringList.Count; ++m) { sb.AppendLine("\t\t" + unpackStringList[m]); } sb.AppendLine("\t}"); sb.AppendLine("}"); sb.AppendLine(); }
public void sWriteLuaFileContent(string fileType, CmdStructFileData fileData) { StringBuilder sb = new StringBuilder(); NetCmdXmlParser.sWriteLuaFileHeadComment(sb, fileData.mClassName, fileData.mDescribe); //生成注释的文件头 //所需XML数据 List <string> declareStringList = new List <string>(); List <string> packStringList = new List <string>(); List <string> unpackStringList = new List <string>(); List <string> ctorStringList = new List <string>(); //初始化字符串 for (int i = 0; i < fileData.mCmdList.Count; ++i) { ParamDataOutString outString = CmdParserComUitls.CmdParamParserDeclare_Lua(fileData.mCmdList[i], fileData.mClassName, true); declareStringList.AddRange(outString.mOutDeclareString.ToArray()); packStringList.AddRange(outString.mOutPackString.ToArray()); unpackStringList.AddRange(outString.mOutUnpackString.ToArray()); ctorStringList.AddRange(outString.mOutCtorString.ToArray()); } //lua的文件直接生成到对应根目录下,防止lua打包时生成过多零碎文件 /* * string filePathName = ""; * if (fileData.mPathName != null) * { * filePathName = fileData.mPathName + "/"; * } */ string outFilePath = ""; //生成文件位置 bool _isWrite = false; switch (fileType) { case "Lua_C": outFilePath = NetCmdXmlParser.targetLuaFileBasePath + cmdOutFilePath_C + fileData.mClassName + "_C.lua"; sWriteLuaFileContent_C(sb, fileData, declareStringList, packStringList); _isWrite = true; break; case "Lua_S": outFilePath = NetCmdXmlParser.targetLuaFileBasePath + cmdOutFilePath_S + fileData.mClassName + "_S.lua"; LuaScriptParserTool.AddLuaRequireString(cmdOutFilePathName_S + "." + fileData.mClassName + "_S"); sWriteLuaFileContent_S(sb, fileData, declareStringList, unpackStringList, ctorStringList); _isWrite = true; break; case "Lua_Handler": outFilePath = NetCmdXmlParser.targetLuaFileBasePath + cmdOutFilePath_Handler + fileData.mClassName + "_Handler.lua"; LuaScriptParserTool.AddLuaRequireString(cmdOutFilePathName_Handler + "." + fileData.mClassName + "_Handler"); if (!File.Exists(outFilePath)) { sWriteLuaFileContent_Handler(sb, fileData); _isWrite = true; } else { return; } break; } if (_isWrite) { NetCmdXmlParser.sWriteStringToFile(outFilePath, sb); } }
void sWriteCSFileContent(string fileType, CmdStructFileData fileData) { StringBuilder sb = new StringBuilder(); NetCmdXmlParser.sWriteFileHeadComment(sb, fileData.mClassName, fileData.mDescribe); //生成注释的文件头 NetCmdXmlParser.sWriteFileHeadNameSpace(sb); //生成命名空间 //所需XML数据 List <string> declareStringList = new List <string>(); List <string> packStringList = new List <string>(); List <string> unpackStringList = new List <string>(); List <string> ctorStringList = new List <string>(); //初始化字符串 for (int i = 0; i < fileData.mCmdList.Count; ++i) { ParamDataOutString outString = CmdParserComUitls.CmdParamParserDeclare_CS(fileData.mCmdList[i], fileData.mClassName, true); declareStringList.AddRange(outString.mOutDeclareString.ToArray()); packStringList.AddRange(outString.mOutPackString.ToArray()); unpackStringList.AddRange(outString.mOutUnpackString.ToArray()); ctorStringList.AddRange(outString.mOutCtorString.ToArray()); } string filePathName = ""; if (fileData.mPathName != null) { filePathName = fileData.mPathName + "/"; } string outFilePath = ""; //生成文件位置 bool _isWrite = false; switch (fileType) { case "C#_C": outFilePath = NetCmdXmlParser.targetFileBasePath + cmdOutFilePath_C + filePathName + fileData.mClassName + "_C.cs"; sWriteCSFileContent_C(sb, fileData, declareStringList, packStringList); _isWrite = true; break; case "C#_S": outFilePath = NetCmdXmlParser.targetFileBasePath + cmdOutFilePath_S + filePathName + fileData.mClassName + "_S.cs"; sWriteCSFileContent_S(sb, fileData, declareStringList, unpackStringList, ctorStringList); _isWrite = true; break; case "C#_Handler": outFilePath = NetCmdXmlParser.targetFileBasePath + cmdOutFilePath_Handler + filePathName + fileData.mClassName + "_Handler.cs"; if (!File.Exists(outFilePath)) { sWriteCSFileContent_Handler(sb, fileData); _isWrite = true; } else { return; } break; } if (_isWrite) { NetCmdXmlParser.sWriteStringToFile(outFilePath, sb); } }