From a169346f53fea6ffbb7c36beeae43d9220244547 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 17 Mar 2024 12:56:28 +0000 Subject: [PATCH] refactor!: extract interface for Avatar --- VpSharp.IntegrationTests/src/Program.cs | 2 +- VpSharp/src/Entities/Avatar.cs | 4 +- VpSharp/src/Entities/IAvatar.cs | 184 ++++++++++++++++++ VpSharp/src/Entities/Message.cs | 4 +- .../src/EventData/AvatarClickedEventArgs.cs | 6 +- VpSharp/src/EventData/AvatarMovedEventArgs.cs | 4 +- .../EventData/AvatarTypeChangedEventArgs.cs | 4 +- VpSharp/src/EventData/ObjectBumpEventArgs.cs | 4 +- .../src/EventData/ObjectChangedEventArgs.cs | 4 +- .../src/EventData/ObjectClickedEventArgs.cs | 4 +- .../src/EventData/ObjectCreatedEventArgs.cs | 4 +- .../src/EventData/ObjectDeletedEventArgs.cs | 4 +- VpSharp/src/EventData/TeleportedEventArgs.cs | 4 +- VpSharp/src/EventData/UriReceivedEventArgs.cs | 4 +- VpSharp/src/VirtualParadiseClient.Avatars.cs | 2 +- VpSharp/src/VirtualParadiseClient.Events.cs | 8 +- .../src/VirtualParadiseClient.NativeEvents.cs | 30 +-- VpSharp/src/VirtualParadiseClient.cs | 11 +- 18 files changed, 235 insertions(+), 52 deletions(-) create mode 100644 VpSharp/src/Entities/IAvatar.cs diff --git a/VpSharp.IntegrationTests/src/Program.cs b/VpSharp.IntegrationTests/src/Program.cs index bcf6289..8ebb547 100644 --- a/VpSharp.IntegrationTests/src/Program.cs +++ b/VpSharp.IntegrationTests/src/Program.cs @@ -45,7 +45,7 @@ Console.WriteLine(@"Entering world"); World world = await client.EnterAsync("Mutation"); Console.WriteLine(@"Entered world!"); -Avatar avatar = client.CurrentAvatar!; +IAvatar avatar = client.CurrentAvatar!; Console.WriteLine($@"My name is {avatar.Name} and I am at {avatar.Location}"); Console.WriteLine($@"Entered {world.Name} with size {world.Size}"); diff --git a/VpSharp/src/Entities/Avatar.cs b/VpSharp/src/Entities/Avatar.cs index 54a005c..8722bd7 100644 --- a/VpSharp/src/Entities/Avatar.cs +++ b/VpSharp/src/Entities/Avatar.cs @@ -10,7 +10,7 @@ namespace VpSharp.Entities; /// /// Represents an avatar within a world. /// -public sealed class Avatar : IEquatable +public sealed class Avatar : IEquatable, IAvatar { private readonly VirtualParadiseClient _client; private User? _user; @@ -233,7 +233,7 @@ public sealed class Avatar : IEquatable throw new ArgumentException(ExceptionMessages.ValueCannotBeEmpty, nameof(message)); } - Avatar avatar; + IAvatar avatar; lock (_client.Lock) { diff --git a/VpSharp/src/Entities/IAvatar.cs b/VpSharp/src/Entities/IAvatar.cs new file mode 100644 index 0000000..d97e7d6 --- /dev/null +++ b/VpSharp/src/Entities/IAvatar.cs @@ -0,0 +1,184 @@ +using System.Drawing; + +namespace VpSharp.Entities; + +public interface IAvatar +{ + /// + /// Gets the details of the application this avatar is using. + /// + /// The avatar's application details. + Application Application { get; } + + /// + /// Gets a value indicating whether this avatar is a bot. + /// + /// if this avatar is a bot; otherwise, . + bool IsBot { get; } + + /// + /// Gets the location of this avatar. + /// + /// The location of this avatar. + Location Location { get; } + + /// + /// Gets the name of this avatar. + /// + /// The name of this avatar. + string Name { get; } + + /// + /// Gets the session ID of this avatar. + /// + /// The session ID. + int Session { get; } + + /// + /// Gets the type of this avatar. + /// + /// The type of this avatar. + int Type { get; } + + /// + /// Gets the user ID associated with this avatar. + /// + /// The user ID. + int UserId { get; } + + /// + /// Clicks this avatar. + /// + /// The position at which the avatar should be clicked. + /// + /// The action cannot be performed on the client's current avatar. + /// -or- + /// An attempt was made to click an avatar outside of a world. + /// + Task ClickAsync(Vector3d? clickPoint = null); + + /// + /// Determines if two instances are equal. + /// + /// The other instance. + /// + /// if this instance is equal to ; otherwise, . + /// + bool Equals(Avatar? other); + + /// + /// Gets the user associated with this avatar. + /// + /// The user. + Task GetUserAsync(); + + /// + /// Sends a console message to the avatar with no name. + /// + /// The message to send. + /// The font style of the message. + /// The text color of the message. + /// The message which was sent. + /// is . + /// + /// An attempt was made to send a message while not connected to a world. + /// -or- + /// An attempt was made to send a message to an avatar that is not in the world. + /// + /// + /// is empty, or consists of only whitespace. + /// -or- + /// is too long to send. + /// + Task SendMessageAsync(string message, FontStyle fontStyle, Color color); + + /// + /// Sends a console message to the avatar. + /// + /// The apparent author of the message. + /// The message to send. + /// The font style of the message. + /// The text color of the message. + /// The message which was sent. + /// is . + /// + /// An attempt was made to send a message while not connected to a world. + /// -or- + /// An attempt was made to send a message to an avatar that is not in the world. + /// + /// + /// is empty, or consists of only whitespace. + /// -or- + /// is too long to send. + /// + /// Passing to will hide the name from the recipient. + Task SendMessageAsync(string? name, string message, FontStyle fontStyle, Color color); + + /// + /// Sends a URI to this avatar. + /// + /// The URI to send. + /// The URL target. See for more information. + /// The action cannot be performed on the client's current avatar. + /// is . + Task SendUriAsync(Uri uri, UriTarget target = UriTarget.Browser); + + /// + /// Modifies the world settings for this avatar. + /// + /// The builder which defines parameters to change. + /// is . + /// The client does not have permission to modify world settings. + Task SendWorldSettings(Action action); + + /// + /// Teleports the avatar to another world. + /// + /// The name of the world to which this avatar should be teleported. + /// The position to which this avatar should be teleported. + /// is . + Task TeleportAsync(World world, Vector3d position); + + /// + /// Teleports the avatar to another world. + /// + /// The name of the world to which this avatar should be teleported. + /// The position to which this avatar should be teleported. + /// The rotation to which this avatar should be teleported. + /// is . + Task TeleportAsync(World world, Vector3d position, Rotation rotation); + + /// + /// Teleports the avatar to another world. + /// + /// The name of the world to which this avatar should be teleported. + /// The position to which this avatar should be teleported. + Task TeleportAsync(string world, Vector3d position); + + /// + /// Teleports the avatar to another world. + /// + /// The name of the world to which this avatar should be teleported. + /// The position to which this avatar should be teleported. + /// The rotation to which this avatar should be teleported. + Task TeleportAsync(string world, Vector3d position, Rotation rotation); + + /// + /// Teleports the avatar to a new position within the current world. + /// + /// The position to which this avatar should be teleported. + Task TeleportAsync(Vector3d position); + + /// + /// Teleports the avatar to a new position and rotation within the current world. + /// + /// The position to which this avatar should be teleported. + /// The rotation to which this avatar should be teleported + Task TeleportAsync(Vector3d position, Rotation rotation); + + /// + /// Teleports this avatar to a new location, which may or may not be a new world. + /// + /// The location to which this avatar should be teleported. + Task TeleportAsync(Location location); +} diff --git a/VpSharp/src/Entities/Message.cs b/VpSharp/src/Entities/Message.cs index cb77df8..49024e6 100644 --- a/VpSharp/src/Entities/Message.cs +++ b/VpSharp/src/Entities/Message.cs @@ -11,7 +11,7 @@ public sealed class Message MessageType type, string? name, string content, - Avatar author, + IAvatar author, FontStyle style, Color color) { @@ -27,7 +27,7 @@ public sealed class Message /// Gets the message author. /// /// The message author. - public Avatar Author { get; } + public IAvatar Author { get; } /// /// Gets the message content. diff --git a/VpSharp/src/EventData/AvatarClickedEventArgs.cs b/VpSharp/src/EventData/AvatarClickedEventArgs.cs index d3dea44..85836ce 100644 --- a/VpSharp/src/EventData/AvatarClickedEventArgs.cs +++ b/VpSharp/src/EventData/AvatarClickedEventArgs.cs @@ -13,7 +13,7 @@ public sealed class AvatarClickedEventArgs : EventArgs /// The avatar responsible for the click. /// The clicked avatar. /// The click point. - public AvatarClickedEventArgs(Avatar avatar, Avatar clickedAvatar, Vector3d clickPoint) + public AvatarClickedEventArgs(IAvatar avatar, IAvatar clickedAvatar, Vector3d clickPoint) { Avatar = avatar; ClickedAvatar = clickedAvatar; @@ -24,13 +24,13 @@ public sealed class AvatarClickedEventArgs : EventArgs /// Gets the avatar responsible for the click. /// /// The avatar responsible for the click. - public Avatar Avatar { get; } + public IAvatar Avatar { get; } /// /// Gets the clicked avatar. /// /// The clicked avatar. - public Avatar ClickedAvatar { get; } + public IAvatar ClickedAvatar { get; } /// /// Gets the point at which the avatar clicked the object. diff --git a/VpSharp/src/EventData/AvatarMovedEventArgs.cs b/VpSharp/src/EventData/AvatarMovedEventArgs.cs index 4a35e8b..6f2b6e7 100644 --- a/VpSharp/src/EventData/AvatarMovedEventArgs.cs +++ b/VpSharp/src/EventData/AvatarMovedEventArgs.cs @@ -13,7 +13,7 @@ public sealed class AvatarMovedEventArgs : EventArgs /// The avatar whose type was changed. /// The avatar's new location. /// The avatar's old location. - public AvatarMovedEventArgs(Avatar avatar, Location locationAfter, Location? locationBefore) + public AvatarMovedEventArgs(IAvatar avatar, Location locationAfter, Location? locationBefore) { Avatar = avatar; LocationAfter = locationAfter; @@ -24,7 +24,7 @@ public sealed class AvatarMovedEventArgs : EventArgs /// Gets the avatar whose location was changed. /// /// The avatar whose location was changed. - public Avatar Avatar { get; } + public IAvatar Avatar { get; } /// /// Gets the avatar's location after the change. diff --git a/VpSharp/src/EventData/AvatarTypeChangedEventArgs.cs b/VpSharp/src/EventData/AvatarTypeChangedEventArgs.cs index e669c70..0a2d0c9 100644 --- a/VpSharp/src/EventData/AvatarTypeChangedEventArgs.cs +++ b/VpSharp/src/EventData/AvatarTypeChangedEventArgs.cs @@ -13,7 +13,7 @@ public sealed class AvatarTypeChangedEventArgs : EventArgs /// The avatar whose type was changed. /// The avatar's new type. /// The avatar's old type. - public AvatarTypeChangedEventArgs(Avatar avatar, int typeAfter, int? typeBefore) + public AvatarTypeChangedEventArgs(IAvatar avatar, int typeAfter, int? typeBefore) { Avatar = avatar; TypeAfter = typeAfter; @@ -24,7 +24,7 @@ public sealed class AvatarTypeChangedEventArgs : EventArgs /// Gets the avatar whose type was changed. /// /// The avatar whose type was changed. - public Avatar Avatar { get; } + public IAvatar Avatar { get; } /// /// Gets the avatar's type after the change. diff --git a/VpSharp/src/EventData/ObjectBumpEventArgs.cs b/VpSharp/src/EventData/ObjectBumpEventArgs.cs index 463d6cb..ca0d5df 100644 --- a/VpSharp/src/EventData/ObjectBumpEventArgs.cs +++ b/VpSharp/src/EventData/ObjectBumpEventArgs.cs @@ -13,7 +13,7 @@ public sealed class ObjectBumpEventArgs : EventArgs /// The avatar. /// The bumped object. /// The bump phase. - public ObjectBumpEventArgs(Avatar avatar, VirtualParadiseObject bumpedObject, BumpPhase phase) + public ObjectBumpEventArgs(IAvatar avatar, VirtualParadiseObject bumpedObject, BumpPhase phase) { Avatar = avatar; BumpedObject = bumpedObject; @@ -24,7 +24,7 @@ public sealed class ObjectBumpEventArgs : EventArgs /// Gets the avatar responsible for the bump. /// /// The avatar responsible for the bump. - public Avatar Avatar { get; } + public IAvatar Avatar { get; } /// /// Gets the object to which this event pertains. diff --git a/VpSharp/src/EventData/ObjectChangedEventArgs.cs b/VpSharp/src/EventData/ObjectChangedEventArgs.cs index 913d16a..e1db7a1 100644 --- a/VpSharp/src/EventData/ObjectChangedEventArgs.cs +++ b/VpSharp/src/EventData/ObjectChangedEventArgs.cs @@ -14,7 +14,7 @@ public sealed class ObjectChangedEventArgs : EventArgs /// The state of the object prior to the change. /// The object which was changed, containing updated values. public ObjectChangedEventArgs( - Avatar avatar, + IAvatar avatar, VirtualParadiseObject? objectBefore, VirtualParadiseObject objectAfter) { @@ -27,7 +27,7 @@ public sealed class ObjectChangedEventArgs : EventArgs /// Gets the avatar which changed the object. /// /// The avatar which changed the object. - public Avatar Avatar { get; } + public IAvatar Avatar { get; } /// /// Gets the object which was changed. diff --git a/VpSharp/src/EventData/ObjectClickedEventArgs.cs b/VpSharp/src/EventData/ObjectClickedEventArgs.cs index e8c9387..f402d03 100644 --- a/VpSharp/src/EventData/ObjectClickedEventArgs.cs +++ b/VpSharp/src/EventData/ObjectClickedEventArgs.cs @@ -14,7 +14,7 @@ public sealed class ObjectClickedEventArgs : EventArgs /// The clicked object. /// The click point. public ObjectClickedEventArgs( - Avatar avatar, + IAvatar avatar, VirtualParadiseObject clickedObject, Vector3d clickPoint) { @@ -27,7 +27,7 @@ public sealed class ObjectClickedEventArgs : EventArgs /// Gets the avatar responsible for the click. /// /// The avatar responsible for the click. - public Avatar Avatar { get; } + public IAvatar Avatar { get; } /// /// Gets the clicked object. diff --git a/VpSharp/src/EventData/ObjectCreatedEventArgs.cs b/VpSharp/src/EventData/ObjectCreatedEventArgs.cs index 609bbac..dad9592 100644 --- a/VpSharp/src/EventData/ObjectCreatedEventArgs.cs +++ b/VpSharp/src/EventData/ObjectCreatedEventArgs.cs @@ -12,7 +12,7 @@ public sealed class ObjectCreatedEventArgs : EventArgs /// /// The avatar responsible for the object being created. /// The created object. - public ObjectCreatedEventArgs(Avatar avatar, VirtualParadiseObject createdObject) + public ObjectCreatedEventArgs(IAvatar avatar, VirtualParadiseObject createdObject) { Avatar = avatar; CreatedObject = createdObject; @@ -22,7 +22,7 @@ public sealed class ObjectCreatedEventArgs : EventArgs /// Gets the avatar responsible for the object being created. /// /// The avatar responsible for the object being created. - public Avatar Avatar { get; } + public IAvatar Avatar { get; } /// /// Gets the object which was created. diff --git a/VpSharp/src/EventData/ObjectDeletedEventArgs.cs b/VpSharp/src/EventData/ObjectDeletedEventArgs.cs index e6ca861..eeddc8b 100644 --- a/VpSharp/src/EventData/ObjectDeletedEventArgs.cs +++ b/VpSharp/src/EventData/ObjectDeletedEventArgs.cs @@ -13,7 +13,7 @@ public sealed class ObjectDeletedEventArgs : EventArgs /// The avatar responsible for the object being deleted. /// The ID of the deleted object. /// The deleted object. - public ObjectDeletedEventArgs(Avatar avatar, int objectId, VirtualParadiseObject deletedObject) + public ObjectDeletedEventArgs(IAvatar avatar, int objectId, VirtualParadiseObject deletedObject) { Avatar = avatar; ObjectId = objectId; @@ -24,7 +24,7 @@ public sealed class ObjectDeletedEventArgs : EventArgs /// Gets the avatar responsible for the object being deleted. /// /// The avatar responsible for the object being deleted. - public Avatar Avatar { get; } + public IAvatar Avatar { get; } /// /// Gets the object which was deleted. diff --git a/VpSharp/src/EventData/TeleportedEventArgs.cs b/VpSharp/src/EventData/TeleportedEventArgs.cs index e054763..2400378 100644 --- a/VpSharp/src/EventData/TeleportedEventArgs.cs +++ b/VpSharp/src/EventData/TeleportedEventArgs.cs @@ -12,7 +12,7 @@ public sealed class TeleportedEventArgs : EventArgs /// /// The avatar which initiated the teleport. /// The target location of the teleport. - public TeleportedEventArgs(Avatar avatar, Location location) + public TeleportedEventArgs(IAvatar avatar, Location location) { Avatar = avatar; Location = location; @@ -22,7 +22,7 @@ public sealed class TeleportedEventArgs : EventArgs /// Gets the avatar which initiated the teleport. /// /// The avatar which initiated the teleport. - public Avatar Avatar { get; } + public IAvatar Avatar { get; } /// /// Gets the target location of the teleport. diff --git a/VpSharp/src/EventData/UriReceivedEventArgs.cs b/VpSharp/src/EventData/UriReceivedEventArgs.cs index 11cab0c..d5bf0c4 100644 --- a/VpSharp/src/EventData/UriReceivedEventArgs.cs +++ b/VpSharp/src/EventData/UriReceivedEventArgs.cs @@ -13,7 +13,7 @@ public sealed class UriReceivedEventArgs : EventArgs /// The received URI. /// The URI target. /// The avatar who sent the URI. - public UriReceivedEventArgs(Uri uri, UriTarget target, Avatar avatar) + public UriReceivedEventArgs(Uri uri, UriTarget target, IAvatar avatar) { Uri = uri; Target = target; @@ -24,7 +24,7 @@ public sealed class UriReceivedEventArgs : EventArgs /// Gets the avatar who sent the URI. /// /// The avatar who sent the URI. - public Avatar Avatar { get; } + public IAvatar Avatar { get; } /// /// Gets the URI target. diff --git a/VpSharp/src/VirtualParadiseClient.Avatars.cs b/VpSharp/src/VirtualParadiseClient.Avatars.cs index a018ca5..8bdeeaa 100644 --- a/VpSharp/src/VirtualParadiseClient.Avatars.cs +++ b/VpSharp/src/VirtualParadiseClient.Avatars.cs @@ -20,7 +20,7 @@ public sealed partial class VirtualParadiseClient /// The avatar whose session is equal to , or if no match was /// found. /// - public Avatar? GetAvatar(int session) + public IAvatar? GetAvatar(int session) { _avatars.TryGetValue(session, out Avatar? avatar); return avatar; diff --git a/VpSharp/src/VirtualParadiseClient.Events.cs b/VpSharp/src/VirtualParadiseClient.Events.cs index d380d6d..0ce4eac 100644 --- a/VpSharp/src/VirtualParadiseClient.Events.cs +++ b/VpSharp/src/VirtualParadiseClient.Events.cs @@ -7,8 +7,8 @@ namespace VpSharp; public sealed partial class VirtualParadiseClient { private readonly Subject _avatarClicked = new(); - private readonly Subject _avatarJoined = new(); - private readonly Subject _avatarLeft = new(); + private readonly Subject _avatarJoined = new(); + private readonly Subject _avatarLeft = new(); private readonly Subject _avatarMoved = new(); private readonly Subject _avatarTypeChanged = new(); private readonly Subject _inviteRequestReceived = new(); @@ -35,7 +35,7 @@ public sealed partial class VirtualParadiseClient /// /// Occurs when an avatar has entered the vicinity of the client. /// - public IObservable AvatarJoined + public IObservable AvatarJoined { get => _avatarJoined; } @@ -43,7 +43,7 @@ public sealed partial class VirtualParadiseClient /// /// Occurs when an avatar has left the vicinity of the client. /// - public IObservable AvatarLeft + public IObservable AvatarLeft { get => _avatarLeft; } diff --git a/VpSharp/src/VirtualParadiseClient.NativeEvents.cs b/VpSharp/src/VirtualParadiseClient.NativeEvents.cs index 98f038c..2d38b13 100644 --- a/VpSharp/src/VirtualParadiseClient.NativeEvents.cs +++ b/VpSharp/src/VirtualParadiseClient.NativeEvents.cs @@ -74,7 +74,7 @@ public sealed partial class VirtualParadiseClient style = (FontStyle)vp_int(sender, IntegerAttribute.ChatEffects); } - Avatar avatar = GetAvatar(session)!; + IAvatar avatar = GetAvatar(session)!; message = new Message((MessageType)type, name, content, avatar, style, color); } @@ -115,7 +115,7 @@ public sealed partial class VirtualParadiseClient rotation = Rotation.CreateFromTiltYawRoll(pitch, yaw, 0); } - Avatar avatar = GetAvatar(session)!; + var avatar = (Avatar)GetAvatar(session)!; if (type != avatar.Type) { int oldType = avatar.Type; @@ -145,7 +145,7 @@ public sealed partial class VirtualParadiseClient session = vp_int(sender, IntegerAttribute.AvatarSession); } - Avatar avatar = GetAvatar(session)!; + IAvatar avatar = GetAvatar(session)!; _avatars.TryRemove(session, out Avatar _); _avatarLeft.OnNext(avatar); } @@ -173,7 +173,7 @@ public sealed partial class VirtualParadiseClient } else { - Avatar avatar = GetAvatar(session)!; + IAvatar avatar = GetAvatar(session)!; var args = new ObjectCreatedEventArgs(avatar, virtualParadiseObject); _objectCreated.OnNext(args); } @@ -190,7 +190,7 @@ public sealed partial class VirtualParadiseClient session = vp_int(sender, IntegerAttribute.AvatarSession); } - Avatar avatar = GetAvatar(session)!; + IAvatar avatar = GetAvatar(session)!; VirtualParadiseObject? cachedObject = null; if (_objects.TryGetValue(objectId, out VirtualParadiseObject? virtualParadiseObject)) @@ -226,7 +226,7 @@ public sealed partial class VirtualParadiseClient session = vp_int(sender, IntegerAttribute.AvatarSession); } - Avatar? avatar = GetAvatar(session); + IAvatar avatar = GetAvatar(session)!; VirtualParadiseObject? virtualParadiseObject; try @@ -240,7 +240,7 @@ public sealed partial class VirtualParadiseClient _objects.TryRemove(objectId, out VirtualParadiseObject _); - var args = new ObjectDeletedEventArgs(avatar!, objectId, virtualParadiseObject!); + var args = new ObjectDeletedEventArgs(avatar, objectId, virtualParadiseObject!); _objectDeleted.OnNext(args); } @@ -261,7 +261,7 @@ public sealed partial class VirtualParadiseClient clickPoint = new Vector3d(x, y, z); } - Avatar avatar = GetAvatar(session)!; + IAvatar avatar = GetAvatar(session)!; try { VirtualParadiseObject virtualParadiseObject = await GetObjectAsync(objectId).ConfigureAwait(false); @@ -423,8 +423,8 @@ public sealed partial class VirtualParadiseClient clickPoint = new Vector3d(x, y, z); } - Avatar avatar = GetAvatar(session)!; - Avatar clickedAvatar = GetAvatar(clickedSession)!; + IAvatar avatar = GetAvatar(session)!; + IAvatar clickedAvatar = GetAvatar(clickedSession)!; var args = new AvatarClickedEventArgs(avatar, clickedAvatar, clickPoint); _avatarClicked.OnNext(args); } @@ -457,8 +457,8 @@ public sealed partial class VirtualParadiseClient : await GetWorldAsync(worldName).ConfigureAwait(false))!; var location = new Location(world, position, rotation); - CurrentAvatar!.Location = location; - Avatar avatar = GetAvatar(session)!; + ((Avatar)CurrentAvatar!).Location = location; + IAvatar avatar = GetAvatar(session)!; var args = new TeleportedEventArgs(avatar, location); _teleported.OnNext(args); } @@ -474,7 +474,7 @@ public sealed partial class VirtualParadiseClient objectId = vp_int(sender, IntegerAttribute.ObjectId); } - Avatar avatar = GetAvatar(session)!; + IAvatar avatar = GetAvatar(session)!; try { var vpObject = await GetObjectAsync(objectId).ConfigureAwait(false); @@ -505,7 +505,7 @@ public sealed partial class VirtualParadiseClient return; } - Avatar avatar = GetAvatar(session)!; + IAvatar avatar = GetAvatar(session)!; var uri = new Uri(url); var args = new UriReceivedEventArgs(uri, target, avatar); _uriReceived.OnNext(args); @@ -522,7 +522,7 @@ public sealed partial class VirtualParadiseClient objectId = vp_int(sender, IntegerAttribute.ObjectId); } - Avatar avatar = GetAvatar(session)!; + IAvatar avatar = GetAvatar(session)!; try { var vpObject = await GetObjectAsync(objectId).ConfigureAwait(false); diff --git a/VpSharp/src/VirtualParadiseClient.cs b/VpSharp/src/VirtualParadiseClient.cs index 2f69dae..ceb8c1c 100644 --- a/VpSharp/src/VirtualParadiseClient.cs +++ b/VpSharp/src/VirtualParadiseClient.cs @@ -66,7 +66,7 @@ public sealed partial class VirtualParadiseClient : IDisposable /// Gets a read-only view of the cached avatars. /// /// The cached avatars. - public IReadOnlyList Avatars + public IReadOnlyList Avatars { get => _avatars.Values.ToArray(); } @@ -77,7 +77,7 @@ public sealed partial class VirtualParadiseClient : IDisposable /// /// An instance of , or if this client is not in a world. /// - public Avatar? CurrentAvatar { get; internal set; } + public IAvatar? CurrentAvatar { get; internal set; } /// /// Gets the current user to which this client is logged in. @@ -399,7 +399,7 @@ public sealed partial class VirtualParadiseClient : IDisposable if (CurrentAvatar is not null) { // TODO why is this here? we reassign CurrentAvatar right below! - CurrentAvatar.Location = new Location(world); + ((Avatar)CurrentAvatar).Location = new Location(world); } world.Size = new Size(size, size); @@ -593,7 +593,7 @@ public sealed partial class VirtualParadiseClient : IDisposable } } - Avatar? avatar = CurrentAvatar; + IAvatar? avatar = CurrentAvatar; return Task.FromResult(new Message( MessageType.ChatMessage, avatar!.Name, @@ -680,12 +680,11 @@ public sealed partial class VirtualParadiseClient : IDisposable } } - Avatar avatar = CurrentAvatar!; return Task.FromResult(new Message( MessageType.ConsoleMessage, name, message, - avatar, + CurrentAvatar!, fontStyle, color ));