86 lines
3.0 KiB
C#
86 lines
3.0 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine.Localization;
|
|
|
|
namespace AibisDream.MiniGame.Language
|
|
{
|
|
public sealed class ExpressionRoundTextSnapshot
|
|
{
|
|
private ExpressionRoundTextSnapshot(
|
|
LocaleIdentifier locale,
|
|
ExpressionParticleLocaleSettings profile,
|
|
string targetText,
|
|
List<string> targetUnits,
|
|
List<float> targetGapWeights,
|
|
List<string> defaultPoolUnits,
|
|
List<string> interferencePoolUnits)
|
|
{
|
|
Locale = locale;
|
|
Profile = profile;
|
|
TargetText = targetText;
|
|
TargetUnits = targetUnits.AsReadOnly();
|
|
TargetGapWeights = targetGapWeights.AsReadOnly();
|
|
DefaultPoolUnits = defaultPoolUnits.AsReadOnly();
|
|
InterferencePoolUnits = interferencePoolUnits.AsReadOnly();
|
|
}
|
|
|
|
public LocaleIdentifier Locale { get; }
|
|
public ExpressionParticleLocaleSettings Profile { get; }
|
|
public string TargetText { get; }
|
|
public IReadOnlyList<string> TargetUnits { get; }
|
|
public IReadOnlyList<float> TargetGapWeights { get; }
|
|
public IReadOnlyList<string> DefaultPoolUnits { get; }
|
|
public IReadOnlyList<string> InterferencePoolUnits { get; }
|
|
|
|
public static bool TryCreate(
|
|
LocaleIdentifier locale,
|
|
ExpressionParticleLocaleSettings profile,
|
|
string targetText,
|
|
IEnumerable<string> interferencePhrases,
|
|
string defaultPool,
|
|
out ExpressionRoundTextSnapshot snapshot,
|
|
out string error)
|
|
{
|
|
snapshot = null;
|
|
profile ??= ExpressionParticleLocaleSettings.CreateFallback();
|
|
|
|
ExpressionTextTokenizer.UnitSequence target =
|
|
ExpressionTextTokenizer.BuildLayoutUnits(targetText, profile.UnitMode);
|
|
if (target.Count == 0)
|
|
{
|
|
error = "目标句没有有效的粒子单位。";
|
|
return false;
|
|
}
|
|
|
|
if (!ExpressionTextTokenizer.TryTokenizePool(
|
|
defaultPool,
|
|
profile.UnitMode,
|
|
out List<string> defaultUnits))
|
|
{
|
|
error = "默认粒子池为空或包含非法分隔符。";
|
|
return false;
|
|
}
|
|
|
|
List<string> interferenceUnits =
|
|
ExpressionTextTokenizer.BuildUnitPool(
|
|
interferencePhrases,
|
|
profile.UnitMode);
|
|
if (interferenceUnits.Count == 0)
|
|
{
|
|
error = "干扰短句没有有效的粒子单位。";
|
|
return false;
|
|
}
|
|
|
|
snapshot = new ExpressionRoundTextSnapshot(
|
|
locale,
|
|
profile,
|
|
targetText,
|
|
new List<string>(target.Units),
|
|
new List<float>(target.GapWeights),
|
|
defaultUnits,
|
|
interferenceUnits);
|
|
error = null;
|
|
return true;
|
|
}
|
|
}
|
|
}
|