改了一亿个东西,修了一亿个 BUG

This commit is contained in:
2021-10-19 17:42:18 +02:00
parent 5b907309e0
commit 888ddce4ef
40 changed files with 1870 additions and 1715 deletions

61
Utils/ReplayPinyinList.cs Normal file
View File

@@ -0,0 +1,61 @@
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;
}
}
}