Don't bind to RoomId where it's expected to be constant

This commit is contained in:
smoogipoo 2021-08-24 14:25:29 +09:00
parent df170afbc4
commit 16ddbcd208
4 changed files with 19 additions and 18 deletions

View File

@ -10,36 +10,36 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
{ {
public class MatchChatDisplay : StandAloneChatDisplay public class MatchChatDisplay : StandAloneChatDisplay
{ {
private readonly IBindable<long?> roomId = new Bindable<long?>();
private readonly IBindable<int> channelId = new Bindable<int>(); private readonly IBindable<int> channelId = new Bindable<int>();
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private ChannelManager channelManager { get; set; } private ChannelManager channelManager { get; set; }
private readonly Room room;
private readonly bool leaveChannelOnDispose; private readonly bool leaveChannelOnDispose;
public MatchChatDisplay(Room room, bool leaveChannelOnDispose = true) public MatchChatDisplay(Room room, bool leaveChannelOnDispose = true)
: base(true) : base(true)
{ {
this.room = room;
this.leaveChannelOnDispose = leaveChannelOnDispose; this.leaveChannelOnDispose = leaveChannelOnDispose;
roomId.BindTo(room.RoomID);
channelId.BindTo(room.ChannelId);
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
// Required for the time being since this component is created prior to the room being joined.
channelId.BindTo(room.ChannelId);
channelId.BindValueChanged(_ => updateChannel(), true); channelId.BindValueChanged(_ => updateChannel(), true);
} }
private void updateChannel() private void updateChannel()
{ {
if (roomId.Value == null || channelId.Value == 0) if (room.RoomID.Value == null || channelId.Value == 0)
return; return;
Channel.Value = channelManager?.JoinChannel(new Channel { Id = channelId.Value, Type = ChannelType.Multiplayer, Name = $"#lazermp_{roomId.Value}" }); Channel.Value = channelManager?.JoinChannel(new Channel { Id = channelId.Value, Type = ChannelType.Multiplayer, Name = $"#lazermp_{room.RoomID.Value}" });
} }
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)

View File

@ -187,10 +187,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
protected override ResultsScreen CreateResults(ScoreInfo score) protected override ResultsScreen CreateResults(ScoreInfo score)
{ {
Debug.Assert(RoomId.Value != null); Debug.Assert(Room.RoomID.Value != null);
return leaderboard.TeamScores.Count == 2 return leaderboard.TeamScores.Count == 2
? new MultiplayerTeamResultsScreen(score, RoomId.Value.Value, PlaylistItem, leaderboard.TeamScores) ? new MultiplayerTeamResultsScreen(score, Room.RoomID.Value.Value, PlaylistItem, leaderboard.TeamScores)
: new MultiplayerResultsScreen(score, RoomId.Value.Value, PlaylistItem); : new MultiplayerResultsScreen(score, Room.RoomID.Value.Value, PlaylistItem);
} }
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)

View File

@ -51,8 +51,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
protected override ResultsScreen CreateResults(ScoreInfo score) protected override ResultsScreen CreateResults(ScoreInfo score)
{ {
Debug.Assert(RoomId.Value != null); Debug.Assert(Room.RoomID.Value != null);
return new PlaylistsResultsScreen(score, RoomId.Value.Value, PlaylistItem, true); return new PlaylistsResultsScreen(score, Room.RoomID.Value.Value, PlaylistItem, true);
} }
protected override async Task PrepareScoreForResultsAsync(Score score) protected override async Task PrepareScoreForResultsAsync(Score score)

View File

@ -1,7 +1,7 @@
// 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.
using osu.Framework.Bindables; using System.Diagnostics;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Scoring; using osu.Game.Scoring;
@ -13,8 +13,6 @@ namespace osu.Game.Screens.Play
/// </summary> /// </summary>
public abstract class RoomSubmittingPlayer : SubmittingPlayer public abstract class RoomSubmittingPlayer : SubmittingPlayer
{ {
protected readonly IBindable<long?> RoomId = new Bindable<long?>();
protected readonly PlaylistItem PlaylistItem; protected readonly PlaylistItem PlaylistItem;
protected readonly Room Room; protected readonly Room Room;
@ -23,18 +21,20 @@ namespace osu.Game.Screens.Play
{ {
Room = room; Room = room;
PlaylistItem = playlistItem; PlaylistItem = playlistItem;
RoomId.BindTo(room.RoomID);
} }
protected override APIRequest<APIScoreToken> CreateTokenRequest() protected override APIRequest<APIScoreToken> CreateTokenRequest()
{ {
if (!(RoomId.Value is long roomId)) if (!(Room.RoomID.Value is long roomId))
return null; return null;
return new CreateRoomScoreRequest(roomId, PlaylistItem.ID, Game.VersionHash); return new CreateRoomScoreRequest(roomId, PlaylistItem.ID, Game.VersionHash);
} }
protected override APIRequest<MultiplayerScore> CreateSubmissionRequest(Score score, long token) => new SubmitRoomScoreRequest(token, RoomId.Value ?? 0, PlaylistItem.ID, score.ScoreInfo); protected override APIRequest<MultiplayerScore> CreateSubmissionRequest(Score score, long token)
{
Debug.Assert(Room.RoomID.Value != null);
return new SubmitRoomScoreRequest(token, Room.RoomID.Value.Value, PlaylistItem.ID, score.ScoreInfo);
}
} }
} }