diff --git a/Assets/Credits.txt b/Assets/Resources/Credits.txt similarity index 100% rename from Assets/Credits.txt rename to Assets/Resources/Credits.txt diff --git a/Assets/Credits.txt.meta b/Assets/Resources/Credits.txt.meta similarity index 100% rename from Assets/Credits.txt.meta rename to Assets/Resources/Credits.txt.meta diff --git a/Assets/Script/PlayerManager.cs b/Assets/Script/PlayerManager.cs index 6c355f3e0..2ff933e2b 100644 --- a/Assets/Script/PlayerManager.cs +++ b/Assets/Script/PlayerManager.cs @@ -4,21 +4,72 @@ using YARG.Input; using YARG.PlayMode; using YARG.Settings; +using UnityEngine; +using UnityEngine.AddressableAssets; namespace YARG { public static class PlayerManager { + public struct LastScore { public DiffPercent percentage; public DiffScore score; public int notesHit; public int notesMissed; + + } + + public struct RandomName { + public string name; + public int size; + } + + private static RandomName RandomNameFromFile() { + // load credits.txt + // read each line + // ignore lines starting with << or or empty lines + // return random line + + // load Assets/Credits.txt + var creditsPath = Addressables.LoadAssetAsync("Credits"); + creditsPath.WaitForCompletion(); + // split credits into lines + var lines = creditsPath.Result.text.Split(new[] { "\r\n", "\r", "\n" }, System.StringSplitOptions.RemoveEmptyEntries); + + + //var lines = System.IO.File.ReadAllLines(creditsPath); + var names = new List(); + foreach (var line in lines) { + if (line.StartsWith("<<") || line.StartsWith("") || line.Length == 0) { + continue; + } + + // special conditions + if (line.Contains("EliteAsian (barely)")) { + continue; + } + if (line.Contains("EliteAsian")) { + names.Add("EliteAsian"); + continue; + } + if (line.Contains("NevesPT")) { + names.Add("NevesPT"); + continue; + } + + names.Add(line); + } + + return new RandomName() { + name = names[Random.Range(0, names.Count)], + size = names.Count + }; } public class Player { private static int nextPlayerName = 1; public string name; - public string DisplayName => name + (inputStrategy.botMode ? " (BOT)" : ""); + public string DisplayName => name + (inputStrategy.botMode ? " BOT" : ""); public InputStrategy inputStrategy; @@ -34,7 +85,16 @@ public class Player { public AbstractTrack track = null; public Player() { - name = $"New Player {nextPlayerName++}"; + int counter = 0; + // do not use the same name twice, if no available names, use "New Player" + do { + RandomName randomName = RandomNameFromFile(); + name = randomName.name; + if (counter++ > randomName.size || name == null) { + name = $"New Player {nextPlayerName++}"; + break; + } + } while (players.Any(i => i.name == name)); } }