GFramework/GFramework.Godot/Text/RichTextEffectPlan.cs
GeWuYou 11515ff791 feat(godot): 添加富文本标签效果系统支持
- 新增 GfRichTextLabel 组件作为富文本标签宿主
- 实现 IRichTextEffectHost 接口用于效果控制器驱动
- 创建 RichTextEffectsController 处理效果装配逻辑
- 添加 RichTextProfile 配置资源类型
- 引入 RichTextEffectPlan 和 RichTextEffectPlanEntry 类型
- 在 CI 工作流中添加 GFramework.Godot.Tests 项目
- 优化 Godot 测试诊断条件判断逻辑
- 添加富文本效果控制器相关单元测试
2026-04-18 15:47:08 +08:00

71 lines
2.6 KiB
C#

namespace GFramework.Godot.Text;
/// <summary>
/// 描述一次富文本效果安装所需的纯托管计划。
/// 该类型用于把控制器与测试替身隔离在 Godot runtime 之外,使刷新决策可以在普通 .NET 测试进程中验证。
/// </summary>
internal sealed class RichTextEffectPlan
{
/// <summary>
/// 初始化一个富文本效果计划。
/// </summary>
/// <param name="effects">计划中声明的效果条目集合。</param>
/// <exception cref="ArgumentNullException">
/// 当 <paramref name="effects" /> 为 <see langword="null" /> 时抛出。
/// </exception>
public RichTextEffectPlan(IReadOnlyList<RichTextEffectPlanEntry> effects)
{
ArgumentNullException.ThrowIfNull(effects);
Effects = effects.ToArray();
}
/// <summary>
/// 获取当前计划启用的效果条目集合。
/// </summary>
public IReadOnlyList<RichTextEffectPlanEntry> Effects { get; }
/// <summary>
/// 从 Godot 资源配置转换为纯托管计划。
/// </summary>
/// <param name="profile">待转换的资源配置。</param>
/// <returns>与资源配置等价的纯托管计划。</returns>
/// <exception cref="ArgumentNullException">
/// 当 <paramref name="profile" /> 为 <see langword="null" /> 时抛出。
/// </exception>
public static RichTextEffectPlan FromProfile(RichTextProfile profile)
{
ArgumentNullException.ThrowIfNull(profile);
var effects = new RichTextEffectPlanEntry[profile.Effects.Length];
for (var index = 0; index < profile.Effects.Length; index++)
{
var entry = profile.Effects[index];
effects[index] = entry is null
? default
: new RichTextEffectPlanEntry(entry.Key, entry.Enabled);
}
return new RichTextEffectPlan(effects);
}
/// <summary>
/// 创建包含全部内置效果的默认计划。
/// </summary>
/// <returns>包含第一阶段全部内置效果键的默认计划。</returns>
public static RichTextEffectPlan CreateBuiltInDefault()
{
return new RichTextEffectPlan(
[
new RichTextEffectPlanEntry("green"),
new RichTextEffectPlanEntry("red"),
new RichTextEffectPlanEntry("gold"),
new RichTextEffectPlanEntry("blue"),
new RichTextEffectPlanEntry("fade_in"),
new RichTextEffectPlanEntry("sine"),
new RichTextEffectPlanEntry("jitter"),
new RichTextEffectPlanEntry("fly_in")
]);
}
}