示例#1
0
        public void writeTooltips()
        {
            List <string> langFiles = getAddonLangPaths();

            for (int l = 0; l < langFiles.Count(); l++)
            {
                string file = langFiles.ElementAt(l);

                string thisLang     = file.Substring(file.LastIndexOf('\\') + 1);
                string thisLangCopy = thisLang;
                thisLang = thisLang.Substring(thisLang.LastIndexOf('_') + 1);
                string outputPath = Path.Combine(GamePath, "resource", "tooltips_" + thisLang);

                alreadyHasKeys.Clear();

                KeyValue[] addon_lang = KVParser.KV1.ParseAll(File.ReadAllText(file));

                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.HasChildren)
                        {
                            IEnumerable <KeyValue> children2 = child.Children;
                            for (int j = 0; j < children2.Count(); j++)
                            {
                                KeyValue child2 = children2.ElementAt(j);
                                alreadyHasKeys.Add(child2.Key.ToLower());
                            }
                        }
                    }
                }

                StringBuilder content = new StringBuilder();

                // 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 " + thisLangCopy +
                    ", nor modifiers with the property \"IsHidden\" \"1\".\n" +
                    "// **********************************************************************************************************************\n";
                content.Append(header);


                string head1 = "\n\t\t// ******************** HEROES ********************\n";
                content.Append(head1);
                for (int i = 0; i < heroesEntries.Count(); i++)
                {
                    HeroEntry hero = heroesEntries.ElementAt(i);
                    if (!alreadyHasKeys.Contains(hero.Name.Key.ToLower()))
                    {
                        content.Append(hero.ToString());
                    }
                }

                string head2 = "\n\t\t// ******************** UNITS ********************\n";
                content.Append(head2);
                for (int i = 0; i < unitEntries.Count(); i++)
                {
                    UnitEntry unit = unitEntries.ElementAt(i);
                    if (!alreadyHasKeys.Contains(unit.Name.Key.ToLower()))
                    {
                        content.Append(unit.ToString());
                    }
                }

                string head3 = "\n\t\t// ******************** ABILITY MODIFIERS ********************\n";
                content.Append(head3);
                for (int i = 0; i < modifierAbilityKeys.Count(); i++)
                {
                    ModifierEntry mod = new ModifierEntry(modifierAbilityKeys.ElementAt(i));
                    if (!alreadyHasKeys.Contains(mod.Name.Key.ToLower()))
                    {
                        content.Append(mod + "\n");
                    }
                }

                string head6 = "\n\t\t// ******************** ITEM MODIFIERS ********************\n";
                content.Append(head6);
                for (int i = 0; i < modifierItemKeys.Count(); i++)
                {
                    //ModifierEntry mod = modifierItemEntries.ElementAt(i);
                    ModifierEntry mod = new ModifierEntry(modifierItemKeys.ElementAt(i));
                    if (!alreadyHasKeys.Contains(mod.Name.Key.ToLower()))
                    {
                        content.Append(mod + "\n");
                    }
                }

                string head4 = "\n\t\t// ******************** ABILITIES ********************\n";
                content.Append(head4);
                for (int i = 0; i < abilityEntries.Count(); i++)
                {
                    AbilityEntry abil = abilityEntries.ElementAt(i);
                    if (!alreadyHasKeys.Contains(abil.Name.Key.ToLower()))
                    {
                        content.Append(abil + "\n");
                    }
                    else
                    {
                        // the addon_language already has this ability. but let's check
                        // if there are any new AbilitySpecials.
                        bool missingAbilSpecials = false;
                        foreach (Pair p in abil.AbilitySpecials)
                        {
                            if (!alreadyHasKeys.Contains(p.Key.ToLower()))
                            {
                                // the addon_language doesn't contain this abil special.
                                content.Append(p.ToString());
                                missingAbilSpecials = true;
                            }
                        }
                        if (missingAbilSpecials)
                        {
                            content.Append("\n");
                        }
                    }
                }

                string head5 = "\n\t\t// ******************** ITEMS ********************\n";
                content.Append(head5);
                for (int i = 0; i < itemEntries.Count(); i++)
                {
                    AbilityEntry item = itemEntries.ElementAt(i);
                    if (!alreadyHasKeys.Contains(item.Name.Key.ToLower()))
                    {
                        content.Append(item + "\n");
                    }
                    else
                    {
                        // the addon_language already has this ability. but let's check
                        // if there are any new AbilitySpecials.
                        bool missingAbilSpecials = false;
                        foreach (Pair p in item.AbilitySpecials)
                        {
                            if (!alreadyHasKeys.Contains(p.Key.ToLower()))
                            {
                                // the addon_language doesn't contain this abil special.
                                content.Append(p.ToString());
                                missingAbilSpecials = true;
                            }
                        }
                        if (missingAbilSpecials)
                        {
                            content.Append("\n");
                        }
                    }
                }

                // open the tooltips.txt in a text editor
                File.WriteAllText(outputPath, content.ToString(), Encoding.Unicode);
                Process.Start(outputPath);
            }
        }
示例#2
0
        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);
        }