public void NegativeTestStripFCFromName3() { var(friendCode, stripped) = FriendCode.ParseAndStripFriendCode("Ludic--<"); Assert.AreEqual(FriendCode.NO_FRIEND_CODE, friendCode); Assert.IsNotNull(stripped); Assert.AreEqual("Ludic--<", stripped); }
public void NegativeTestStripFCFromName2() { var(friendCode, stripped) = FriendCode.ParseAndStripFriendCode("0123SomeSquid4567"); Assert.AreEqual(FriendCode.NO_FRIEND_CODE, friendCode); Assert.IsNotNull(stripped); Assert.AreEqual("0123SomeSquid4567", stripped); }
public void StripFCInsideName2() { var(friendCode, stripped) = FriendCode.ParseAndStripFriendCode("My name 1234 - 5678 - 9012"); Assert.AreNotEqual(FriendCode.NO_FRIEND_CODE, friendCode); Assert.IsNotNull(stripped); Assert.AreEqual("1234-5678-9012", friendCode.ToString()); Assert.AreEqual("My name", stripped); }
public void StripFCInsideName() { var(friendCode, stripped) = FriendCode.ParseAndStripFriendCode(":) Some pleb (SW: 0123-4567-8912)"); Assert.AreNotEqual(FriendCode.NO_FRIEND_CODE, friendCode); Assert.IsNotNull(stripped); Assert.AreEqual("0123 4567 8912", friendCode.ToString(" ")); Assert.AreEqual(":) Some pleb", stripped); }
public Source Load() { Debug.WriteLine("Loading " + jsonFile); string json = File.ReadAllText(jsonFile); BattlefyJsonTeam[] rows = JsonConvert.DeserializeObject <BattlefyJsonTeam[]>(json) ?? Array.Empty <BattlefyJsonTeam>(); List <Team> teams = new(); List <Player> players = new(); foreach (BattlefyJsonTeam row in rows) { if (row.TeamName == null || row.Players == null) { Console.Error.WriteLine("ERROR: JSON did not import a team correctly. Ignoring this team entry. File: " + jsonFile); continue; } if (row.Players.Length < 1) { // Report if the team name doesn't begin with "bye" if (!row.TeamName.StartsWith("bye", StringComparison.OrdinalIgnoreCase)) { Console.Error.WriteLine($"ERROR: JSON does not contain a player for team \"{row.TeamName}\". Ignoring this team entry. File: " + jsonFile); } continue; } // Set the source start time if not already if (source.Start == Builtins.UnknownDateTime && row.CheckInTime != null) { source.Start = new DateTime(row.CheckInTime.Value.Year, row.CheckInTime.Value.Month, row.CheckInTime.Value.DayOfYear); } if (row.Captain == null) { Console.WriteLine($"Warning: JSON does not contain a Team Captain for team \"{row.TeamName}\". Assuming player 1 is captain. File: " + jsonFile); row.Captain = row.Players[0]; } if (string.IsNullOrEmpty(row.Captain.Name)) { Console.Error.WriteLine($"ERROR: The captain for team \"{row.TeamName}\" does not have a name. Ignoring this team entry. File: " + jsonFile); continue; } // Attempt to resolve the team tags ClanTag?teamTag = ClanTag.CalculateTagFromNames(row.Players.Select(p => p.Name).Where(name => name != null && !string.IsNullOrWhiteSpace(name)).ToArray() !, source); Team newTeam = new(row.TeamName, source); if (teamTag != null) { newTeam.AddClanTag(teamTag); } if (row.BattlefyPersistentTeamId != null) { newTeam.AddBattlefyId(row.BattlefyPersistentTeamId, source); } // If we already have a team with this id then merge it. if (newTeam.BattlefyPersistentTeamId != null) { var knownTeam = teams.Find(t => newTeam.BattlefyPersistentTeamId.Equals(t.BattlefyPersistentTeamId)); if (knownTeam != null) { knownTeam.Merge(newTeam); } else { teams.Add(newTeam); } } else { teams.Add(newTeam); } foreach (BattlefyJsonPlayer p in row.Players) { if (p.Name == null) { Console.Error.WriteLine($"ERROR: Player's Name ({p.Name}) not populated. Ignoring this player entry. File: " + jsonFile); continue; } if (p.PersistentPlayerId == null) { Console.WriteLine($"Warning: Player ({p.Name}) does not have a PersistentPlayerId. Did they sub? Ignoring this player entry. File: " + jsonFile); continue; } // Filter the friend code from the name, if found var(parsedFriendCode, strippedName) = FriendCode.ParseAndStripFriendCode(p.Name); if (!parsedFriendCode.NoCode) { p.Name = strippedName; } // Remove tag from player if (teamTag != null) { p.Name = teamTag.StripFromPlayer(p.Name.Trim()); } // Add Discord information, if we have it var newPlayer = new Player(p.Name, new[] { newTeam.Id }, source); if (p.BattlefyName != null && p.BattlefyName == row.Captain.BattlefyName) { if (parsedFriendCode.NoCode && !row.CaptainFriendCode.NoCode) { parsedFriendCode = row.CaptainFriendCode; } if (row.CaptainDiscordName != null) { newPlayer.AddDiscordUsername(row.CaptainDiscordName, source); } } // Add Battlefy if (p.BattlefyName != null && p.BattlefyUserSlug != null && p.PersistentPlayerId != null) { newPlayer.AddBattlefyInformation(p.BattlefyUserSlug, p.BattlefyName, p.PersistentPlayerId, source); } newPlayer.AddFCs(parsedFriendCode, source); players.Add(newPlayer); } } source.Players = players.ToArray(); source.Teams = teams.ToArray(); return(source); }