using GFramework.Godot.Text.Effects; namespace GFramework.Godot.Text; /// /// 默认的富文本效果注册表。 /// 该实现仅负责内置效果键的解析,不处理业务层文本构建或配置持久化。 /// public sealed class DefaultRichTextEffectRegistry : IRichTextEffectRegistry { /// /// 创建当前配置对应的全部效果实例。 /// /// 效果组合配置。 /// 当前是否允许字符级动态效果生效。 /// 内置效果实例集合。 /// /// 当 时抛出。 /// public IReadOnlyList CreateEffects(RichTextProfile profile, bool animatedEffectsEnabled) { ArgumentNullException.ThrowIfNull(profile); var effects = new List(profile.Effects.Length); foreach (var entry in profile.Effects) { if (entry is null || !entry.Enabled || string.IsNullOrWhiteSpace(entry.Key)) { continue; } var effect = CreateEffect(entry.Key, animatedEffectsEnabled); if (effect is not null) { effects.Add(effect); } } return effects; } /// /// 根据效果键创建单个效果实例。 /// /// 效果键。 /// 当前是否允许字符级动态效果生效。 /// 解析成功时返回效果实例;否则返回 public RichTextEffect? CreateEffect(string key, bool animatedEffectsEnabled) { if (string.IsNullOrWhiteSpace(key)) { return null; } return key.Trim().ToLowerInvariant() switch { "green" => new RichTextGreenEffect(), "red" => new RichTextRedEffect(), "gold" => new RichTextGoldEffect(), "blue" => new RichTextBlueEffect(), "fade_in" => new RichTextFadeInEffect(animatedEffectsEnabled), "sine" => new RichTextSineEffect(animatedEffectsEnabled), "jitter" => new RichTextJitterEffect(animatedEffectsEnabled), "fly_in" => new RichTextFlyInEffect(animatedEffectsEnabled), _ => null }; } }