Skip to content

Commit 7bda997

Browse files
authored
Random Names from Team (#257)
* Random Names from Team [EDITED] - Added a function to read from Credits.txt and add a random name for the "Empty" Player Name - Change the "BOT" text to blue color [CHANGED] - Changed Location of Credits.txt from '/Assets' to '/Assets/Resources' * Update PlayerManager.cs
1 parent 8b8231d commit 7bda997

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

Assets/Script/PlayerManager.cs

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,72 @@
44
using YARG.Input;
55
using YARG.PlayMode;
66
using YARG.Settings;
7+
using UnityEngine;
8+
using UnityEngine.AddressableAssets;
79

810
namespace YARG {
911
public static class PlayerManager {
12+
1013
public struct LastScore {
1114
public DiffPercent percentage;
1215
public DiffScore score;
1316
public int notesHit;
1417
public int notesMissed;
18+
19+
}
20+
21+
public struct RandomName {
22+
public string name;
23+
public int size;
24+
}
25+
26+
private static RandomName RandomNameFromFile() {
27+
// load credits.txt
28+
// read each line
29+
// ignore lines starting with << or <u> or empty lines
30+
// return random line
31+
32+
// load Assets/Credits.txt
33+
var creditsPath = Addressables.LoadAssetAsync<TextAsset>("Credits");
34+
creditsPath.WaitForCompletion();
35+
// split credits into lines
36+
var lines = creditsPath.Result.text.Split(new[] { "\r\n", "\r", "\n" }, System.StringSplitOptions.RemoveEmptyEntries);
37+
38+
39+
//var lines = System.IO.File.ReadAllLines(creditsPath);
40+
var names = new List<string>();
41+
foreach (var line in lines) {
42+
if (line.StartsWith("<<") || line.StartsWith("<u>") || line.Length == 0) {
43+
continue;
44+
}
45+
46+
// special conditions
47+
if (line.Contains("EliteAsian (barely)")) {
48+
continue;
49+
}
50+
if (line.Contains("EliteAsian")) {
51+
names.Add("<b>E</b>lite<b>A</b>sian");
52+
continue;
53+
}
54+
if (line.Contains("NevesPT")) {
55+
names.Add("<b>N</b>eves<b>PT</b>");
56+
continue;
57+
}
58+
59+
names.Add(line);
60+
}
61+
62+
return new RandomName() {
63+
name = names[Random.Range(0, names.Count)],
64+
size = names.Count
65+
};
1566
}
1667

1768
public class Player {
1869
private static int nextPlayerName = 1;
1970

2071
public string name;
21-
public string DisplayName => name + (inputStrategy.botMode ? " (BOT)" : "");
72+
public string DisplayName => name + (inputStrategy.botMode ? " <color=#00DBFD>BOT</color>" : "");
2273

2374
public InputStrategy inputStrategy;
2475

@@ -34,7 +85,16 @@ public class Player {
3485
public AbstractTrack track = null;
3586

3687
public Player() {
37-
name = $"New Player {nextPlayerName++}";
88+
int counter = 0;
89+
// do not use the same name twice, if no available names, use "New Player"
90+
do {
91+
RandomName randomName = RandomNameFromFile();
92+
name = randomName.name;
93+
if (counter++ > randomName.size || name == null) {
94+
name = $"New Player {nextPlayerName++}";
95+
break;
96+
}
97+
} while (players.Any(i => i.name == name));
3898
}
3999
}
40100

0 commit comments

Comments
 (0)