Esempio n. 1
0
        public static void FindPossibleValuesForKey(string file, string key)
        {
            KVLib.KeyValue srcDoc = KVLib.KVParser.KV1.Parse(File.ReadAllText(file));

            List <string> foundValues = new List <string>();


            foreach (KVLib.KeyValue k in srcDoc.Children)
            {
                KVLib.KeyValue val = k[key];
                if (val == null)
                {
                    continue;
                }
                string sval = val.GetString();
                if (!foundValues.Contains(sval))
                {
                    foundValues.Add(sval);
                }
            }

            KVLib.KeyValue outDoc = new KVLib.KeyValue("PossibleValues");
            int            count  = 0;

            foreach (string s in foundValues)
            {
                outDoc += new KVLib.KeyValue(count.ToString()) + s;
                count++;
            }

            File.WriteAllText(key + ".txt", outDoc.ToString());
        }
Esempio n. 2
0
        public static void FindPossibleValuesForKey(string file, string key)
        {
            KVLib.KeyValue srcDoc = KVLib.KVParser.KV1.Parse(File.ReadAllText(file));

            List<string> foundValues = new List<string>();


            foreach (KVLib.KeyValue k in srcDoc.Children)
            {
                KVLib.KeyValue val = k[key];
                if (val == null) continue;
                string sval = val.GetString();
                if (!foundValues.Contains(sval)) foundValues.Add(sval);
            }

            KVLib.KeyValue outDoc = new KVLib.KeyValue("PossibleValues");
            int count = 0;
            foreach (string s in foundValues)
            {
                outDoc += new KVLib.KeyValue(count.ToString()) + s;
                count++;
            }

            File.WriteAllText(key + ".txt", outDoc.ToString());
        }
Esempio n. 3
0
        public static void GenerateDataPropertiesFromKeyValues(string file, string baseKey, string outputFile)
        {
            KVLib.KeyValue kv = KVLib.KVParser.KV1.Parse(File.ReadAllText(file));
            kv = kv[baseKey];

            KVLib.KeyValue doc = new KVLib.KeyValue("Schema");


            foreach (KVLib.KeyValue k in kv.Children)
            {
                KVLib.KeyValue property = new KVLib.KeyValue(k.Key);
                property += new KVLib.KeyValue("Category") + "Misc";
                property += new KVLib.KeyValue("Description") + "No Description Set";
                string type = DetermineType(k);
                property += new KVLib.KeyValue("Type") + type;
                property += new KVLib.KeyValue("DefaultValue") + k.GetString();

                doc += property;
            }

            File.WriteAllText(outputFile, doc.ToString());
        }
Esempio n. 4
0
        public static void GenerateDataPropertiesFromKeyValues(string file, string baseKey, string outputFile)
        {
            KVLib.KeyValue kv = KVLib.KVParser.KV1.Parse(File.ReadAllText(file));
            kv = kv[baseKey];

            KVLib.KeyValue doc = new KVLib.KeyValue("Schema");


            foreach (KVLib.KeyValue k in kv.Children)
            {
                KVLib.KeyValue property = new KVLib.KeyValue(k.Key);
                property += new KVLib.KeyValue("Category") + "Misc";
                property += new KVLib.KeyValue("Description") + "No Description Set";
                string type = DetermineType(k);
                property += new KVLib.KeyValue("Type") + type;
                property += new KVLib.KeyValue("DefaultValue") + k.GetString();

                doc += property;


            }

            File.WriteAllText(outputFile, doc.ToString());
        }
Esempio n. 5
0
        static string DetermineType(KVLib.KeyValue k)
        {
            //If they key contains 'Is', 'Can', 'Has', then it's probably a bool
            if (k.Key.IndexOf("Is", StringComparison.OrdinalIgnoreCase) != -1 ||
                k.Key.IndexOf("Can", StringComparison.OrdinalIgnoreCase) != -1 ||
                k.Key.IndexOf("Has", StringComparison.OrdinalIgnoreCase) != -1)
            {
                return("bool");
            }

            //Attributes are always ints
            if (k.Key.IndexOf("Attribute", StringComparison.OrdinalIgnoreCase) != -1)
            {
                return("int");
            }

            //Determine the type of the KV
            List <string> PossibleTypes = new List <string>()
            {
                "float",
                "string",
                "bool",
                "int",
            };

            float f;

            if (!k.TryGet(out f)) //Not a float
            {
                PossibleTypes.Remove("float");
            }
            int i;

            if (!k.TryGet(out i))
            {
                PossibleTypes.Remove("int");
            }
            bool b;

            if (!k.TryGet(out b))
            {
                PossibleTypes.Remove("bool");
            }
            if (PossibleTypes.Count > 1) //If we have more than one type, it's probably not a string
            {
                PossibleTypes.Remove("string");
            }

            if (PossibleTypes.Count == 1)
            {
                //Got it, return that one
                return(PossibleTypes.First());
            }

            //If the possible types are float or int, default to int
            if (PossibleTypes.Contains("int") && PossibleTypes.Contains("float") &&
                !PossibleTypes.Contains("bool"))
            {
                return("int");
            }

            if (k.GetInt() < 0 || k.GetInt() > 1) //If the number is less than 0 or greater than 1, assume int
            {
                return("int");
            }
            //If the value is '0' or '1', it could be float int or bool.  If the name didn't have 'is', lets default to
            //lets default to int


            return("CANTDETERMINE");
        }
Esempio n. 6
0
        public void PSample6()
        {
            KeyValue kv = KVTestHelper.Sample6(new PenguinParser());

            Assert.AreEqual("DOTAAbilities", kv.Key);
        }
Esempio n. 7
0
 public void PSample8()
 {
     //Just a parsing test.
     KeyValue kv = KVTestHelper.Sample8(new PenguinParser());
 }