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

51 lines
1.8 KiB
C#

namespace GFramework.Godot.Text;
/// <summary>
/// 描述一个富文本效果组合配置。
/// 该资源是 Godot 编辑器与场景系统使用的配置载体;运行时控制器会先把它转换为
/// <see cref="RichTextEffectPlan" />,再在纯托管边界内完成刷新决策。
/// </summary>
[GlobalClass]
public partial class RichTextProfile : Resource
{
/// <summary>
/// 获取或设置当前配置启用的效果条目集合。
/// </summary>
[Export]
public RichTextEffectEntry[] Effects { get; set; } = [];
/// <summary>
/// 创建包含全部内置效果的默认配置。
/// 该方法为第一阶段提供零配置可用的回退组合。
/// </summary>
/// <returns>包含全部内置效果键的默认配置。</returns>
public static RichTextProfile CreateBuiltInDefault()
{
return FromPlan(RichTextEffectPlan.CreateBuiltInDefault());
}
/// <summary>
/// 从纯托管效果计划创建对应的 Godot 资源配置。
/// 该转换只应发生在真正需要与 Godot 宿主或公开注册表交互的适配层边界上。
/// </summary>
/// <param name="plan">待转换的纯托管效果计划。</param>
/// <returns>与计划等价的 Godot 资源配置。</returns>
/// <exception cref="ArgumentNullException">
/// 当 <paramref name="plan" /> 为 <see langword="null" /> 时抛出。
/// </exception>
internal static RichTextProfile FromPlan(RichTextEffectPlan plan)
{
ArgumentNullException.ThrowIfNull(plan);
var profile = new RichTextProfile();
profile.Effects = plan.Effects
.Select(static entry => new RichTextEffectEntry
{
Key = entry.Key,
Enabled = entry.Enabled
})
.ToArray();
return profile;
}
}