Simplify channel filter method

This commit is contained in:
Dean Herbert
2022-05-26 18:47:50 +09:00
parent b2607196b8
commit a98d0cf0d8

View File

@ -3,7 +3,6 @@
#nullable enable #nullable enable
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Diagnostics; using System.Diagnostics;
@ -56,13 +55,6 @@ namespace osu.Game.Overlays
private const float side_bar_width = 190; private const float side_bar_width = 190;
private const float chat_bar_height = 60; private const float chat_bar_height = 60;
private readonly ChannelType[] excludedChannelTypes =
{
ChannelType.Multiplayer,
ChannelType.Spectator,
ChannelType.Temporary,
};
[Resolved] [Resolved]
private OsuConfigManager config { get; set; } = null!; private OsuConfigManager config { get; set; } = null!;
@ -353,7 +345,7 @@ namespace osu.Game.Overlays
switch (args.Action) switch (args.Action)
{ {
case NotifyCollectionChangedAction.Add: case NotifyCollectionChangedAction.Add:
IEnumerable<Channel> newChannels = filterToChatChannels(args.NewItems); IEnumerable<Channel> newChannels = args.NewItems.OfType<Channel>().Where(isChatChannel);
foreach (var channel in newChannels) foreach (var channel in newChannels)
channelList.AddChannel(channel); channelList.AddChannel(channel);
@ -361,7 +353,7 @@ namespace osu.Game.Overlays
break; break;
case NotifyCollectionChangedAction.Remove: case NotifyCollectionChangedAction.Remove:
IEnumerable<Channel> leftChannels = filterToChatChannels(args.OldItems); IEnumerable<Channel> leftChannels = args.OldItems.OfType<Channel>().Where(isChatChannel);
foreach (var channel in leftChannels) foreach (var channel in leftChannels)
{ {
@ -408,7 +400,21 @@ namespace osu.Game.Overlays
channelList.ScrollChannelIntoView(currentChannel.Value); channelList.ScrollChannelIntoView(currentChannel.Value);
} }
private IEnumerable<Channel> filterToChatChannels(IEnumerable channels) /// <summary>
=> channels.Cast<Channel>().Where(c => !excludedChannelTypes.Contains(c.Type)); /// Whether a channel should be displayed in this overlay, based on its type.
/// </summary>
private static bool isChatChannel(Channel channel)
{
switch (channel.Type)
{
case ChannelType.Multiplayer:
case ChannelType.Spectator:
case ChannelType.Temporary:
return false;
default:
return true;
}
}
} }
} }