62 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using AnotherReplayReader.ReplayFile;
 | 
						|
using System.Collections.Immutable;
 | 
						|
using System.Linq;
 | 
						|
 | 
						|
namespace AnotherReplayReader.Utils
 | 
						|
{
 | 
						|
    internal class ReplayPinyinList
 | 
						|
    {
 | 
						|
        private readonly PlayerIdentity _playerIdentity;
 | 
						|
        public ImmutableArray<Replay> Replays { get; } = ImmutableArray<Replay>.Empty;
 | 
						|
        public ImmutableArray<ReplayPinyinData> Pinyins { get; } = ImmutableArray<ReplayPinyinData>.Empty;
 | 
						|
 | 
						|
        public ReplayPinyinList(PlayerIdentity playerIdentity) :
 | 
						|
            this(ImmutableArray<Replay>.Empty, playerIdentity)
 | 
						|
        {
 | 
						|
        }
 | 
						|
 | 
						|
        public ReplayPinyinList(ImmutableArray<Replay> replay, PlayerIdentity playerIdentity) :
 | 
						|
            this(replay,
 | 
						|
                 replay.Select(replay => new ReplayPinyinData(replay, playerIdentity)).ToImmutableArray(),
 | 
						|
                 playerIdentity)
 | 
						|
        {
 | 
						|
        }
 | 
						|
 | 
						|
        private ReplayPinyinList(ImmutableArray<Replay> replay,
 | 
						|
                                 ImmutableArray<ReplayPinyinData> pinyins,
 | 
						|
                                 PlayerIdentity playerIdentity)
 | 
						|
        {
 | 
						|
            _playerIdentity = playerIdentity;
 | 
						|
            Replays = replay;
 | 
						|
            Pinyins = pinyins;
 | 
						|
        }
 | 
						|
 | 
						|
        public ReplayPinyinList SetItem(int index, Replay replay)
 | 
						|
        {
 | 
						|
            return new(Replays.SetItem(index, replay),
 | 
						|
                       Pinyins.SetItem(index, new(replay, _playerIdentity)),
 | 
						|
                       _playerIdentity);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    class ReplayPinyinData
 | 
						|
    {
 | 
						|
        public Replay Replay { get; }
 | 
						|
        public string? PinyinDetails { get; }
 | 
						|
        public string? PinyinMod { get; }
 | 
						|
 | 
						|
        public ReplayPinyinData(Replay replay, PlayerIdentity playerIdentity)
 | 
						|
        {
 | 
						|
            Replay = replay;
 | 
						|
            PinyinDetails = replay.GetDetails(playerIdentity).ToPinyin();
 | 
						|
            PinyinMod = replay.Mod.ModName.ToPinyin();
 | 
						|
        }
 | 
						|
 | 
						|
        public bool MatchPinyin(string? pinyin)
 | 
						|
        {
 | 
						|
            return PinyinDetails?.ContainsIgnoreCase(pinyin) is true
 | 
						|
                || PinyinMod?.ContainsIgnoreCase(pinyin) is true;
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |