diff options
Diffstat (limited to 'OnekoNet.cs')
| -rw-r--r-- | OnekoNet.cs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/OnekoNet.cs b/OnekoNet.cs new file mode 100644 index 0000000..a7f2d83 --- /dev/null +++ b/OnekoNet.cs @@ -0,0 +1,46 @@ +using System.Numerics; +using OnekoOnline.Net; +using Raylib_cs; + +namespace OnekoOnline; + +class OnekoNet : Oneko +{ + readonly User MyUser; + + public static Dictionary<int, OnekoNet> NetNekos = []; + + public OnekoNet(Bitmap bitmap, User user) : base(bitmap) + { + MyUser = user; + + Client.UserDisconnected += disconnectedUser => { + if (disconnectedUser == MyUser) Dispose(); + }; + + Client.PacketRecived += (reader, user, packetType) => { + if (user != MyUser) return; + + if (packetType == PacketType.OnekoTargetPosition) TargetPosition = reader.GetVector2(); + }; + } + + public static void SpawnNetNeko(User user) + { + if (user.ExchangedData && !NetNekos.ContainsKey(user.Id)) { + Bitmap spriteSheet = Bitmap.Deserialize(user.SpriteSheet); + NetNekos.Add(user.Id, new OnekoNet(spriteSheet, user)); + } + } + + public override void Dispose() + { + NetNekos.Remove(MyUser.Id); + base.Dispose(); + } + + public static void DisconnectAll() + { + foreach (OnekoNet neko in NetNekos.Values) neko.Dispose(); + } +}
\ No newline at end of file |
