示例#1
0
    //----------------------内部调用-------------------------
    #region 内部调用
    /// <summary>
    /// 生成Data脚本
    /// </summary>
    void sWriteFile(DataStructFileData fileData)
    {
        if (fileData.mIsCS)
        {
            //生成C#脚本
            StringBuilder sb = new StringBuilder();
            NetCmdXmlParser.sWriteFileHeadComment(sb, fileData.mClassName, fileData.mDescribe);                       //生成注释的文件头
            NetCmdXmlParser.sWriteFileHeadNameSpace(sb);                                                              //写命名空间
            sWriteCSFileContent(sb, fileData);                                                                        //将解析到的xml生成string,并赋值到sb
            //写文件
            string outFilePath = NetCmdXmlParser.targetFileBasePath + paramOutFilePath + fileData.mClassName + ".cs"; //生成文件路径
            NetCmdXmlParser.sWriteStringToFile(outFilePath, sb);                                                      //生成文件
        }
        if (fileData.mIsLua)
        {
            //生成Lua脚本
            StringBuilder lua_sb = new StringBuilder();
            NetCmdXmlParser.sWriteLuaFileHeadComment(lua_sb, fileData.mClassName, fileData.mDescribe);                       //生成注释的文件头
            sWriteLuaFileContent(lua_sb, fileData);                                                                          //将解析到的xml生成string,并赋值到lua_sb
            //写Lua文件
            string outLuaFilePath = NetCmdXmlParser.targetLuaFileBasePath + paramOutFilePath + fileData.mClassName + ".lua"; //生成文件路径
            NetCmdXmlParser.sWriteStringToFile(outLuaFilePath, lua_sb);                                                      //生成文件

            //放入NetCmdLuaHandler中进行引用,以便加载
            LuaScriptParserTool.AddLuaRequireString(constPackageName + "." + fileData.mClassName);
        }
    }
示例#2
0
    //----------------------内部调用-------------------------
    #region 内部调用
    /// <summary>
    /// 生成base脚本
    /// </summary>
    void sWriteFile(AllBaseCmdFileData fileData)
    {
        if (fileData.mIsCS)
        {
            //生成C#脚本
            StringBuilder sb = new StringBuilder();
            NetCmdXmlParser.sWriteFileHeadComment(sb, fileData.mClassName, fileData.mDescribe); //生成注释的文件头
            NetCmdXmlParser.sWriteFileHeadNameSpace(sb);                                        //写命名空间引用
            sWriteCSFileContent(sb, fileData);                                                  //将解析到的xml生成string,并赋值到sb
            //写文件
            string outFilePath = NetCmdXmlParser.targetFileBasePath + baseCmdOutFilePath + fileData.mClassName + ".cs";
            NetCmdXmlParser.sWriteStringToFile(outFilePath, sb);
        }

        if (fileData.mIsLua)
        {
            //生成Lua脚本
            StringBuilder lua_db = new StringBuilder();
            NetCmdXmlParser.sWriteLuaFileHeadComment(lua_db, fileData.mClassName, fileData.mDescribe); //生成注释的文件头
            sWriteLuaFileContent(lua_db, fileData);                                                    //将解析到的xml生成string,并赋值到sb
            //写Lua文件
            string outLuaFilePath = NetCmdXmlParser.targetLuaFileBasePath + baseCmdOutFilePath + fileData.mClassName + ".lua";
            NetCmdXmlParser.sWriteStringToFile(outLuaFilePath, lua_db);

            //放入NetCmdLuaHandler中进行引用,以便加载
            LuaScriptParserTool.AddLuaRequireString(LuaScriptParserTool.CmdBaseDirectory + "." + fileData.mClassName);
        }
    }
示例#3
0
    //----------------------内部调用-------------------------
    #region 内部调用
    /// <summary>
    /// 生成Const脚本
    /// </summary>
    void sWriteFile(ConstFileData fileData)
    {
        //生成C#脚本
        StringBuilder sb = new StringBuilder();

        NetCmdXmlParser.sWriteFileHeadComment(sb, fileData.mClassName, "网络消息所用常量"); //生成注释的文件头
        NetCmdXmlParser.sWriteFileHeadNameSpace(sb);                                //写命名空间
        sWriteCSFileContent(sb, fileData);                                          //将解析到的xml生成string,并赋值到sb
        //写文件
        string outFilePath = NetCmdXmlParser.targetFileBasePath + constOutFilePath + fileData.mClassName + ".cs";

        NetCmdXmlParser.sWriteStringToFile(outFilePath, sb);

        //生成Lua脚本
        StringBuilder lua_sb = new StringBuilder();

        NetCmdXmlParser.sWriteLuaFileHeadComment(lua_sb, fileData.mClassName, "网络消息所用常量"); //生成注释的文件头
        sWriteLuaFileContent(lua_sb, fileData);                                            //将解析到的xml生成string,并赋值到sb
        //写文件
        string outLuaFilePath = NetCmdXmlParser.targetLuaFileBasePath + constOutFilePath + fileData.mClassName + ".lua";

        NetCmdXmlParser.sWriteStringToFile(outLuaFilePath, lua_sb);

        //放入NetCmdLuaHandler中进行引用,以便加载
        LuaScriptParserTool.AddLuaRequireString(constPackageName + "." + fileData.mClassName);      //加入const的引用
    }
示例#4
0
    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);
        }
    }