Client LuaCsForBarotrauma
CompositeFriendProvider.cs
1 using System.Collections.Immutable;
2 using System.Linq;
3 using System.Threading.Tasks;
6 
7 namespace Barotrauma;
8 
9 sealed class CompositeFriendProvider : FriendProvider
10 {
11  private readonly ImmutableArray<FriendProvider> providers;
12 
13  public CompositeFriendProvider(params FriendProvider[] providers)
14  {
15  this.providers = providers.ToImmutableArray();
16  }
17 
18  public override async Task<Option<FriendInfo>> RetrieveFriend(AccountId id)
19  {
20  return (await Task.WhenAll(providers
21  .Select(p => p.RetrieveFriend(id))))
22  .NotNone().FirstOrNone();
23  }
24 
25  public override async Task<ImmutableArray<FriendInfo>> RetrieveFriends()
26  {
27  var friends = await Task.WhenAll(providers.Select(p => p.RetrieveFriends()));
28  return friends.SelectMany(a => a).ToImmutableArray();
29  }
30 
31  public override async Task<Option<Sprite>> RetrieveAvatar(FriendInfo friend, int avatarSize)
32  {
33  var subTasks = await Task.WhenAll(providers.Select(p => p.RetrieveAvatar(friend, avatarSize)));
34  return subTasks.FirstOrDefault(t => t.IsSome());
35  }
36 
37  public override async Task<string> GetSelfUserName()
38  {
39  foreach (var provider in providers)
40  {
41  string userName = await provider.GetSelfUserName();
42  if (userName is { Length: > 0 }) { return userName; }
43  }
44  return "";
45  }
46 }
override async Task< ImmutableArray< FriendInfo > > RetrieveFriends()
override async Task< Option< Sprite > > RetrieveAvatar(FriendInfo friend, int avatarSize)
CompositeFriendProvider(params FriendProvider[] providers)
override async Task< Option< FriendInfo > > RetrieveFriend(AccountId id)
override async Task< string > GetSelfUserName()