Beispiel #1
0
    public override bool LoadConfig(int id)
    {
        WDBSheetLine line = CDataMgr.Item.GetData(id);

        if (line == null)
        {
            LKDebug.LogError("LoadConfig error: can't find " + id + " in Item table!");
            return(false);
        }

        id_             = line.GetData <int>(WDB_Item.Id);
        name_           = line.GetData <string>(WDB_Item.Name);
        desc_           = line.GetData <string>(WDB_Item.Desc);
        body_           = line.GetData <string>(WDB_Item.Body);
        body_drop_      = line.GetData <string>(WDB_Item.Body_Drop);
        drop_effect_    = line.GetData <int>(WDB_Item.Drop_Effect);
        quality_        = line.GetData <int>(WDB_Item.Quality);
        bag_            = line.GetData <int>(WDB_Item.Bag);
        use_            = line.GetData <int>(WDB_Item.Use);
        autu_gein_      = line.GetData <int>(WDB_Item.AutuGein);
        stack_sum_      = line.GetData <int>(WDB_Item.StackSum);
        is_resolve_     = line.GetData <int>(WDB_Item.IsResolve);
        is_sold_        = line.GetData <int>(WDB_Item.IsSold);
        price_          = line.GetData <int>(WDB_Item.Price);
        is_affirm_sold_ = line.GetData <int>(WDB_Item.IsAffirmSold);
        icon_           = line.GetData <string>(WDB_Item.Icon);
        icon_type_      = line.GetData <int>(WDB_Item.IconType);
        function_       = line.GetData <int>(WDB_Item.Function);
        buff_id_        = line.GetData <int>(WDB_Item.BuffId);
        drop_           = line.GetData <int>(WDB_Item.Drop);
        trun_around_    = line.GetData <int>(WDB_Item.TrunAround);
        gain_effect_    = line.GetData <int>(WDB_Item.GainEffect);

        return(true);
    }
Beispiel #2
0
    /// <summary>
    /// 填写target的数据.
    /// </summary>
    /// <param name="fromType">target被解析为的类型, 它与target.GetType()不一定相同, 可能是该类型的基类</param>
    /// <param name="target">需要被填写的对象</param>
    /// <param name="paramArray">参数列表</param>
    /// <param name="paramIndex">参数列表的开始位置, 从该位置开始的内容被填写到target中</param>
    static private void loadLine(Type fromType, object target, WDBSheetLine paramArray, ref int paramIndex)
    {
        // 如果fromType有基类, 先读取基类的信息.
        if (fromType.BaseType != typeof(object))
        {
            loadLine(fromType.BaseType, target, paramArray, ref paramIndex);
        }

        // 不读取static成员.
        System.Reflection.FieldInfo[] fields = fromType.GetFields(
            System.Reflection.BindingFlags.Public
            | System.Reflection.BindingFlags.DeclaredOnly
            | System.Reflection.BindingFlags.Instance
            );

        foreach (System.Reflection.FieldInfo f in fields)
        {
            Type elementType = f.FieldType;
            int  count       = 1;

            // 如果该域是数组, 那么取数组长度和数组的元素类型.
            if (f.FieldType.IsArray)
            {
                count       = ((object[])f.GetValue(target)).Length;
                elementType = f.FieldType.GetElementType();
            }

            //
            object[] value = new object[count];

            for (int i = 0; i < count; ++i)
            {
                // 如果是内置类型(string的IsPrimitive为false, 特殊处理).
                if (!elementType.IsPrimitive && (elementType != typeof(string)))
                {
                    value[i] = Activator.CreateInstance(elementType);
                    loadLine(elementType, value[i], paramArray, ref paramIndex);
                }
                else
                {
                    if (paramIndex >= paramArray.m_Line.Length)
                    {
                        throw new Exception("文件中的列数和结构中定义的不一致");
                    }

                    value[i] = paramArray.GetData(paramIndex++);
                }
            }

            // 拷贝数组到结果中.
            if (f.FieldType.IsArray)
            {
                Array.Copy(value, (Array)f.GetValue(target), count);
            }
            else
            {
                f.SetValue(target, value[0]);
            }
        }
    }
Beispiel #3
0
    public object GetData(int index, int field)
    {
        WDBSheetLine data = this.GetData(index);

        if (data != null)
        {
            return(data.GetData(field));
        }
        return(null);
    }
Beispiel #4
0
    public T GetDataByNumber <T>(int row, int field)
    {
        WDBSheetLine dataByNumber = this.GetDataByNumber(row);

        if (dataByNumber != null)
        {
            return(dataByNumber.GetData <T>(field));
        }
        return(createInstance <T>());
    }
Beispiel #5
0
    public object GetDataByNumber(int row, int field)
    {
        WDBSheetLine dataByNumber = this.GetDataByNumber(row);

        if (dataByNumber != null)
        {
            return(dataByNumber.GetData(field));
        }
        return(null);
    }
Beispiel #6
0
    private static object loadLine(WDBSheetLine line, object item, int keyIdx)
    {
        int index = 0;

        loadLine(item.GetType(), item, line, ref index);

        if (index != line.m_Line.Length)
        {
            throw new Exception("文件中的列数和结构中定义的不一致");
        }

        return(line.GetData(keyIdx));
    }
Beispiel #7
0
    public WDBSheetLine GetDataByNumber(int row)
    {
        if (row >= 0 && row < GetRecordCount())
        {
            WDBSheetLine data = new WDBSheetLine();
            data.m_Line = new object[mHeader.nFields];

            for (int i = 0; i < mHeader.nFields; i++)
            {
                data.m_Line[i] = GetDataByNumber(row, i);
            }

            return(data);
        }
        return(null);
    }
Beispiel #8
0
    public static WDBData Analyze(string text)
    {
        if (string.IsNullOrEmpty(text))
        {
            return(null);
        }
        WDBData             data      = new WDBData();
        List <WDBSheetLine> sheetList = new List <WDBSheetLine>();

        data.m_Type = new List <TYPE>();
        Dictionary <int, TYPE> _type = new Dictionary <int, TYPE>();

        string[] lineData = text.Split('\n');

        int keyLine  = -1;
        int typeLine = -1;

        for (int nLine = 0; nLine < lineData.Length; ++nLine)
        {
            string[] datas = lineData[nLine].Split('\r');
            datas = datas[0].Split('\t');

            if (datas.Length == 0 || datas[0].IndexOf("#") == 0)
            {
                continue;//判断有错误,如果未找到该字符串,则为 -1。 如果 value 为 String.Empty,则返回值为 0
            }
            if (datas.Length == 1 && datas[0] == "")
            {
                continue;
            }
            if (keyLine < 0)
            {
                keyLine = nLine;
            }
            else
            {
                if (nLine == keyLine + 1)
                {
                    typeLine = nLine;
                }
            }


            WDBSheetLine sheetLine = new WDBSheetLine();
            sheetLine.m_Line = new object[datas.Length];

            for (int col = 0; col < datas.Length; ++col)
            {
                //								if (nLine == keyLine)
                //										data.m_FieldName.Add (datas [col], col);
                if (nLine == typeLine)
                {
                    TYPE strType = nameToType(datas[col]);
                    if (strType == TYPE.TYPE_INVALID)
                    {
                        throw new Exception("failed to parse type: " + datas[col]);
                    }
                    _type.Add(col, strType);
                    data.m_Type.Add(strType);
                    continue;
                }
                if (nLine == keyLine)
                {
                    sheetLine.m_Line[col] = datas[col];
                }
                else
                {
                    sheetLine.m_Line[col] = ConvertValue(datas[col], _type[col]);
                }
            }
            if (nLine != typeLine)
            {
                sheetList.Add(sheetLine);
            }
        }

        if (sheetList.Count > 0)
        {
            data.m_Data = new WDBSheetLine[sheetList.Count];
            for (int n = 0; n < sheetList.Count; ++n)
            {
                data.m_Data[n] = sheetList[n];
            }
            sheetList.Clear();
            data.Init();
        }

        return(data);
    }
Beispiel #9
0
    private void OnLoadTextCallback(string path, byte[] bytes)
    {
        if (!mLoadHandles.ContainsKey(path))
        {
            //出现严重错误
            return;
        }
        string text = "";

        LoadHandler handle = mLoadHandles[path] as LoadHandler;

        if (handle.isXML)
        {
            text = System.Text.Encoding.UTF8.GetString(bytes);
        }
        else
        {
            text = System.Text.Encoding.Unicode.GetString(bytes);
        }

        if (string.IsNullOrEmpty(text))
        {
            return;
        }

        //Hashtable tb = new Hashtable(new CustomEqualityComparer());

        DataTable tb = new DataTable();

        if (!handle.isXML)
        {
            WDBData dbData = null;
            try
            {
                dbData = TextAnalyze.Analyze(text);
            }
            catch (Exception analyzeException)
            {
                throw new Exception("加载" + path + "失败: " + analyzeException.Message);
            }

            for (int i = 0; i < dbData.GetRecordCount(); ++i)
            {
                WDBSheetLine line = dbData.GetDataByNumber(i);

                if (line != null)
                {
                    object item = System.Activator.CreateInstance(handle.type);
                    try
                    {
                        tb.Add(loadLine(line, item, handle.keyIdx), item);
                    }
                    catch (Exception exp)
                    {
                        throw new Exception("解析" + path + "失败: " + exp.Message);
                    }
                }
            }
        }
        else
        {
            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(text);
            XmlNode node = xDoc.FirstChild;
            node = node.NextSibling;
            XmlNodeList nodeList = node.ChildNodes;
            for (int i = 0; i < nodeList.Count; ++i)
            {
                XmlNode childNode = nodeList[i];

                if (!string.IsNullOrEmpty(childNode.Name) &&
                    childNode.LocalName == "#comment")
                {
                    continue;
                }
                object item = System.Activator.CreateInstance(handle.type);

                Type itemType = item.GetType();
                System.Reflection.FieldInfo[] fields = itemType.GetFields();

                foreach (System.Reflection.FieldInfo f in fields)
                {
                    XmlNode nd = childNode.Attributes.GetNamedItem(f.Name);
                    if (nd != null)
                    {
                        if (f.FieldType.Name == "Int32")
                        {
                            f.SetValue(item, System.Convert.ToInt32(nd.Value));
                        }
                        if (f.FieldType.Name == "Single")
                        {
                            f.SetValue(item, System.Convert.ToSingle(nd.Value));
                        }
                        if (f.FieldType.Name == "String")
                        {
                            f.SetValue(item, nd.Value);
                        }
                    }
                }

                tb.Add(fields[0].GetValue(item), item);
            }
        }

        mLoadHandles.Remove(path);
        mTableList.Add((int)handle.dataType, tb);


        if (mLoadHandles.Count <= 0)
        {
            OnAllLoad();
        }
    }