using AnotherReplayReader.ReplayFile; using System.Collections.Immutable; using System.Linq; namespace AnotherReplayReader.Utils { internal class ReplayPinyinList { private readonly PlayerIdentity _playerIdentity; public ImmutableArray Replays { get; } = ImmutableArray.Empty; public ImmutableArray Pinyins { get; } = ImmutableArray.Empty; public ReplayPinyinList(PlayerIdentity playerIdentity) : this(ImmutableArray.Empty, playerIdentity) { } public ReplayPinyinList(ImmutableArray replay, PlayerIdentity playerIdentity) : this(replay, replay.Select(replay => new ReplayPinyinData(replay, playerIdentity)).ToImmutableArray(), playerIdentity) { } private ReplayPinyinList(ImmutableArray replay, ImmutableArray 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; } } }