public void LateUpdate() { if (uiFont is null && SceneManager.GetActiveScene().name.Equals("Main Menu")) { uiFont = GameObject.Find("Profile Title").GetComponent <Text>().font; } if (sceneChanged) { sceneChanged = false; if (SceneManager.GetActiveScene().name.Equals("Gameplay")) { var gameManagerObject = GameObject.Find("Game Manager"); gameManager = GameManagerWrapper.Wrap(GameObject.Find("Game Manager")?.GetComponent <GameManager>()); if (gameManager.GlobalVariables.SongEntry.SongEntry.lyrics && gameManager.GlobalVariables.SongEntry.SongEntry.chartPath.EndsWith("notes.mid")) { string file = gameManager.GlobalVariables.SongEntry.SongEntry.chartPath; MidiParser parser = new MidiParser(file); List <List <ChartCommand> > coms = parser.ParseMidi(); commands0 = coms[0]; commands1 = coms[1]; commands2 = coms[2]; Logger.LogDebug(commands2.Count); foreach (ChartCommand com in commands2) { Logger.LogDebug($"{com.TimeInMs} {com.Command} {com.Parameter}"); } index0 = 0; index1 = 0; index2 = 0; //Logger.LogDebug(gameManager.GlobalVariables.SongEntry.SongEntry.chartPath); lyricsTransform = GameObject.Find("Lyrics").transform; altLyrics0 = CreateTmpText(lyricsTransform, "AltLyrics1", 3); altLyrics1 = CreateTmpText(lyricsTransform, "AltLyrics2", 2); altLyrics2 = CreateTmpText(lyricsTransform, "AltLyrics3", 1); altLyrics0.fontSize = 44f; altLyrics1.fontSize = 44f; altLyrics2.fontSize = 44f; altLyrics0.transform.localPosition = new Vector2(0, 460); altLyrics1.transform.localPosition = new Vector2(0, 300); altLyrics2.transform.localPosition = new Vector2(0, 240); altLyrics0.horizontalAlignment = HorizontalAlignmentOptions.Center; altLyrics1.horizontalAlignment = HorizontalAlignmentOptions.Center; altLyrics2.horizontalAlignment = HorizontalAlignmentOptions.Center; altLyrics0.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width / 2, altLyrics0.preferredHeight); altLyrics1.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width / 2, altLyrics1.preferredHeight); altLyrics2.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width / 2, altLyrics2.preferredHeight); indexes0 = new List <int>(); indexes1 = new List <int>(); indexes2 = new List <int>(); ClearLyric0(); ClearLyric1(); ClearLyric2(); } else if (gameManager.GlobalVariables.SongEntry.SongEntry.lyrics && gameManager.GlobalVariables.SongEntry.SongEntry.chartPath.EndsWith("notes.chart")) { string file = gameManager.GlobalVariables.SongEntry.SongEntry.chartPath; LyricsParser parser = new LyricsParser(file); commands0 = parser.ParseLyrics()[0]; index0 = 0; Logger.LogDebug(gameManager.GlobalVariables.SongEntry.SongEntry.chartPath); lyricsTransform = GameObject.Find("Lyrics").transform; altLyrics0 = CreateTmpText(lyricsTransform, "AltLyrics1", 1); altLyrics0.fontSize = 44f; altLyrics0.transform.localPosition = new Vector2(0, 460); altLyrics0.horizontalAlignment = HorizontalAlignmentOptions.Center; altLyrics0.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width / 2, altLyrics0.preferredHeight); indexes0 = new List <int>(); ClearLyric0(); ClearLyric1(); ClearLyric2(); } else { commands0 = new List <ChartCommand>(); } //UpdateTextButton(altLyrics, "TEST", 40, Color.white); } } if (SceneManager.GetActiveScene().name.Equals("Gameplay")) { if (index0 < commands0.Count) { if (TimeSpan.FromSeconds(gameManager.SongTime).TotalMilliseconds >= commands0[index0].TimeInMs) { ChartCommand curCommand = commands0[index0++]; if (curCommand.Command == "phrase_start") { ClearLyric0(); int i = 0; ChartCommand x; while ((index0 + i) < commands0.Count && (x = commands0[index0 + i++]).Command == "lyric") { altLyricText0 += x.Parameter; if (altLyricText0.EndsWith("=")) { altLyricText0 = altLyricText0.TrimEnd('=') + "-"; } else if (altLyricText0.EndsWith("$") || altLyricText0.EndsWith("#")) { altLyricText0 = altLyricText0.TrimEnd(new char[] { '$', '#' }); } else if (altLyricText0.EndsWith("-")) { altLyricText0 = altLyricText0.TrimEnd('-'); } else { altLyricText0 += " "; } indexes0.Add(altLyricText0.Length); } altLyrics0.text = altLyricText0; } else if (curCommand.Command == "phrase_end") { ClearLyric0(); } else { altLyrics0.text = "<color=#47a9ea>" + altLyricText0.Substring(0, indexes0[colorIndex0]) + "</color>" + altLyricText0.Substring(indexes0[colorIndex0++]); } //altLyrics.text = $"{curCommand.Command} {curCommand.Parameter}"; } } if (index1 < commands1.Count) { if (TimeSpan.FromSeconds(gameManager.SongTime).TotalMilliseconds >= commands1[index1].TimeInMs) { ChartCommand curCommand = commands1[index1++]; if (curCommand.Command == "phrase_start") { ClearLyric1(); int i = 0; ChartCommand x; while ((index1 + i) < commands1.Count && (x = commands1[index1 + i++]).Command == "lyric") { altLyricText1 += x.Parameter; if (altLyricText1.EndsWith("=")) { altLyricText1 = altLyricText1.TrimEnd('=') + "-"; } else if (altLyricText1.EndsWith("$") || altLyricText1.EndsWith("#")) { altLyricText1 = altLyricText1.TrimEnd(new char[] { '$', '#' }); } else if (altLyricText1.EndsWith("-")) { altLyricText1 = altLyricText1.TrimEnd('-'); } else { altLyricText1 += " "; } indexes1.Add(altLyricText1.Length); } altLyrics1.text = altLyricText1; } else if (curCommand.Command == "phrase_end") { ClearLyric1(); } else { altLyrics1.text = "<color=#e59b2b>" + altLyricText1.Substring(0, indexes1[colorIndex1]) + "</color>" + altLyricText1.Substring(indexes1[colorIndex1++]); } //altLyrics.text = $"{curCommand.Command} {curCommand.Parameter}"; } } if (index2 < commands2.Count) { if (TimeSpan.FromSeconds(gameManager.SongTime).TotalMilliseconds >= commands2[index2].TimeInMs) { Logger.LogDebug("TEST0"); ChartCommand curCommand = commands2[index2++]; Logger.LogDebug("TEST1"); if (curCommand.Command == "phrase_start") { ClearLyric2(); int i = 0; ChartCommand x; while ((index2 + i) < commands2.Count && (x = commands2[index2 + i++]).Command == "lyric") { Logger.LogDebug("TEST2"); altLyricText2 += x.Parameter; if (altLyricText2.EndsWith("=")) { altLyricText2 = altLyricText2.TrimEnd('=') + "-"; } else if (altLyricText2.EndsWith("$") || altLyricText2.EndsWith("#")) { altLyricText2 = altLyricText2.TrimEnd(new char[] { '$', '#' }); } else if (altLyricText2.EndsWith("-")) { altLyricText2 = altLyricText2.TrimEnd('-'); } else { altLyricText2 += " "; } indexes2.Add(altLyricText2.Length); } altLyrics2.text = altLyricText2; } else if (curCommand.Command == "phrase_end") { ClearLyric2(); } else { altLyrics2.text = "<color=#af3e1c>" + altLyricText2.Substring(0, indexes2[colorIndex2]) + "</color>" + altLyricText2.Substring(indexes2[colorIndex2++]); } //altLyrics.text = $"{curCommand.Command} {curCommand.Parameter}"; } } } }
public List <ChartCommand> ParseChart(string[] acceptedCommands) { string line; bool readingEvents = false; bool readingSong = false; bool readingSyncTrack = false; float resolution = 192f; float bpm = 120000f; List <ChartCommand> commands = new List <ChartCommand>(); StreamReader file = new StreamReader(this.fileName); while ((line = file.ReadLine()) != null) { if (readingEvents) { if (line != "{") { if (line == "}") { readingEvents = false; } else { string[] splitted = line.Trim(' ').Split('"'); string[] spaceSplitted = splitted[1].Split(' '); string commandString = spaceSplitted[0]; if (acceptedCommands.Contains(commandString)) { int tick = Int32.Parse(splitted[0].Split(' ')[0]); float timeInMs = tick / resolution * 60.0f / bpm; string parameter = String.Join(" ", spaceSplitted.Skip(1).ToArray()); ChartCommand command = new ChartCommand() { Tick = tick, TimeInMs = timeInMs, Command = commandString, Parameter = parameter, OriginalCommand = line }; commands.Add(command); } } } } if (readingSong && line != "{") { if (line == "}") { readingSong = false; } else { string[] splitted = line.Split('='); if (splitted[0].Trim(' ') == "Resolution") { resolution = float.Parse(splitted[1].Trim(' ')); } } } if (readingSyncTrack && line != "{") { if (line == "}") { readingSyncTrack = false; } else { string[] splitted = line.Split('=')[1].Trim(' ').Split(' '); if (splitted[0] == "B") { bpm = float.Parse(splitted[1]); } } } if (line == "[Events]") { readingEvents = true; } if (line == "[Song]") { readingSong = true; } if (line == "[SyncTrack]") { readingSyncTrack = true; } } file.Close(); return(commands); }