/*TODO Maybe use later, for now will not take a file name * //On submit of rando file name * bool OnEnterRandoFileName(string fileName) * { * Console.WriteLine($"File name received: {fileName}"); * randoFileName = fileName; * * //Pop up next input for which file slot to create this file in * TextEntryPopup fileSlotPopup = InitTextEntryPopup(generateSeedButton.addedTo, "Which save slot would you like to start a rando seed?", (entry) => OnEnterRandoFileSlot(entry), 1, null, CharsetFlags.Number); * fileSlotPopup.onBack += () => * { * fileSlotPopup.gameObject.SetActive(false); * generateSeedButton.textEntryPopup.gameObject.SetActive(true); * generateSeedButton.textEntryPopup.StartCoroutine(generateSeedButton.textEntryPopup.BackWhenBackButtonReleased()); * }; * generateSeedButton.textEntryPopup.gameObject.SetActive(false); * * //Initialize the file slot popup * fileSlotPopup.Init(string.Empty); * fileSlotPopup.gameObject.SetActive(true); * fileSlotPopup.transform.SetParent(generateSeedButton.addedTo.transform.parent); * generateSeedButton.addedTo.gameObject.SetActive(false); * Canvas.ForceUpdateCanvases(); * fileSlotPopup.initialSelection.GetComponent<UIObjectAudioHandler>().playAudio = false; * EventSystem.current.SetSelectedGameObject(fileSlotPopup.initialSelection); * fileSlotPopup.initialSelection.GetComponent<UIObjectAudioHandler>().playAudio = true; * return false; * } */ ///On submit of rando file location bool OnEnterFileSlot(string fileSlot) { Console.WriteLine($"In Method: OnEnterFileSlot. Provided value: '{fileSlot}'"); Console.WriteLine($"Received file slot number: {fileSlot}"); int slot = Convert.ToInt32(fileSlot); if (slot < 1 || slot > 3) { Console.WriteLine($"Invalid slot number provided: {slot}"); return(false); } //Load in mappings and save them to the state //Load encoded seed information string encodedSeedInfo = ItemRandomizerUtil.LoadMappingsFromFile(slot); Console.WriteLine($"File reading complete. Received the following encoded seed info: '{encodedSeedInfo}'"); string decodedSeedInfo = ItemRandomizerUtil.DecryptSeedInfo(encodedSeedInfo); Console.WriteLine($"Decryption complete. Received the following seed info: '{decodedSeedInfo}'"); SeedRO seedRO = ItemRandomizerUtil.ParseSeed(slot, decodedSeedInfo); randoStateManager.AddSeed(seedRO); //Save Save.seedData = randomizerSaveMethod.GenerateSaveData(); return(true); }
public void Load(string load) { Console.WriteLine($"Received value during mod option load: '{load}'"); //Split on delimeter to get all seeds string[] seeds = load.Split(RANDO_OPTION_VALUE_DELIM); Console.WriteLine("load data split into seeds"); for (int i = 1; i < seeds.Length; i++) { string seedDetails = seeds[i]; Console.WriteLine($"Adding '{seedDetails}' to state manager."); //find necessary indicies in the string int randoTypeIndex = seedDetails.IndexOf(RANDO_OPTION_TYPE_DELIM); int randoSettingIndex = seedDetails.IndexOf(RANDO_OPTION_SETTING_DELIM); string seedSub = seedDetails.Substring(0, randoTypeIndex); Console.WriteLine($"Extracted seed '{seedSub}' from seed split {i}"); //This will parse the seed into an int. If the value cannot be parsed for some reason, seed will be 0 Int32.TryParse(seedSub, out int seed); //Need to check if there are settings for this seed. If so, consider them when getting the seedtype. If not, the rest of the string is the seedtype. string seedTypeSub = randoSettingIndex != -1 ? seedDetails.Substring(randoTypeIndex + 1, randoSettingIndex - (randoTypeIndex + 1)) : seedDetails.Substring(randoTypeIndex + 1); Console.WriteLine($"Extracted seedtype '{seedTypeSub}' from seed split {i}"); //This will pull out the seed type. If there is none, default it. SeedType seedType = SeedType.None; if (seedTypeSub != null && Enum.IsDefined(typeof(SeedType), seedTypeSub)) //using IsDefined because I dont have TryParse in this .NET version T_T { seedType = (SeedType)Enum.Parse(typeof(SeedType), seedTypeSub); } //If there are settings, I need to pull them out as well Dictionary <SettingType, SettingValue> seedSettings = new Dictionary <SettingType, SettingValue>(); List <RandoItemRO> collectedRandoItemList = new List <RandoItemRO>(); string mappingString = ""; if (randoSettingIndex != -1) { string seedSettingSub = seedDetails.Substring(seedDetails.IndexOf(RANDO_OPTION_SETTING_DELIM) + 1); Console.WriteLine($"Extracted seed settings '{seedSettingSub}' from seed split {i}"); string[] splitSeedSettings = seedSettingSub.Split(RANDO_OPTION_SETTING_DELIM); foreach (string setting in splitSeedSettings) { //handle collected item loading if (setting.StartsWith("CollectedItems=")) { string collectedItemsRaw = setting.Substring(setting.IndexOf(RANDO_OPTION_SETTING_VALUE_DELIM) + 1); //split further to get each rando item string[] collectedItems = collectedItemsRaw.Split(RANDO_OPTION_ITEM_DELIM); SaveGameSlot save = Manager <SaveManager> .Instance.GetSaveSlot(i - 1); foreach (string collectedItem in collectedItems) { try { RandoItemRO randoItemFromModSave = RandoItemRO.ParseString(collectedItem); if (save.Items.ContainsKey(randoItemFromModSave.Item)) { collectedRandoItemList.Add(randoItemFromModSave); Console.WriteLine($"Added item '{collectedItem}' to Collected Item pool for file slot '{i}'."); } else { Console.WriteLine($"Item '{randoItemFromModSave.Item}' was not in the game save so we are ignoring it."); } } catch (Exception) { Console.WriteLine($"ERROR WHILE LOADING FROM MOD SAVE FILE: Found an item that could not be processed. Item in question '{collectedItem}'. Skipping item."); continue; } } } else if (setting.StartsWith("Mappings=")) { //Load mappings string mappingString = setting.Substring(setting.IndexOf(RANDO_OPTION_SETTING_VALUE_DELIM) + 1); } else //Other settings { string[] splitSeedSetting = setting.Split(RANDO_OPTION_SETTING_VALUE_DELIM); if (splitSeedSetting.Length == 2) { string splitSeedSettingType = splitSeedSetting[0]; string splitSeedSettingValue = splitSeedSetting[1]; Console.WriteLine($"Split setting '{splitSeedSettingType}' with value '{splitSeedSettingValue}' added to seed split {i}"); if ((splitSeedSettingType != null && Enum.IsDefined(typeof(SettingType), splitSeedSettingType)) && (splitSeedSettingValue != null && Enum.IsDefined(typeof(SettingValue), splitSeedSettingValue))) { seedSettings.Add((SettingType)Enum.Parse(typeof(SettingType), splitSeedSettingType), (SettingValue)Enum.Parse(typeof(SettingValue), splitSeedSettingValue)); } } else { Console.WriteLine($"ERROR WHILE LOADING FROM MOD SAVE FILE: Setting not properly formatted in file. Setting in question '{setting}'. Throwing it away and moving on."); } } } } stateManager.AddSeed(i, seedType, seed, seedSettings, collectedRandoItemList, mappingString); Console.WriteLine($"'{seeds[i]}' added to state manager successfully."); } Console.WriteLine("Loading into state manager complete."); }