Пример #1
0
        public static void CreateDictionary()
        {
            Regex rgx = new Regex("[^a-zA-Z0-9 -]");

            System.Net.WebClient wc = new System.Net.WebClient();
            string webData          = wc.DownloadString("https://raw.githubusercontent.com/LagoLunatic/wwrando/9f4752b6defbc5849ef52044422109b36f2ad790/logic/item_locations.txt");

            string[] Lines = webData.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

            List <string> DictionaryLines = new List <string> {
                "DictionaryName,LocationName,ItemName,LocationArea,ItemSubType,SpoilerLocation,SpoilerItem,EntrancePair"
            };

            LogicObjects.LogicDictionaryEntry Item = new LogicObjects.LogicDictionaryEntry();

            foreach (var i in Lines)
            {
                string Line = i.Trim();
                //Debugging.Log(Line);
                bool Unimplimented = false;
                if (Line.StartsWith("#"))
                {
                    Line.Replace("#", "");
                    Unimplimented = true;
                }
                if (Line.Contains(" -") && !Line.StartsWith("-") && !Line.Contains("\"") && Line.Contains(":") && !Line.Contains("Original item:") && !Line.Contains("Note:") && !Line.Contains("/"))
                {
                    if (!string.IsNullOrWhiteSpace(Item.DictionaryName))
                    {
                        string DictionaryLine = $"{Item.DictionaryName},{Item.LocationName},{Item.ItemName},{Item.LocationArea},{Item.ItemSubType},{Item.SpoilerLocation},{Item.SpoilerItem},";
                        DictionaryLines.Add(DictionaryLine.Replace("  ", " "));
                    }
                    Item = new LogicObjects.LogicDictionaryEntry();
                    var AllParts = Line.Split(new string[] { " -" }, StringSplitOptions.None);

                    string CombineParts = "";
                    for (var j = 1; j < AllParts.Length; j++)
                    {
                        string Seperater = (j == AllParts.Length - 1) ? "" : " -";
                        CombineParts = CombineParts + AllParts[j] + Seperater;
                    }

                    string[] Parts = new string[2] {
                        AllParts[0], CombineParts
                    };


                    Item.ItemSubType     = "Item";
                    Item.LocationArea    = Parts[0].Trim().Replace("#", "");
                    Item.LocationName    = Parts[1].Substring(0, Parts[1].IndexOf(":")).Trim();
                    Item.SpoilerLocation = Item.LocationName;
                    Item.DictionaryName  = Item.LocationArea + " " + rgx.Replace(Parts[1].Trim(), "").Replace("-", "");
                    Item.LocationName    = (Unimplimented) ? "" : Item.LocationName;
                }
                if (Line.Contains("Original item:"))
                {
                    Item.ItemName    = Line.Split(':')[1].Trim();
                    Item.SpoilerItem = Item.ItemName;
                }
            }
            SaveFileDialog saveDic = new SaveFileDialog
            {
                Filter   = "CSV File (*.csv)|*.csv",
                Title    = "Save Dictionary File",
                FileName = "WWRDICTIONARYV" + "1.7.0" + ".csv"
            };

            saveDic.ShowDialog();
            File.WriteAllLines(saveDic.FileName, DictionaryLines);
        }
Пример #2
0
        public static void CreateMinishLogDic()
        {
            var MinishLogicFile = File.ReadAllLines(@"D:\Emulated Games\Emulator\mGBA-0.7.3-win64\MinishRandomizer.v0.6.1a\MinishRandomizer.v0.6.1a\default.logic");

            bool AtLogic      = false;
            bool IsInIf       = false;
            bool IsInElse     = false;
            bool atKinstones  = false;
            bool atRupeeMania = false;

            LogicObjects.TrackerInstance MinishLogic = new LogicObjects.TrackerInstance
            {
                Logic           = new List <LogicObjects.LogicEntry>(),
                LogicDictionary = new List <LogicObjects.LogicDictionaryEntry>(),
                GameCode        = "MCR",
                LogicVersion    = 1
            };


            string CurrentLocation = "Overworld";

            foreach (var i in MinishLogicFile)
            {
                if (i.Trim().StartsWith("#Kinstone"))
                {
                    atKinstones = true;
                }
                if (i.Trim().StartsWith("HearthPot;"))
                {
                    atKinstones = false;
                }
                if (i.Trim().StartsWith("!ifdef - RUPEEMANIA"))
                {
                    atRupeeMania = true;
                }
                if (i.Trim() == "# Item Macro Helpers")
                {
                    AtLogic = true;
                }
                if (i.Trim() == "#Unrandomized locations")
                {
                    AtLogic = false;
                }
                if (!AtLogic)
                {
                    continue;
                }
                if (string.IsNullOrWhiteSpace(i))
                {
                    continue;
                }
                if (i.Trim().StartsWith("#"))
                {
                    continue;
                }

                if (i.Contains("!ifdef") || i.Contains("!ifndef"))
                {
                    IsInIf = true; continue;
                }
                if (i.Contains("!else"))
                {
                    IsInElse = true; IsInIf = false; continue;
                }
                if (i.Contains("!endif"))
                {
                    IsInElse = false; IsInIf = false; continue;
                }

                //if (IsInElse) { continue; }

                string CleanedLine = i.Replace("Items.", "").Replace("Helpers.", "").Replace("Locations.", "");

                var Data = CleanedLine.Split(';').Select(x => x.Trim()).ToArray();

                if (Data.Count() < 4)
                {
                    continue;
                }
                LogicObjects.LogicEntry           Entry = new LogicObjects.LogicEntry();
                LogicObjects.LogicDictionaryEntry Dic   = new LogicObjects.LogicDictionaryEntry();

                Entry.DictionaryName = Data[0];

                if (Data[0].Contains(":"))
                {
                    Data[0] = Data[0].Substring(0, Data[0].IndexOf(":"));
                }

                CurrentLocation = "Overworld";

                var LogicData = Data[3].Split(',').Select(x => x.Replace(")", "").Replace("(", "").Replace("|", "").Replace("&", "")).ToList();
                var AreaData  = LogicData.Find(x => x.Contains("Access"));
                if (AreaData != null)
                {
                    string Loc = string.Concat(AreaData.Replace("Access", "").Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
                    CurrentLocation = Loc;
                }


                if (MinishLogic.Logic.Where(x => x.DictionaryName == Entry.DictionaryName).Any())
                {
                    continue;
                }
                Console.WriteLine(Entry.DictionaryName);

                Entry.IsFake         = Data[1] == "Helper";
                Entry.Checked        = false;
                Entry.ItemSubType    = "Item";
                Entry.RandomizedItem = -2;
                Entry.SpoilerRandom  = -2;
                if (!Entry.IsFake)
                {
                    Dic.DictionaryName  = Entry.DictionaryName;
                    Dic.LocationArea    = CurrentLocation;
                    Dic.LocationName    = string.Concat(Data[0].Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
                    Dic.SpoilerLocation = Data[0];

                    string ItemName    = "";
                    string DicItemName = "";
                    if (Data.Count() > 4)
                    {
                        DicItemName = Data[4];
                        if (DicItemName.Contains("#"))
                        {
                            DicItemName = DicItemName.Substring(0, DicItemName.IndexOf("#")).Trim();
                        }
                        if (DicItemName.Contains("'"))
                        {
                            DicItemName = DicItemName.Substring(0, DicItemName.IndexOf("'")).Trim();
                        }
                        if (string.IsNullOrWhiteSpace(DicItemName))
                        {
                            DicItemName = "";
                        }
                        ItemName = string.Concat(DicItemName.Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
                    }

                    Dic.SpoilerItem = DicItemName;
                    Dic.ItemName    = ItemName;
                    Dic.ItemSubType = "Item";
                    MinishLogic.LogicDictionary.Add(Dic);

                    Entry.LocationArea = CurrentLocation;
                    Entry.LocationName = string.Concat(Data[0].Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
                    Entry.ItemName     = ItemName;
                    Console.WriteLine(ItemName);
                }

                MinishLogic.Logic.Add(Entry);
                Console.WriteLine("================");
            }

            LogicObjects.MainTrackerInstance = MinishLogic;
            MainInterface.CurrentProgram.PrintToListBox();
            MainInterface.CurrentProgram.ResizeObject();
            MainInterface.CurrentProgram.FormatMenuItems();

            List <string> csv = new List <string> {
                "DictionaryName,LocationName,ItemName,LocationArea,ItemSubType,SpoilerLocation,SpoilerItem"
            };

            foreach (LogicObjects.LogicDictionaryEntry entry in MinishLogic.LogicDictionary)
            {
                csv.Add(string.Format("{0},{1},{2},{3},{4},{5},{6}",
                                      entry.DictionaryName, entry.LocationName, entry.ItemName, entry.LocationArea,
                                      entry.ItemSubType, entry.SpoilerLocation, entry.SpoilerItem));
            }

            SaveFileDialog saveDic = new SaveFileDialog
            {
                Filter   = "CSV File (*.csv)|*.csv",
                Title    = "Save Dictionary File",
                FileName = "MCRDICTIONARYV6.csv"
            };

            saveDic.ShowDialog();
            File.WriteAllLines(saveDic.FileName, csv);

            SaveFileDialog saveDialog = new SaveFileDialog {
                Filter = "Logic File (*.txt)|*.txt", FilterIndex = 1
            };

            if (saveDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var          logicText = LogicEditing.WriteLogicToArray(MinishLogic, true).ToList();
            StreamWriter LogicFile = new StreamWriter(File.Open(saveDialog.FileName, FileMode.Create));

            for (int i = 0; i < logicText.Count; i++)
            {
                if (i == logicText.Count - 1)
                {
                    LogicFile.Write(logicText[i]); break;
                }
                LogicFile.WriteLine(logicText[i]);
            }
            LogicFile.Close();

            return;
        }