1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-12 01:27:20 +08:00

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.2 KiB
C#
Raw Normal View History

2020-12-19 00:15:41 +09:00
// 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.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Development;
2020-12-19 00:15:41 +09:00
using osu.Framework.Graphics;
using osu.Framework.Logging;
2020-12-25 13:38:11 +09:00
using osu.Game.Online.Rooms;
2020-12-19 00:15:41 +09:00
namespace osu.Game.Screens.OnlinePlay.Components
2020-12-19 00:15:41 +09:00
{
// Todo: This class should be inlined into the lounge.
public partial class RoomManager : Component, IRoomManager
2020-12-19 00:15:41 +09:00
{
public event Action? RoomsUpdated;
2020-12-19 00:15:41 +09:00
private readonly BindableList<Room> rooms = new BindableList<Room>();
public IBindableList<Room> Rooms => rooms;
public RoomManager()
2020-12-19 00:15:41 +09:00
{
RelativeSizeAxes = Axes.Both;
}
private readonly HashSet<long> ignoredRooms = new HashSet<long>();
2020-12-19 00:15:41 +09:00
public void AddOrUpdateRoom(Room room)
2020-12-19 00:15:41 +09:00
{
Debug.Assert(ThreadSafety.IsUpdateThread);
Debug.Assert(room.RoomID != null);
if (ignoredRooms.Contains(room.RoomID.Value))
return;
try
2020-12-19 00:15:41 +09:00
{
var existing = rooms.FirstOrDefault(e => e.RoomID == room.RoomID);
2021-08-16 13:04:06 +09:00
if (existing == null)
rooms.Add(room);
else
existing.CopyFrom(room);
2020-12-19 00:15:41 +09:00
}
catch (Exception ex)
2020-12-19 00:15:41 +09:00
{
2024-11-13 16:55:18 +09:00
Logger.Error(ex, $"Failed to update room: {room.Name}.");
2020-12-19 00:15:41 +09:00
ignoredRooms.Add(room.RoomID.Value);
rooms.Remove(room);
2020-12-19 00:15:41 +09:00
}
notifyRoomsUpdated();
2020-12-19 00:15:41 +09:00
}
public void RemoveRoom(Room room)
{
Debug.Assert(ThreadSafety.IsUpdateThread);
rooms.Remove(room);
notifyRoomsUpdated();
}
2020-12-19 02:02:04 +09:00
public void ClearRooms()
{
Debug.Assert(ThreadSafety.IsUpdateThread);
rooms.Clear();
notifyRoomsUpdated();
}
private void notifyRoomsUpdated()
{
Scheduler.AddOnce(invokeRoomsUpdated);
void invokeRoomsUpdated() => RoomsUpdated?.Invoke();
}
2020-12-19 00:15:41 +09:00
}
}