3 using System.Collections.Immutable;
5 using System.Threading.Tasks;
8 using Microsoft.Xna.Framework.Graphics;
14 private FriendInfo FromSteamFriend(Steamworks.Friend steamFriend)
16 name: steamFriend.Name ??
"",
17 id:
new SteamId(steamFriend.Id),
18 status: steamFriend.State
switch
20 Steamworks.FriendState.Offline => FriendStatus.Offline,
21 Steamworks.FriendState.Invisible => FriendStatus.Offline,
22 _ when steamFriend.IsPlayingThisGame => FriendStatus.PlayingBarotrauma,
23 _ when steamFriend.GameInfo is { GameID: > 0 } => FriendStatus.PlayingAnotherGame,
24 _ => FriendStatus.NotPlaying
26 serverName: steamFriend.GetRichPresence(
"servername") ??
"",
27 connectCommand: steamFriend.GetRichPresence(
"connect") is { } connectCmd
28 ? ConnectCommand.Parse(ToolBox.SplitCommand(connectCmd))
33 => Task.FromResult(
id is SteamId steamId
34 ? Option.Some(FromSteamFriend(
new Steamworks.Friend(steamId.Value)))
38 => Task.FromResult(SteamManager.IsInitialized
39 ? Steamworks.SteamFriends.GetFriends().Select(FromSteamFriend).ToImmutableArray()
40 : ImmutableArray<FriendInfo>.Empty);
44 if (
friend.Id is not SteamId steamId) {
return Option.None; }
46 Func<Steamworks.SteamId, Task<Steamworks.Data.Image?>> avatarFunc = avatarSize
switch
48 <= 24 => Steamworks.SteamFriends.GetSmallAvatarAsync,
49 <= 48 => Steamworks.SteamFriends.GetMediumAvatarAsync,
50 _ => Steamworks.SteamFriends.GetLargeAvatarAsync
53 var img = await avatarFunc(steamId.Value).ToOptionTask();
54 if (!img.TryUnwrap(out var avatarImage)) {
return Option.None; }
56 if (
friend.Avatar.TryUnwrap(out var prevAvatar))
61 var avatarTexture =
new Texture2D(
GameMain.
Instance.GraphicsDevice, (
int)avatarImage.Width, (
int)avatarImage.Height);
62 avatarTexture.SetData(avatarImage.Data);
63 return Option.Some(
new Sprite(texture: avatarTexture, sourceRectangle:
null, newOffset:
null));
67 => Task.FromResult(SteamManager.GetUsername());
override Task< string > GetSelfUserName()
override Task< ImmutableArray< FriendInfo > > RetrieveFriends()
override async Task< Option< Sprite > > RetrieveAvatar(FriendInfo friend, int avatarSize)
override Task< Option< FriendInfo > > RetrieveFriend(AccountId id)