Beispiel #1
0
    private static void WriteItems(FileStream fs, CompileXml compileXml, XmlNode rootNode)
    {
        var itemsNode = rootNode.SelectSingleNode("Items");

        foreach (var itemNode in itemsNode)
        {
            var itemElement = (XmlElement)itemNode;
            var dataNodes   = itemElement.ChildNodes;
            compileXml.writeItemCount(fs, (short)dataNodes.Count);

            foreach (var dataNode in dataNodes)
            {
                var dataElement = (XmlElement)dataNode;
                var name        = dataElement.Name;
                var _index      = name.IndexOf('_');
                if (_index > -1)
                {
                    name = name.Substring(0, _index);
                }

                var fieldType = compileXml.m_FieldTypeList[compileXml.m_FieldNameBufferToIndexMap[name]];
                var bytes     = compileXml.ParseTypeMap[fieldType]((short)compileXml.m_FieldNameBufferToIndexMap[name],
                                                                   dataElement.InnerText);
                fs.Write(bytes, 0, bytes.Length);
            }
        }
    }
Beispiel #2
0
    private static void ParseXml(string path, string xmlBinExportDir)
    {
        try
        {
            var complieXml = new CompileXml();
            var xmlDoc     = new XmlDocument();
            xmlDoc.Load(path);
            var rootNode = xmlDoc.SelectSingleNode("root");

            var nodeList = rootNode.SelectSingleNode("Props").ChildNodes;
            foreach (var childNode in nodeList)
            {
                var childElement = (XmlElement)childNode;
                var fieldName    = childElement.InnerText;

                CsBuilder.IsPrimaryKey(ref fieldName);
                var fieldType = CsBuilder.GetFieldType(ref fieldName);

                complieXml.m_FieldNameList.Add(fieldName);
                complieXml.m_FieldNameBufferToIndexMap.Add(fieldName, complieXml.m_FieldNameBufferToIndexMap.Count);
                complieXml.m_FieldTypeList.Add(TypeMap[fieldType]);
            }

            complieXml.m_FieldNameBufferSzie = GetStringBufferSize(complieXml.m_FieldNameList);
            complieXml.m_FieldCount          = (short)complieXml.m_FieldTypeList.Count;

            string name = Path.GetFileNameWithoutExtension(path);

            FileStream fs = File.Create(xmlBinExportDir + "/" + name + ".xml");

            complieXml.WriteHead(fs);

            GetStringBuffer(complieXml, rootNode);
            complieXml.WriteStringBuffer(fs);

            WriteItems(fs, complieXml, rootNode);

            fs.Flush();
            fs.Close();
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }
    }
    private void SavePriorityConfig()
    {
        m_ProcessResults.Add("###<color=#ffffff>保存数据优先级配置</color>");
        m_ProcessResults.Add(m_Window.PriorityConfig.SavePriorityConfig(m_Window.SettingUI.XmlExportDirectory));
        m_ProcessResults.Add("###<color=#22b454>=======================保存数据优先级配置成功=======================</color>");

        try
        {
            m_ProcessResults.Add("###<color=#ffffff>写入数据优先级配置</color>");
            m_ProcessResults.Add(m_SaveGameDataConfig.ExportConfig());
            m_ProcessResults.Add("###<color=#22b454>=======================写入数据优先级配置成功=======================</color>");
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }

        CompileXml.ComplieXmlFile(m_Window.SettingUI.XmlExportDirectory, m_Window.SettingUI.XmlBinExportDirectory);
        CsBuilder.CreateCsCode(m_Window.SettingUI.XmlExportDirectory, m_Window.SettingUI.CsExportDirectory, m_CodeTemplateFilePath);
    }
Beispiel #4
0
    private static void GetStringBuffer(CompileXml compileXml, XmlNode rootNode)
    {
        var itemsNode = rootNode.SelectSingleNode("Items");

        compileXml.m_ItemCount = itemsNode.ChildNodes.Count;

        foreach (var itemNode in itemsNode)
        {
            var itemElement = (XmlElement)itemNode;
            var dataNodes   = itemElement.ChildNodes;
            foreach (var dataNode in dataNodes)
            {
                var dataElement = (XmlElement)dataNode;
                var name        = dataElement.Name;
                var _index      = name.IndexOf('_');
                if (_index > -1)
                {
                    name = name.Substring(0, _index);
                }

                var fieldType = compileXml.m_FieldTypeList[compileXml.m_FieldNameBufferToIndexMap[name]];
                if (fieldType == 2)
                {
                    if (!compileXml.m_StringBufferToIndexMap.ContainsKey(dataElement.InnerText) &&
                        !string.IsNullOrEmpty(dataElement.InnerText))
                    {
                        compileXml.m_StringBufferList.Add(dataElement.InnerText);
                        compileXml.m_StringBufferToIndexMap.Add(dataElement.InnerText,
                                                                compileXml.m_StringBufferList.Count - 1);
                    }
                }
                if (fieldType == 8 || fieldType == 17)
                {
                    var strings = dataElement.InnerText.Split(',');
                    foreach (var str in strings)
                    {
                        if (!compileXml.m_StringBufferToIndexMap.ContainsKey(str) && !string.IsNullOrEmpty(str))
                        {
                            compileXml.m_StringBufferList.Add(str);
                            compileXml.m_StringBufferToIndexMap.Add(str, compileXml.m_StringBufferList.Count - 1);
                        }
                    }
                }
                if (fieldType == 9)
                {
                    string[] valueSplit = dataElement.InnerText.Split(',');

                    for (int i = 0; i < valueSplit.Length; i++)
                    {
                        var parseResult = valueSplit[i].Split('_');
                        for (int j = 0; j < parseResult.Length; j++)
                        {
                            if (!compileXml.m_StringBufferToIndexMap.ContainsKey(parseResult[j]) &&
                                !string.IsNullOrEmpty(parseResult[j]))
                            {
                                compileXml.m_StringBufferList.Add(parseResult[j]);
                                compileXml.m_StringBufferToIndexMap.Add(parseResult[j],
                                                                        compileXml.m_StringBufferList.Count - 1);
                            }
                        }
                    }
                }
                if (fieldType == 13)
                {
                    string[] valueSplit = dataElement.InnerText.Split(',');

                    for (int i = 0; i < valueSplit.Length; i++)
                    {
                        var parseResult = valueSplit[i].Split(':');

                        if (!compileXml.m_StringBufferToIndexMap.ContainsKey(parseResult[1]) &&
                            !string.IsNullOrEmpty(parseResult[1]))
                        {
                            compileXml.m_StringBufferList.Add(parseResult[1]);
                            compileXml.m_StringBufferToIndexMap.Add(parseResult[1],
                                                                    compileXml.m_StringBufferList.Count - 1);
                        }
                    }
                }
                if (fieldType == 14)
                {
                    string[] valueSplit = dataElement.InnerText.Split(',');
                    for (int i = 0; i < valueSplit.Length; i++)
                    {
                        var parseResult = valueSplit[i].Split(':');
                        for (int j = 0; j < 2; j++)
                        {
                            if (!compileXml.m_StringBufferToIndexMap.ContainsKey(parseResult[j]) &&
                                !string.IsNullOrEmpty(parseResult[j]))
                            {
                                compileXml.m_StringBufferList.Add(parseResult[j]);
                                compileXml.m_StringBufferToIndexMap.Add(parseResult[j],
                                                                        compileXml.m_StringBufferList.Count - 1);
                            }
                        }
                    }
                }
                if (fieldType == 15)
                {
                    string[] valueSplit = dataElement.InnerText.Split(',');

                    for (int i = 0; i < valueSplit.Length; i++)
                    {
                        var parseResult = valueSplit[i].Split(':');

                        if (!compileXml.m_StringBufferToIndexMap.ContainsKey(parseResult[0]) &&
                            !string.IsNullOrEmpty(parseResult[0]))
                        {
                            compileXml.m_StringBufferList.Add(parseResult[0]);
                            compileXml.m_StringBufferToIndexMap.Add(parseResult[0],
                                                                    compileXml.m_StringBufferList.Count - 1);
                        }
                    }
                }
            }
        }

        if (compileXml.m_StringBufferList.Count > 0)
        {
            compileXml.m_HasStringBuffer = 1;
        }
    }