Beispiel #1
0
 public static KVItemDto ToDto(this KVItem obj)
 {
     return(new()
     {
         K = obj.K,
         V = obj.V
     });
 }
Beispiel #2
0
        public static void FillByDictionary(this KVItem item, List <DictionaryItemKV> list)
        {
            if (item is null || string.IsNullOrWhiteSpace(item.V))
            {
                return;
            }
            var dic = list.Find(x => x.V == item.V);

            if (dic != null)
            {
                item.K = dic.K;
                item.V = dic.V;
            }
        }
Beispiel #3
0
        public static KVItem FillStandardByV(this KVItem obj, Type type)
        {
            if (string.IsNullOrWhiteSpace(obj.V))
            {
                throw new("V cant be null");
            }
            if (type.IsSubclassOf(typeof(DicItem)) == false)
            {
                throw new("type is not correct,must be subclass of StandardDictionary type");
            }
            var dic = Activator.CreateInstance(type) as DicItem;

            dic.V = obj.V;
            dic.FillByV();
            obj.K = dic.K;
            return(obj);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Dictionary <string, string> langdict = new Dictionary <string, string>();

            KVItem langtree = KVParser.ReadFromFile("tf_english.txt");

            for (int i = 0; i < langtree.subItems.Count; i++)
            {
                for (int x = 0; x < langtree.subItems[i].subItems.Count; x++)
                {
                    KVItem subitem = langtree.subItems[i].subItems[x];
                    string lower   = subitem.key.ToLower();

                    langdict.Add(lower, subitem.value);
                }
            }

            KVItem        tree    = KVParser.ReadFromFile("items.txt");
            List <short>  indexes = new List <short>();
            List <string> names   = new List <string>();

            for (int i = 0; i < tree.subItems.Count; i++)
            {
                string index = tree.subItems[i].key;

                for (int x = 0; x < tree.subItems[i].subItems.Count; x++)
                {
                    KVItem subitem = tree.subItems[i].subItems[x];

                    if (subitem.key == "item_name")
                    {
                        string lang = subitem.value;

                        if (lang.Substring(0, 1) == "#")
                        {
                            lang = langdict[lang.Substring(1).ToLower()];
                            if (lang.Length > 63)
                            {
                                lang = lang.Substring(0, 63);
                            }
                        }

                        indexes.Add(Int16.Parse(index));
                        names.Add(lang);

                        break;
                    }
                }
            }

            FileStream   fs = File.Create("item.db");
            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write((Int16)indexes.Count);
            for (int x = 0; x < indexes.Count; x++)
            {
                bw.Write(indexes[x]);
                bw.Write(names[x]);
            }

            bw.Close();
            fs.Close();

            Console.WriteLine("Completed. (" + indexes.Count + " items)");
        }