private void B_Randomize_Click(object sender, EventArgs e) { // gametext can be horribly broken if randomized if (Mode == TextEditorMode.Common && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomizing Game Text is dangerous!", "Continue?")) { return; } // get if the user wants to randomize current text file or all files var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, $"Yes: Randomize ALL{Environment.NewLine}No: Randomize current Text File{Environment.NewLine}Cancel: Abort"); if (dr == DialogResult.Cancel) { return; } // get if pure shuffle or smart shuffle (no shuffle if variable present) var drs = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Smart shuffle:{Environment.NewLine}Yes: Shuffle if no Variable present{Environment.NewLine}No: Pure random!"); if (drs == DialogResult.Cancel) { return; } bool all = dr == DialogResult.Yes; bool smart = drs == DialogResult.Yes; // save current if (entry > -1) { TextData[entry] = GetCurrentDGLines(); } // single-entire looping int start = all ? 0 : entry; int end = all ? TextData.Length - 1 : entry; // Gather strings List <string> strings = new List <string>(); for (int i = start; i <= end; i++) { string[] data = TextData[i]; strings.AddRange(smart ? data.Where(line => !line.Contains("[")) : data); } // Shuffle up string[] pool = strings.ToArray(); Util.Shuffle(pool); // Apply Text int ctr = 0; for (int i = start; i <= end; i++) { string[] data = TextData[i]; for (int j = 0; j < data.Length; j++) // apply lines { if (!smart || !data[j].Contains("[")) { data[j] = pool[ctr++]; } } TextData[i] = data; } // Load current text file SetStringsDataGridView(TextData[entry]); WinFormsUtil.Alert("Strings randomized!"); }
private bool ImportTextFiles(string fileName) { string[] fileText = File.ReadAllLines(fileName, Encoding.Unicode); string[][] textLines = new string[TextData.Length][]; int ctr = 0; bool newlineFormatting = false; // Loop through all files for (int i = 0; i < fileText.Length; i++) { string line = fileText[i]; if (line != "~~~~~~~~~~~~~~~") { continue; } string[] brokenLine = fileText[i++ + 1].Split(new[] { " : " }, StringSplitOptions.None); if (brokenLine.Length != 2) { WinFormsUtil.Error($"Invalid Line @ {i}, expected Text File : {ctr}"); return(false); } var file = brokenLine[1]; if (int.TryParse(file, out var fnum)) { if (fnum != ctr) { WinFormsUtil.Error($"Invalid Line @ {i}, expected Text File : {ctr}"); return(false); } } // else pray that the filename index lines up i += 2; // Skip over the other header line List <string> Lines = new List <string>(); while (i < fileText.Length && fileText[i] != "~~~~~~~~~~~~~~~") { Lines.Add(fileText[i]); newlineFormatting |= fileText[i].Contains("\\n"); // Check if any line wasn't stripped of ingame formatting codes for human readability. i++; } i--; textLines[ctr++] = Lines.ToArray(); } // Error Check if (ctr != TextData.Length) { WinFormsUtil.Error("The amount of Text Files in the input file does not match the required for the text file.", $"Received: {ctr}, Expected: {TextData.Length}"); return(false); } if (!newlineFormatting) { WinFormsUtil.Error("The input Text Files do not have the in-game newline formatting codes (\\n,\\r,\\c).", "When exporting text, do not remove newline formatting."); return(false); } // All Text Lines received. Store all back. for (int i = 0; i < TextData.Length; i++) { try { TextData[i] = textLines[i]; } catch (Exception e) { WinFormsUtil.Error($"The input Text File (# {i}) failed to convert:", e.ToString()); return(false); } } return(true); }