1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-16 18:32:56 +08:00

Make remaining model classes nullable and serializable

This commit is contained in:
Dean Herbert 2020-12-08 16:15:51 +09:00
parent 2365d65610
commit 5d2ca7fc39
5 changed files with 28 additions and 11 deletions

View File

@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable enable
namespace osu.Game.Online.RealtimeMultiplayer namespace osu.Game.Online.RealtimeMultiplayer
{ {
public class MultiplayerClientState public class MultiplayerClientState

View File

@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable enable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -25,13 +27,18 @@ namespace osu.Game.Online.RealtimeMultiplayer
/// <summary> /// <summary>
/// All currently enforced game settings for this room. /// All currently enforced game settings for this room.
/// </summary> /// </summary>
public MultiplayerRoomSettings Settings { get; set; } public MultiplayerRoomSettings Settings { get; set; } = MultiplayerRoomSettings.Empty();
/// <summary> /// <summary>
/// All users currently in this room. /// All users currently in this room.
/// </summary> /// </summary>
public List<MultiplayerRoomUser> Users { get; set; } = new List<MultiplayerRoomUser>(); public List<MultiplayerRoomUser> Users { get; set; } = new List<MultiplayerRoomUser>();
/// <summary>
/// The host of this room, in control of changing room settings.
/// </summary>
public MultiplayerRoomUser? Host { get; set; }
private object writeLock = new object(); private object writeLock = new object();
/// <summary> /// <summary>

View File

@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable enable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -9,6 +11,7 @@ using osu.Game.Online.API;
namespace osu.Game.Online.RealtimeMultiplayer namespace osu.Game.Online.RealtimeMultiplayer
{ {
[Serializable]
public class MultiplayerRoomSettings : IEquatable<MultiplayerRoomSettings> public class MultiplayerRoomSettings : IEquatable<MultiplayerRoomSettings>
{ {
public int? BeatmapID { get; set; } public int? BeatmapID { get; set; }
@ -18,8 +21,10 @@ namespace osu.Game.Online.RealtimeMultiplayer
[NotNull] [NotNull]
public IEnumerable<APIMod> Mods { get; set; } = Enumerable.Empty<APIMod>(); public IEnumerable<APIMod> Mods { get; set; } = Enumerable.Empty<APIMod>();
public bool Equals(MultiplayerRoomSettings other) => BeatmapID == other?.BeatmapID && Mods.SequenceEqual(other?.Mods) && RulesetID == other?.RulesetID; public bool Equals(MultiplayerRoomSettings other) => BeatmapID == other.BeatmapID && Mods.SequenceEqual(other.Mods) && RulesetID == other.RulesetID;
public override string ToString() => $"Beatmap:{BeatmapID} Mods:{string.Join(',', Mods)} Ruleset:{RulesetID}"; public override string ToString() => $"Beatmap:{BeatmapID} Mods:{string.Join(',', Mods)} Ruleset:{RulesetID}";
public static MultiplayerRoomSettings Empty() => new MultiplayerRoomSettings();
} }
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable enable
namespace osu.Game.Online.RealtimeMultiplayer namespace osu.Game.Online.RealtimeMultiplayer
{ {
/// <summary> /// <summary>

View File

@ -1,27 +1,29 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable enable
using System; using System;
using osu.Game.Users; using osu.Game.Users;
namespace osu.Game.Online.RealtimeMultiplayer namespace osu.Game.Online.RealtimeMultiplayer
{ {
[Serializable]
public class MultiplayerRoomUser : IEquatable<MultiplayerRoomUser> public class MultiplayerRoomUser : IEquatable<MultiplayerRoomUser>
{ {
public readonly long UserID;
public MultiplayerUserState State { get; set; } = MultiplayerUserState.Idle;
public User? User { get; set; }
public MultiplayerRoomUser(in int userId) public MultiplayerRoomUser(in int userId)
{ {
UserID = userId; UserID = userId;
} }
public long UserID { get; }
public MultiplayerUserState State { get; set; }
public User User { get; set; }
public bool Equals(MultiplayerRoomUser other) public bool Equals(MultiplayerRoomUser other)
{ {
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true; if (ReferenceEquals(this, other)) return true;
return UserID == other.UserID; return UserID == other.UserID;
@ -29,9 +31,8 @@ namespace osu.Game.Online.RealtimeMultiplayer
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true; if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false; if (obj.GetType() != GetType()) return false;
return Equals((MultiplayerRoomUser)obj); return Equals((MultiplayerRoomUser)obj);
} }