Ejemplo n.º 1
0
        public static LogicObjects.VersionInfo GetVersionDataFromLogicFile(string[] LogicFile)
        {
            LogicObjects.VersionInfo versionData = new LogicObjects.VersionInfo {
                Version = 0, Gamecode = "MMR"
            };
            LogicObjects.LogicFile NewformatLogicFile = null;
            try { NewformatLogicFile = LogicObjects.LogicFile.FromJson(string.Join("", LogicFile)); }
            catch { }

            if (NewformatLogicFile != null)
            {
                versionData.Version = NewformatLogicFile.Version;
                return(versionData);
            }

            if (LogicFile[0].Contains("-version"))       //Ensure the first line of this file has version data
            {
                if (!LogicFile[0].Contains("-version ")) //Check if the version line has game code data after "-version"
                {
                    var i = LogicFile[0].Split(' ');
                    versionData.Gamecode = i[0].Replace("-version", "");
                }
                var j = LogicFile[0].Split(' ');
                if (j.Count() > 1 && int.TryParse(j[1], out int Ver))
                {
                    versionData.Version = Ver;
                }
            }
            return(versionData);
        }
Ejemplo n.º 2
0
        public static bool PopulateTrackerInstance(LogicObjects.TrackerInstance instance)
        {
            LogicObjects.LogicFile NewformatLogicFile = null;
            try { NewformatLogicFile = LogicObjects.LogicFile.FromJson(string.Join("", instance.RawLogicFile)); }
            catch { }

            if (NewformatLogicFile == null)
            {
                instance.JsonLogic = false;
                return(PopulatePre115TrackerInstance(instance));
            }
            else
            {
                instance.JsonLogic = true;
                return(PopulatePost115TrackerInstance(instance));
            }
        }
Ejemplo n.º 3
0
 public static string[] WriteLogicToJson(LogicObjects.TrackerInstance Instance)
 {
     LogicObjects.LogicFile LogicFile = new LogicObjects.LogicFile
     {
         Logic   = new List <LogicObjects.JsonFormatLogicItem>(),
         Version = Instance.LogicVersion
     };
     foreach (var i in Instance.Logic)
     {
         LogicObjects.JsonFormatLogicItem Newentry = new LogicObjects.JsonFormatLogicItem();
         Newentry.Id               = i.DictionaryName;
         Newentry.RequiredItems    = i.Required.Select(x => Instance.Logic[x].DictionaryName).ToList();
         Newentry.ConditionalItems = i.Conditionals.Select(x => x.Select(y => Instance.Logic[y].DictionaryName).ToList()).ToList();
         Newentry.TimeAvailable    = (LogicObjects.TimeOfDay)i.AvailableOn;
         Newentry.TimeNeeded       = (LogicObjects.TimeOfDay)i.NeededBy;
         Newentry.IsTrick          = i.IsTrick;
         Newentry.TrickTooltip     = i.TrickToolTip;
         LogicFile.Logic.Add(Newentry);
     }
     return(new string[] { LogicFile.ToString() });
 }
Ejemplo n.º 4
0
        public static bool PopulatePost115TrackerInstance(LogicObjects.TrackerInstance instance)
        {
            LogicObjects.LogicFile NewformatLogicFile = LogicObjects.LogicFile.FromJson(string.Join("", instance.RawLogicFile));
            instance.Logic.Clear();
            instance.DicNameToID.Clear();
            instance.EntrancePairs.Clear();
            instance.LogicVersion = NewformatLogicFile.Version;
            instance.GameCode     = "MMR";

            if (instance.LogicDictionary == null || instance.LogicDictionary.Count < 1)
            {
                string DictionaryPath = VersionHandeling.GetDictionaryPath(instance, true);
                if (!string.IsNullOrWhiteSpace(DictionaryPath))
                {
                    try
                    {
                        instance.LogicDictionary = JsonConvert.DeserializeObject <List <LogicObjects.LogicDictionaryEntry> >(Utility.ConvertCsvFileToJsonObject(File.ReadAllLines(DictionaryPath)));
                    }
                    catch { MessageBox.Show($"The Dictionary File \"{DictionaryPath}\" has been corrupted. The tracker will not function correctly."); }
                }
                else
                {
                    MessageBox.Show($"A valid dictionary file could not be found for this logic. The tracker will not function correctly.");
                }
            }

            Dictionary <string, int> LogicNametoId = new Dictionary <string, int>();
            int DicCounter = 0;

            foreach (var i in NewformatLogicFile.Logic)
            {
                LogicNametoId.Add(i.Id, DicCounter);
                DicCounter++;
            }

            LogicObjects.LogicEntry LogicEntry1 = new LogicObjects.LogicEntry();
            foreach (var i in NewformatLogicFile.Logic)
            {
                LogicEntry1.ID             = NewformatLogicFile.Logic.IndexOf(i);
                LogicEntry1.DictionaryName = i.Id;
                LogicEntry1.Checked        = false;
                LogicEntry1.RandomizedItem = -2;
                LogicEntry1.IsFake         = true;
                LogicEntry1.SpoilerRandom  = -2;
                LogicEntry1.Required       = i.RequiredItems.Select(x => LogicNametoId[x]).ToArray();
                LogicEntry1.Conditionals   = i.ConditionalItems.Select(x => x.Select(y => LogicNametoId[y]).ToArray()).ToArray();
                LogicEntry1.NeededBy       = (int)i.TimeNeeded;
                LogicEntry1.AvailableOn    = (int)i.TimeAvailable;
                LogicEntry1.IsTrick        = i.IsTrick;
                LogicEntry1.TrickEnabled   = i.IsTrick;
                LogicEntry1.TrickToolTip   = i.TrickTooltip;

                var DicEntry = instance.LogicDictionary.Find(x => x.DictionaryName == LogicEntry1.DictionaryName);
                if (DicEntry != null)
                {
                    LogicEntry1.IsFake          = false;
                    LogicEntry1.ItemName        = (string.IsNullOrWhiteSpace(DicEntry.ItemName)) ? null : DicEntry.ItemName;
                    LogicEntry1.LocationName    = (string.IsNullOrWhiteSpace(DicEntry.LocationName)) ? null : DicEntry.LocationName;
                    LogicEntry1.LocationArea    = (string.IsNullOrWhiteSpace(DicEntry.LocationArea)) ? "Misc" : DicEntry.LocationArea;
                    LogicEntry1.ItemSubType     = (string.IsNullOrWhiteSpace(DicEntry.ItemSubType)) ? "Item" : DicEntry.ItemSubType;
                    LogicEntry1.SpoilerLocation = (string.IsNullOrWhiteSpace(DicEntry.SpoilerLocation))
                        ? new List <string> {
                        LogicEntry1.LocationName
                    } : DicEntry.SpoilerLocation.Split('|').ToList();
                    LogicEntry1.SpoilerItem = (string.IsNullOrWhiteSpace(DicEntry.SpoilerItem))
                        ? new List <string> {
                        LogicEntry1.ItemName
                    } : DicEntry.SpoilerItem.Split('|').ToList();
                }

                //Push Data to the instance
                instance.Logic.Add(LogicEntry1);
                LogicEntry1 = new LogicObjects.LogicEntry();
            }

            instance.EntranceRando   = instance.IsEntranceRando();
            instance.EntranceAreaDic = CreateAreaClearDictionary(instance);
            CreateDicNameToID(instance);
            if (instance.EntranceRando)
            {
                CreatedEntrancepairDcitionary(instance);
            }
            MarkUniqeItemsUnrandomizedManual(instance);

            return(true);
        }