public void getCurrentAddonEnglish() { // Parse addon_english.txt KV KeyValue[] addonEnglishKeyVals = KVParser.ParseAllKVRootNodes(System.IO.File.ReadAllText(addonEnglishPath)); for (int i = 0; i < addonEnglishKeyVals.Length; i++) { } }
public void getUnitTooltips() { unitEntries.Clear(); KeyValue[] unitsKeyVals = KVParser.ParseAllKVRootNodes(System.IO.File.ReadAllText(unitsCustomPath)); IEnumerable <KeyValue> children = unitsKeyVals[0].Children; for (int i = 0; i < children.Count(); i++) { string unit = children.ElementAt(i).Key; if (unit != "Version") { unitEntries.Add(new UnitEntry(unit)); } } for (int i = 0; i < unitEntries.Count(); i++) { // Debug.WriteLine(unitEntries.ElementAt(i).ToString()); } }
private void parseLanguageFile() { KeyValue[] addon_lang = KVParser.ParseAllKVRootNodes(File.ReadAllText(Lang)); if (addon_lang.Count() > 0) { IEnumerable <KeyValue> rootChildren = addon_lang[0].Children; for (int k = 0; k < rootChildren.Count(); k++) { KeyValue child = rootChildren.ElementAt(k); if (child.Key == "Language") { // extract language name languageName = child.GetString(); } if (child.Key == "Tokens") { if (child.HasChildren) { // store the main addon_language keys and vals. LangKV = child.Children; // extract some basic info while we're here for (int i = 0; i < LangKV.Count(); i++) { KeyValue kv = LangKV.ElementAt(i); string v = kv.GetString(); if (kv.Key == "addon_game_name") { AddonName = v; } } } } } } }
public void getHeroesTooltips() { heroesEntries.Clear(); KeyValue[] heroesKeyVals = KVParser.ParseAllKVRootNodes(System.IO.File.ReadAllText(heroesCustomPath)); IEnumerable <KeyValue> children = heroesKeyVals[0].Children; for (int i = 0; i < children.Count(); i++) { KeyValue child = children.ElementAt(i); if (child.HasChildren) { IEnumerable <KeyValue> children2 = child.Children; for (int j = 0; j < children2.Count(); j++) { KeyValue child2 = children2.ElementAt(j); if (child2.Key == "override_hero") { HeroEntry h = new HeroEntry(child2.GetString()); //Debug.WriteLine(h.ToString()); } } } } }
private bool parse() { if (!File.Exists(wiki.Addon.HeroesCustomPath)) { return false; } KeyValue[] heroKeyVals = KVParser.ParseAllKVRootNodes(File.ReadAllText(wiki.Addon.HeroesCustomPath)); // ensure we can get to the main heroKey data. if (heroKeyVals.Count() == 0 || !heroKeyVals[0].HasChildren) { return false; } IEnumerable<KeyValue> entries = heroKeyVals[0].Children; for (int i = 0; i < entries.Count(); i++) { // create a new heroKey hero from this data HeroEntry hero = new HeroEntry(); KeyValue heroKey = entries.ElementAt(i); hero.kvName = heroKey.Key; if (heroKey.HasChildren) { IEnumerable<KeyValue> children = heroKey.Children; for (int j = 0; j < children.Count(); j++) { KeyValue child = children.ElementAt(j); string k = child.Key; string v = child.GetString(); // Extract num of abilities. if (k == "AbilityLayout") { hero.numAbilities = Int32.Parse(v); } // extract heroKey name. else if (k == "override_hero") { hero.baseName = v; } else if (k.Contains("Ability")) { int abilNum = Int32.Parse(k.Substring(7)); hero.abilities[abilNum] = v; } else if (k == "MovementTurnRate") { hero.movementTurnRate = v; } else if (k == "MovementSpeed") { hero.movementSpeed = v; } else if (k == "VisionDaytimeRange") { hero.visionDaytimeRange = v; } else if (k == "VisionNighttimeRange") { hero.visionNighttimeRange = v; } else if (k == "MovementSpeed") { hero.movementSpeed = v; } else if (k == "StatusHealth") { hero.statusHealth = v; } else if (k == "AttackCapabilities") { hero.attackCapabilities = v; } else if (k == "AttackRate") { hero.attackRate = v; } else if (k == "StatusMana") { hero.statusMana = v; } else if (k == "AttackDamageMin") { hero.attackDamageMin = v; } else if (k == "AttackDamageMax") { hero.attackDamageMax = v; } else if (k == "MovementCapabilities") { hero.movementCapabilities = v; } } // now extract the useful info from the LangKV. for (int j = 0; j < wiki.LangKV.Count(); j++) { KeyValue kv = wiki.LangKV.ElementAt(j); // check for ex. npc_dota_hero_blah if (kv.Key == hero.baseName) { hero.actualName = kv.GetString(); // this is the only useful thing to extract for heroes, so break here is fine. break; } } heroEntries.Add(hero); } } return true; }
public void writeTooltips() { alreadyHasKeys.Clear(); if (Directory.Exists(addonEnglishPath)) { KeyValue[] currAddonEnglish = KVParser.ParseAllKVRootNodes(System.IO.File.ReadAllText(addonEnglishPath)); IEnumerable <KeyValue> children = currAddonEnglish[0].Children; for (int i = 0; i < children.Count(); i++) { KeyValue child = children.ElementAt(i); if (child.HasChildren) { IEnumerable <KeyValue> children2 = child.Children; for (int j = 0; j < children2.Count(); j++) { KeyValue child2 = children2.ElementAt(j); alreadyHasKeys.Add(child2.Key); } } } } // WriteAllText will clear the contents of this file first string header = "// **********************************************************************************************************************\n" + "// This file contains generated tooltips created from the files in the scripts/npc directory of this mod.\n" + "// It does not contain tooltips already defined in addon_english.txt, nor modifiers with the property \"IsHidden\" \"1\".\n" + "// **********************************************************************************************************************\n"; System.IO.File.WriteAllText(generatedTooltips, header, Encoding.Unicode); string head1 = "\n// ******************** HEROES ********************\n"; System.IO.File.AppendAllText(GeneratedTooltips, head1, Encoding.Unicode); for (int i = 0; i < heroesEntries.Count(); i++) { HeroEntry hero = heroesEntries.ElementAt(i); if (!alreadyHasKeys.Contains(hero.Hero.Key)) { System.IO.File.AppendAllText(GeneratedTooltips, hero.ToString(), Encoding.Unicode); } } string head2 = "\n// ******************** UNITS ********************\n"; System.IO.File.AppendAllText(GeneratedTooltips, head2, Encoding.Unicode); for (int i = 0; i < unitEntries.Count(); i++) { UnitEntry unit = unitEntries.ElementAt(i); if (!alreadyHasKeys.Contains(unit.Name.Key)) { System.IO.File.AppendAllText(GeneratedTooltips, unit.ToString(), Encoding.Unicode); } } string head3 = "\n// ******************** ABILITY MODIFIERS ********************\n"; System.IO.File.AppendAllText(GeneratedTooltips, head3, Encoding.Unicode); for (int i = 0; i < modifierAbilityEntries.Count(); i++) { ModifierEntry mod = modifierAbilityEntries.ElementAt(i); if (!alreadyHasKeys.Contains(mod.Name.Key)) { System.IO.File.AppendAllText(GeneratedTooltips, mod.ToString() + "\n", Encoding.Unicode); } } string head6 = "\n// ******************** ITEM MODIFIERS ********************\n"; System.IO.File.AppendAllText(GeneratedTooltips, head6, Encoding.Unicode); for (int i = 0; i < modifierItemEntries.Count(); i++) { ModifierEntry mod = modifierItemEntries.ElementAt(i); if (!alreadyHasKeys.Contains(mod.Name.Key)) { System.IO.File.AppendAllText(GeneratedTooltips, mod.ToString() + "\n", Encoding.Unicode); } } string head4 = "\n// ******************** ABILITIES ********************\n"; System.IO.File.AppendAllText(GeneratedTooltips, head4, Encoding.Unicode); for (int i = 0; i < abilityEntries.Count(); i++) { AbilityEntry abil = abilityEntries.ElementAt(i); if (!alreadyHasKeys.Contains(abil.Name.Key)) { System.IO.File.AppendAllText(GeneratedTooltips, abil.ToString() + "\n", Encoding.Unicode); } } string head5 = "\n// ******************** ITEMS ********************\n"; System.IO.File.AppendAllText(GeneratedTooltips, head5, Encoding.Unicode); for (int i = 0; i < itemEntries.Count(); i++) { AbilityEntry item = itemEntries.ElementAt(i); if (!alreadyHasKeys.Contains(item.Name.Key)) { System.IO.File.AppendAllText(GeneratedTooltips, item.ToString() + "\n", Encoding.Unicode); } } /*string head7 = "\n// ******************** HIDDEN MODIFIERS ********************\n"; * System.IO.File.AppendAllText(GeneratedTooltips, head7, Encoding.Unicode); * for (int i = 0; i < hiddenModifierEntries.Count(); i++) * { * ModifierEntry mod = hiddenModifierEntries.ElementAt(i); * if (!alreadyHasKeys.Contains(mod.Name.Key)) * { * System.IO.File.AppendAllText(GeneratedTooltips, mod.ToString() + "\n", Encoding.Unicode); * } * }*/ // open the tooltips.txt in a text editor Process.Start(Path.Combine(gamePath, "resource", "tooltips.txt")); //MessageBox.Show("Tooltips successfully generated in: " + Path.Combine(gamePath,"resource", "tooltips.txt"), "Success", // MessageBoxButtons.OK, MessageBoxIcon.Information); }
public void getAbilityTooltips(bool items) { if (items) { itemEntries.Clear(); modifierItemEntries.Clear(); } else { AbilityEntries.Clear(); modifierAbilityEntries.Clear(); } //hiddenModifierEntries.Clear(); // Parse abilities_custom.txt KV KeyValue[] abilitiesCustomKeyVals = KVParser.ParseAllKVRootNodes(System.IO.File.ReadAllText(AbilitiesCustomPath)); if (items) { abilitiesCustomKeyVals = KVParser.ParseAllKVRootNodes(System.IO.File.ReadAllText(ItemsCustomPath)); } IEnumerable <KeyValue> abilityNames = abilitiesCustomKeyVals[0].Children; for (int i = 0; i < abilityNames.Count(); i++) { KeyValue ability = abilityNames.ElementAt(i); if (ability.Key == "Version") { continue; } // NOTE: can't have a blank comment (//) above the ability or else the Key will be blank. //Debug.WriteLine("Abil name: " + ability.Key); if (ability.HasChildren) { IEnumerable <KeyValue> children = ability.Children; // Find the abilityspecial stuff. for (int j = 0; j < children.Count(); j++) { KeyValue child = children.ElementAt(j); if (child.Key == "AbilitySpecial" || child.Key == "Modifiers") { bool modifiers = false; if (child.Key == "Modifiers") { modifiers = true; } // We have the AbilitySpecial now. See if there is actually anything in it. if (child.HasChildren) { List <string> kvs = new List <string>(); IEnumerable <KeyValue> children2 = child.Children; for (int k = 0; k < children2.Count(); k++) { KeyValue child2 = children2.ElementAt(k); bool isHidden = false; if (child2.HasChildren) { IEnumerable <KeyValue> children3 = child2.Children; for (int l = 0; l < children3.Count(); l++) { KeyValue child3 = children3.ElementAt(l); if (modifiers) { if (child3.Key == "IsHidden") { // Ensure it's actually hidden. Debug.WriteLine("IsHidden? " + child3.GetString()); if (child3.GetString() == "1") { isHidden = true; } } } else // we have a modifier, not ability. { // Map item name to its item specials. if (child3.Key != "var_type") { kvs.Add(child3.Key); } } } } // we're done going through all the children of this ability/modifier. if (modifiers) { if (!isHidden) { if (items) { modifierItemEntries.Add(new ModifierEntry(child2.Key)); } else { modifierAbilityEntries.Add(new ModifierEntry(child2.Key)); } } else { //hiddenModifierEntries.Add(new ModifierEntry(child2.Key)); } } } if (!modifiers) { if (items) { itemEntries.Add(new AbilityEntry(ability.Key, kvs)); } else { AbilityEntries.Add(new AbilityEntry(ability.Key, kvs)); } } } } } } } }
private static KeyValue parseKVStream(Stream s) { return(KVParser.ParseAllKVRootNodes(s.ReadAsUTF8())[0]); }