Beispiel #1
0
        public static void LoadInstance()
        {
            if (!Tools.PromptSave(LogicObjects.MainTrackerInstance))
            {
                return;
            }
            string file = Utility.FileSelect("Select A Save File", "MMR Tracker Save (*.MMRTSAV)|*.MMRTSAV");

            if (file == "")
            {
                return;
            }
            var backup = Utility.CloneTrackerInstance(LogicObjects.MainTrackerInstance);

            LogicObjects.MainTrackerInstance = new LogicObjects.TrackerInstance();
            //Try to load the save file with the new system. If that fails try wth the old system. If that fails restore the current instance and show an error.
            try { LogicObjects.MainTrackerInstance = JsonConvert.DeserializeObject <LogicObjects.TrackerInstance>(File.ReadAllText(file)); }
            catch
            {
                try
                {
                    string[] options = File.ReadAllLines(file);
                    LogicObjects.MainTrackerInstance.Logic = JsonConvert.DeserializeObject <List <LogicObjects.LogicEntry> >(options[0]);
                    if (options.Length > 1)
                    {
                        LogicObjects.MainTrackerInstance.LogicVersion = Int32.Parse(options[1].Replace("version:", ""));
                    }
                    else
                    {
                        MessageBox.Show("Save File Invalid!");
                        LogicObjects.MainTrackerInstance = backup;
                        return;
                    }
                }
                catch
                {
                    MessageBox.Show("Save File Invalid!");
                    LogicObjects.MainTrackerInstance = backup;
                    return;
                }
            }
            //Extra saftey checks for older save files
            LogicObjects.MainTrackerInstance.EntranceRando = LogicObjects.MainTrackerInstance.IsEntranceRando();
            if (LogicObjects.MainTrackerInstance.LogicVersion == 0)
            {
                LogicObjects.MainTrackerInstance.LogicVersion = VersionHandeling.GetVersionFromLogicFile(LogicObjects.MainTrackerInstance.RawLogicFile).Version;
            }
            return;
        }
Beispiel #2
0
 public static void UpdateNames(LogicObjects.TrackerInstance Instance)
 {
     string[] VersionData = VersionHandeling.GetDictionaryPath(Instance);
     if (VersionData.Count() > 0)
     {
         Instance.LogicDictionary = JsonConvert.DeserializeObject <List <LogicObjects.LogicDictionaryEntry> >(Utility.ConvertCsvFileToJsonObject(VersionData[0]));
     }
     foreach (var entry in Instance.Logic)
     {
         foreach (var dicent in Instance.LogicDictionary)
         {
             if (entry.DictionaryName == dicent.DictionaryName)
             {
                 entry.LocationName    = dicent.LocationName;
                 entry.ItemName        = dicent.ItemName;
                 entry.LocationArea    = dicent.LocationArea;
                 entry.ItemSubType     = dicent.ItemSubType;
                 entry.SpoilerItem     = dicent.SpoilerItem;
                 entry.SpoilerLocation = dicent.SpoilerLocation;
                 break;
             }
         }
     }
 }
Beispiel #3
0
        public static void CreateDictionary()
        {
            string file = Utility.FileSelect("Select A Logic File", "Logic File (*.txt)|*.txt");

            if (file == "")
            {
                return;
            }

            LogicObjects.TrackerInstance CDLogic = new LogicObjects.TrackerInstance();
            int LogicVersion = VersionHandeling.GetVersionFromLogicFile(File.ReadAllLines(file)).Version;

            LogicEditing.PopulateTrackerInstance(CDLogic);

            List <LogicObjects.SpoilerData> SpoilerLog = Tools.ReadHTMLSpoilerLog("", CDLogic);

            if (SpoilerLog.Count == 0)
            {
                return;
            }

            //For each entry in your logic list, check each entry in your spoiler log to find the rest of the data
            foreach (LogicObjects.LogicEntry entry in CDLogic.Logic)
            {
                foreach (LogicObjects.SpoilerData spoiler in SpoilerLog)
                {
                    if (spoiler.LocationID == entry.ID)
                    {
                        entry.IsFake          = false;
                        entry.LocationName    = spoiler.LocationName;
                        entry.SpoilerLocation = spoiler.LocationName;
                        entry.LocationArea    = spoiler.LocationArea;
                        entry.ItemSubType     = "Item";
                        if (entry.DictionaryName.Contains("Bottle:"))
                        {
                            entry.ItemSubType = "Bottle";
                        }
                        if (entry.DictionaryName.StartsWith("Entrance"))
                        {
                            entry.ItemSubType = "Entrance";
                        }

                        if (!CDLogic.EntranceRando)
                        {
                            if (entry.DictionaryName == "Woodfall Temple access")
                            {
                                entry.LocationArea = "Dungeon Entrance"; entry.ItemSubType = "Dungeon Entrance";
                            }
                            if (entry.DictionaryName == "Snowhead Temple access")
                            {
                                entry.LocationArea = "Dungeon Entrance"; entry.ItemSubType = "Dungeon Entrance";
                            }
                            if (entry.DictionaryName == "Great Bay Temple access")
                            {
                                entry.LocationArea = "Dungeon Entrance"; entry.ItemSubType = "Dungeon Entrance";
                            }
                            if (entry.DictionaryName == "Inverted Stone Tower Temple access")
                            {
                                entry.LocationArea = "Dungeon Entrance"; entry.ItemSubType = "Dungeon Entrance";
                            }
                        } //Dungeon Entrance Rando is dumb
                    }
                    if (spoiler.ItemID == entry.ID)
                    {
                        entry.IsFake      = false; //Not necessary, might cause problem but also might fix them ¯\_(ツ)_/¯
                        entry.ItemName    = spoiler.ItemName;
                        entry.SpoilerItem = spoiler.ItemName;
                    }
                }
            }

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

            //Write this data to list of strings formated as lines of csv and write that to a text file
            foreach (LogicObjects.LogicEntry entry in CDLogic.Logic)
            {
                if (!entry.IsFake)
                {
                    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 = "MMRDICTIONARYV" + LogicVersion + ".csv"
            };

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