Compare commits

...

209 Commits

Author SHA1 Message Date
gewuyou
63b1d71a0e
Merge pull request #127 from GeWuYou/feat/async-log-appender-error-handler
feat(logging): 添加异步日志输出器的错误处理回调功能
2026-03-21 22:09:06 +08:00
GeWuYou
cdc49c319a feat(logging): 添加异步日志输出器功能
- 使用 Channel 实现异步日志处理机制
- 解耦调用线程与慢速日志目标
- 添加全局 Channels 命名空间引用
- 完善日志组件的异步处理能力
2026-03-21 22:04:09 +08:00
GeWuYou
d94d8deb29 fix(logging): 修复异步日志追加器中的操作取消异常处理
- 添加对 OperationCanceledException 的特殊处理,避免将其报告为后台处理错误
- 在 ReportProcessingError 方法中检查并过滤掉操作取消异常
- 添加单元测试验证当内部追加器抛出 OperationCanceledException 时不报告错误
- 创建 CancellationAppender 测试辅助类来模拟取消异常场景
- 确保取消相关的异常不会触发错误处理逻辑
2026-03-21 21:59:51 +08:00
GeWuYou
49609d3821 feat(logging): 添加异步日志输出器的错误处理回调功能
- 在 AsyncLogAppender 构造函数中添加 processingErrorHandler 参数用于处理后台异常
- 实现 ReportProcessingError 方法安全上报后台处理异常而不影响处理循环
- 更新文档注释说明异常处理机制和错误回调用途
- 修改测试用例验证异常处理回调功能的正确性
- 确保错误观察者异常不会终止日志处理线程
- 移除直接写入控制台错误输出的逻辑改为统一回调处理
2026-03-21 21:54:24 +08:00
gewuyou
003fe42ad8
Merge pull request #126 from GeWuYou/refactor/generators-downgrade-to-netstandard20
refactor(generators): 将源代码生成器项目目标框架降级至 netstandard2.0
2026-03-21 21:40:43 +08:00
GeWuYou
a42ec0c282 fix(generator): 修复优先级生成器中的部分关键字检查逻辑
- 将语法节点的部分关键字检查从 Any 操作改为 All 操作
- 修正了对非部分类的诊断报告条件判断
- 确保只有当所有修饰符都不是部分关键字时才报告错误
2026-03-21 21:31:52 +08:00
GeWuYou
884249649d chore(build): 配置项目构建属性以支持源代码生成器
- 为 GFramework.Godot 项目添加 GodotProjectDir 属性默认值
- 在 GFramework 元包中添加 NoPackageAnalysis 属性配置
- 为不同 .NET 版本添加占位符文件到包输出中
- 确保源代码生成器在标准 SDK 构建中正常运行
2026-03-21 21:30:29 +08:00
GeWuYou
d582dffe40 refactor(generators): 将源代码生成器项目目标框架降级至 netstandard2.0
- 将 GFramework.Godot.SourceGenerators 项目的目标框架从 netstandard2.1 更改为 netstandard2.0
- 将 GFramework.SourceGenerators.Abstractions 项目的目标框架从 netstandard2.1 更改为 netstandard2.0
- 将 GFramework.SourceGenerators 项目的目标框架从 netstandard2.1 更改为 netstandard2.0
- 将 GFramework.SourceGenerators.Common 项目的目标框架从 netstandard2.1 更改为 netstandard2.0
- 从 GFramework.SourceGenerators 项目中移除对 GFramework.Core.Abstractions 的引用
- 从 GFramework.SourceGenerators.Abstractions 项目中移除对 GFramework.Core.Abstractions 的引用
- 更新 PriorityGenerator 中的语法检查逻辑,使用 Any 替代 All 进行 partial 关键字检查
- 更新 PriorityAttribute 文档注释中的 cref 格式为 c 标签
2026-03-21 21:20:32 +08:00
GeWuYou
63a6c2e6f0 refactor(abstractions): 移除重复的Key属性声明
- 从LockInfo结构体移除StructLayout特性
- 从ISceneBehavior接口移除重复的Key属性声明
- 从IUiPageBehavior接口移除重复的Key属性声明
- 简化LockInfo类定义减少不必要的using引用
2026-03-21 21:13:53 +08:00
GeWuYou
f3d45169cd refactor(pause): 将暂停状态变化事件改为标准事件模式
- 将 OnPauseStateChanged 事件从 Action<PauseGroup, bool> 类型改为 EventHandler<PauseStateChangedEventArgs>
- 添加 PauseStateChangedEventArgs 类来封装事件数据
- 更新所有事件处理方法的签名以匹配新的事件参数
- 修改文档中相关的事件处理代码示例
- 在 PauseStackManager 中添加 RaisePauseStateChanged 方法统一处理事件触发
- 更新测试代码以适应新的事件处理方式
2026-03-21 21:13:53 +08:00
GeWuYou
86645d34cb fix(generator): 修复诊断消息中的多余句号
- 移除了 Priority 特性描述中的多余句号
- 移除了 IPrioritized 接口实现跳过警告中的多余句号
- 移除了 partial 类要求错误中的多余句号
- 移除了 Priority 特性值验证错误中的多余句号
- 移除了嵌套类限制错误中的多余句号
- 移除了服务获取建议信息中的多余句号
2026-03-21 20:51:03 +08:00
GeWuYou
ab04f0ace7 docs(diagnostic): 更新诊断消息描述文本
- 为 Priority 特性错误消息添加句号结尾
- 为接口实现警告消息添加句号结尾
- 为 partial 类要求错误消息添加句号结尾
- 为整数值验证错误消息添加句号结尾
- 为嵌套类限制错误消息添加句号结尾
- 为服务获取建议消息添加句号结尾
- 在测试项目配置中添加警告级别设置
2026-03-21 20:51:03 +08:00
gewuyou
51492b1dcd fix(docs): remove dead ADR references 2026-03-21 15:56:18 +08:00
gewuyou
4caa3c0d71
Merge pull request #122 from GeWuYou/feat/localization-compact-number-formatter
Feat/localization compact number formatter
2026-03-21 15:07:02 +08:00
GeWuYou
fca3808657 fix(localization): 修复紧凑数字格式化器处理未知选项的行为
- 修改 CompactNumberLocalizationFormatter 中 TryApplyOption 方法的返回逻辑
- 当键名未知时现在返回 true 而不是 false,允许忽略未知选项
- 更新 NumericDisplayFormatter 使用 ResolveRule 方法来确定格式化规则
- 添加对不同数值显示风格的支持和验证
- 在集成测试中添加未知选项的测试用例以验证正确行为
- 改进 NumericSuffixFormatRule 的文档注释以更清楚地描述功能
2026-03-21 15:01:47 +08:00
GeWuYou
5996ecf5f3 docs(core): 添加内置数值显示工具文档
- 新增内置数值显示工具使用说明
- 提供 FormatCompact 和 ToCompactString 示例代码
- 展示 NumericFormatOptions 配置选项用法
- 介绍本地化文本中的数值格式化功能
- 更新相关链接列表移除多余逗号
2026-03-21 14:43:55 +08:00
GeWuYou
53edd13f8f feat(localization): 添加本地化格式化器和数值显示功能
- 在LocalizationManager中注册内置格式化器包括条件、复数和紧凑数值格式化器
- 实现CompactNumberLocalizationFormatter支持{value:compact}格式化语法
- 添加数值显示扩展方法ToDisplayString和ToCompactString
- 实现NumericDisplayFormatter和NumericSuffixFormatRule数值格式化核心逻辑
- 添加数值格式化选项配置包括小数位数、四舍五入策略等参数
- 为紧凑数值格式化功能添加完整的单元测试覆盖各种数值类型和边界情况
2026-03-21 14:43:42 +08:00
gewuyou
0442fec2d1
Merge pull request #121 from GeWuYou/docs/refactor-guidelines-comprehensive
Docs/refactor guidelines comprehensive
2026-03-21 13:47:39 +08:00
GeWuYou
2001eddbff refactor(scripts): 重构AI环境生成脚本以优化工具选择逻辑
- 移除shell脚本中的冗余命令执行逻辑
- 添加select_tool函数统一处理工具偏好和回退逻辑
- 使用新函数重构搜索、JSON处理、脚本编写等工具选择
- 更新时间戳以反映代码变更后的重新生成
- 简化构建工具配置的回退策略
2026-03-21 12:49:51 +08:00
GeWuYou
3130a3bab2 feat(docs): 添加开发环境能力清单及相关工具脚本
- 在贡献指南中添加开发环境能力清单链接和说明
- 创建详细的开发环境能力清单文档,记录项目所需的运行时和工具
- 添加 .ai/environment/tools.ai.yaml 文件,为 AI 提供精简的环境能力信息
- 添加 .ai/environment/tools.raw.yaml 文件,存储完整的环境检测数据
- 创建 collect-dev-environment.sh 脚本,用于收集和输出环境信息
- 创建 generate-ai-environment.py 脚本,从原始数据生成 AI 友好的环境清单
- 在 .gitignore 中添加 .venv/ 工具目录忽略规则
2026-03-21 12:37:56 +08:00
GeWuYou
ba4ee24ce7 docs(guidelines): 更新 AGENTS.md 和 CLAUDE.md 文档内容
- 重写 AGENTS.md 为 AI 代理和贡献者提供完整的编码行为准则
- 新增详细的注释规则,包括 XML 文档、内联注释和架构级注释要求
- 完善代码风格指南,涵盖命名约定、格式化和 C# 最佳实践
- 扩展测试要求,明确覆盖率、组织结构和执行期望
- 添加安全规则和文档规范,确保代码质量和安全性
- 重构 CLAUDE.md 为 AI 代理提供项目理解指导
- 更新模块依赖图和架构模式说明,澄清各层职责
- 补充源码生成器、测试框架和文档结构的详细说明
- 优化项目概述和设计意图描述,提升 AI 理解准确性
2026-03-21 11:36:39 +08:00
gewuyou
dfae4ba207
Merge pull request #120 from GeWuYou/feat/docs-add-repository-guide
docs(guide): 添加仓库开发指南文档
2026-03-20 08:36:02 +08:00
GeWuYou
ccb51791a3 docs(guide): 更新提交和拉取请求指南中的拼写错误
- 修复了 "Conventional Commit" 到 "Conventional Commits" 的拼写
- 确保文档中使用的术语与业界标准保持一致
2026-03-20 08:24:17 +08:00
GeWuYou
55234c4d70 docs(guide): 添加仓库开发指南文档
- 创建了项目结构和模块组织说明
- 添加了构建测试和开发命令指南
- 定义了代码风格和命名约定规范
- 提供了测试指南和最佳实践
- 包含了提交和拉取请求准则
- 记录了解决方案文件和目录布局说明
2026-03-20 08:18:00 +08:00
dependabot[bot]
108bcbf27e Bump Meziantou.Analyzer from 3.0.19 to 3.0.25
---
updated-dependencies:
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.25
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.25
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.25
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.25
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.25
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-20 08:12:51 +08:00
dependabot[bot]
51393c30ee Bump Microsoft.Extensions.DependencyInjection from 10.0.4 to 10.0.5
---
updated-dependencies:
- dependency-name: Microsoft.Extensions.DependencyInjection
  dependency-version: 10.0.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-20 08:12:35 +08:00
dependabot[bot]
589f9f7d63 Bump the nuget group with 1 update
Bumps Scriban from 6.2.0 to 6.6.0

---
updated-dependencies:
- dependency-name: Scriban
  dependency-version: 6.6.0
  dependency-type: direct:production
  dependency-group: nuget
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-20 08:12:18 +08:00
gewuyou
ba8369c8b3
Merge pull request #115 from GeWuYou/feat/localization-system
feat(core): 添加本地化系统支持多语言功能
2026-03-19 13:21:22 +08:00
GeWuYou
9ca28a44d8 refactor(localization): 优化回退表检查逻辑
- 将 Fallback.ContainsKey 检查替换为更安全的模式匹配语法
- 避免了潜在的空引用异常风险
- 提高了代码的可读性和健壮性
- 保持了原有的功能逻辑不变
2026-03-19 13:15:39 +08:00
GeWuYou
0c5c9dceae test(localization): 添加本地化集成测试的临时文件管理和测试数据创建
- 添加 System.IO 命名空间引用以支持文件操作
- 实现 CreateTestLocalizationFiles 方法创建测试用的多语言文件
- 使用 GUID 生成唯一的临时目录路径避免冲突
- 添加 TearDown 方法清理测试过程中创建的临时文件
- 在 Setup 方法中调用文件创建方法初始化测试环境
- 将目标框架配置改为可配置的条件变量方式
2026-03-19 12:52:11 +08:00
GeWuYou
d7e7d3cc7f feat(events): 为优先级事件系统添加线程安全支持
- 添加同步锁对象以保护处理器集合的并发访问
- 在注册和注销操作中加入线程安全锁机制
- 实现快照创建方法以避免迭代期间的并发修改
- 重构触发器逻辑以使用线程安全的快照创建
- 在计数器方法中添加同步保护
- 确保所有集合操作都在安全锁内执行
2026-03-19 12:51:59 +08:00
GeWuYou
b5c67850ce docs(localization): 更新本地化字符串类的XML文档注释
- 为构造函数添加更详细的参数描述和异常说明
- 为WithVariable方法添加完整的XML文档注释
- 为WithVariables方法添加完整的XML文档注释
- 为Format方法添加详细的返回值和备注信息
- 为GetRaw方法添加完整的XML文档注释
- 为Exists方法添加完整的XML文档注释
- 为私有FormatString方法添加参数和返回值说明
- 为私有FormatMatch方法添加详细的处理逻辑描述
- 为私有TryFormatValue方法添加格式化器相关参数说明
- 为私有FormatValue方法添加默认格式化逻辑说明
- 为私有GetOptionalGroupValue方法添加功能说明
- 为私有GetFormatter方法添加获取格式化器的详细描述
2026-03-19 09:20:43 +08:00
GeWuYou
1f680d2822 refactor(localization): 重构本地化字符串格式化逻辑
- 将 FormatVariablePattern 从 readonly 字段改为 const 常量
- 提取复杂的正则替换逻辑到独立的 FormatMatch 方法中
- 新增 GetOptionalGroupValue 辅助方法处理可选组值提取
- 分离格式化值和尝试格式化的逻辑到独立方法
- 简化条件判断并提高代码可读性
- 优化错误处理流程,保持原有功能不变
2026-03-19 09:19:34 +08:00
GeWuYou
075d397a4c refactor(localization): 更新集成测试中的命名空间引用
- 添加对 GFramework.Core.Abstractions.Localization 的引用
- 确保测试文件能够访问本地化相关的抽象接口
- 为后续的本地化功能扩展做好准备
- 保持代码结构的一致性与可维护性
2026-03-18 23:25:55 +08:00
GeWuYou
5fb96761a3 docs(localization): 更新本地化文档并完善功能实现
- 添加了配置项暂不支持的说明信息
- 扩展了语言变化监听的使用方式,增加命名方法订阅示例
- 完善了覆盖机制的文档说明
- 优化了异常处理逻辑,精确捕获本地化相关异常
- 实现了正则表达式的预编译以提升性能
- 添加了必要的命名空间引用
2026-03-18 23:25:09 +08:00
GeWuYou
e49713a842 feat(core): 添加本地化系统支持多语言功能
- 实现 ILocalizationManager 接口及 LocalizationManager 管理器
- 添加 ILocalizationTable 和 ILocalizationString 接口及其实现
- 创建 LocalizationConfig 配置类用于管理本地化行为
- 实现 ConditionalFormatter 和 PluralFormatter 内置格式化器
- 添加本地化文档包括 API 参考和使用指南
- 集成本地化系统到核心框架架构中
2026-03-18 22:58:07 +08:00
gewuyou
aee13c3c1d
Merge pull request #114 from GeWuYou/docs/add-claude-md-guide
docs(guide): 添加 CLAUDE.md 文件提供项目开发指导
2026-03-18 10:00:28 +08:00
GeWuYou
05c4f06717 docs(guide): 添加 CLAUDE.md 文件提供项目开发指导
- 新增项目概述说明,介绍 GFramework 框架的核心特性
- 添加构建和测试命令指南,包括 dotnet 构建和测试脚本
- 提供模块依赖关系图,说明各模块之间的依赖结构
- 详细描述架构模式,包括四层结构和关键设计模式
- 添加代码约定说明,涵盖命名空间、隐式引用等规范
- 补充测试框架信息,说明测试结构和基类使用方式
- 介绍源码生成器功能,列出四个主要生成器的作用
- 提供文档站点信息,说明 VitePress 文档的本地预览方法
2026-03-18 09:44:06 +08:00
gewuyou
2accbf4bdf
Merge pull request #113 from GeWuYou/refactor/router-base-ci-concurrency
refactor(game): 重构路由系统并优化CI测试流程
2026-03-17 16:45:05 +08:00
GeWuYou
60068aff4f refactor(ci): 重构工作流配置以分离代码质量和构建测试任务
- 将原有的 test job 重命名为 code-quality,专注于代码质量与安全检查
- 添加构建和测试独立的 build-and-test job,实现并行执行
- 更新 MegaLinter 配置,优化缓存和报告上传流程
- 重新组织 CI 工作流结构,提升执行效率和可维护性
- 调整作业名称和描述,明确职责分工
2026-03-17 16:34:09 +08:00
GeWuYou
9c69c4ec00 refactor(ci): 优化CI工作流中的测试执行策略
- 将多个独立的测试步骤合并为单个并发执行步骤
- 移除重复的测试配置以简化工作流定义
- 保留后台测试等待机制确保执行完整性
- 统一测试项目名称提高可读性
2026-03-17 16:20:55 +08:00
GeWuYou
65b949b62f perf(scene): 优化路由守卫异步方法性能
- 将 ISceneRouteGuard 中的 Task 返回类型改为 ValueTask
- 将 IUiRouteGuard 中的 Task 返回类型改为 ValueTask
- 移除注释中的多余缩进空格
- 提升异步操作的性能表现
2026-03-17 16:10:24 +08:00
GeWuYou
4afa856fdc refactor(game): 重构路由系统并优化CI测试流程
- 将SceneRouterBase和UiRouterBase继承自新的RouterBase基类
- 移除原有的守卫管理相关代码,统一使用基类实现
- 更新路由栈操作使用基类提供的Stack属性
- 重写Current、Contains等方法以使用基类实现
- 在CI工作流中启用并发测试执行以提升性能
- 添加等待步骤确保并发测试完成
- 更新项目文件排除测试项目的编译
- 在解决方案文件中添加GFramework.Game.Tests项目引用
- 新增RouterBase基类提供通用路由管理功能
2026-03-17 15:01:55 +08:00
gewuyou
27858df94e
Merge pull request #112 from GeWuYou/refactor/architecture-modular-safety
refactor(architecture): 重构架构类为模块化设计提升代码安全性
2026-03-17 12:56:34 +08:00
GeWuYou
1c2e68fc5a style(docs): 统一文档中IoC容器术语格式并优化架构生命周期代码
- 将文档中的"IOC"统一更正为"IoC"格式
- 重构ArchitectureLifecycle类构造函数使用主构造函数语法
- 移除私有字段前缀下划线,直接使用参数名称
- 修复配置访问权限问题,移除字段访问前缀下划线
- 调整组件注册方法泛型约束,提升类型安全
- 优化日志记录器访问方式,移除字段访问前缀下划线
- 重构销毁逻辑,分离组件清理和服务模块销毁流程
- 提取清理组件逻辑到独立方法,提升代码可读性
- 更新阶段转换和钩子通知中的对象引用方式
2026-03-17 12:50:43 +08:00
GeWuYou
3d8e19b5e2 refactor(architecture): 重构架构类为模块化设计提升代码安全性
- 将单一 Architecture 类拆分为 ArchitectureLifecycle、ArchitectureComponentRegistry 和 ArchitectureModules
- 消除 3 处 null! 强制断言,在构造函数中初始化管理器提高代码安全性
- 添加 PhaseChanged 事件支持架构阶段监听
- 所有公共 API 保持不变确保向后兼容
- 实现单一职责原则使代码更易维护和测试
- 组件注册、生命周期管理和模块管理职责分离到专门的管理器中
2026-03-17 11:08:48 +08:00
gewuyou
ef05713bf2
Merge pull request #111 from GeWuYou/refactor/architecture-to-architectures-namespace
Refactor/architecture to architectures namespace
2026-03-14 17:01:31 +08:00
GeWuYou
e022a10bd5 refactor(architecture): 将架构相关文件从 Architecture 目录移动到 Architectures 目录
- 重命名目录名称从 Architecture 到 Architectures
- 更新所有相关文件的命名空间声明
- 保持代码功能不变,仅调整目录结构和命名空间一致性
2026-03-14 16:54:07 +08:00
GeWuYou
c82a15f8bc refactor(abstractions): 将Architecture命名空间重命名为Architectures
- 更新所有引用GFramework.Core.Abstractions.Architecture的文件
- 将ArchitectureModuleRegistry.cs从Architecture目录移动到Architectures目录
- 将IArchitecture.cs从Architecture目录移动到Architectures目录
- 将IArchitectureConfiguration.cs从Architecture目录移动到Architectures目录
- 将IArchitectureContext.cs从Architecture目录移动到Architectures目录
- 将IArchitectureContextProvider.cs从Architecture目录移动到Architectures目录
- 将IArchitectureLifecycleHook.cs从Architecture目录移动到Architectures目录
- 将IArchitectureModule.cs从Architecture目录移动到Architectures目录
- 将IArchitecturePhaseListener.cs从Architecture目录移动到Architectures目录
- 将IArchitectureServices.cs从Architecture目录移动到Architectures目录
- 将IServiceModule.cs从Architecture目录移动到Architectures目录
- 将IServiceModuleManager.cs从Architecture目录移动到Architectures目录
- 在ArchitectureModuleRegistry中将私有字段_factories重命名为Factories并添加StringComparer.Ordinal参数
2026-03-14 16:52:28 +08:00
gewuyou
2d89efa4b7
Merge pull request #110 from GeWuYou/docs/remove-migration-guide
Docs/remove migration guide
2026-03-13 22:44:29 +08:00
GeWuYou
597d4dfeda docs(menu): 移除迁移指南菜单项
- 从中文导航菜单中删除迁移指南链接
- 更新配置文件中的菜单结构
2026-03-13 22:44:01 +08:00
GeWuYou
f3deb299ac docs: 移除版本迁移指南文档
- 删除了整个迁移指南文档文件 docs/zh-CN/migration-guide.md
- 移除了详细的从 0.x 到 1.x 版本迁移说明
- 删除了架构变更、API 变更和配置变更相关内容
- 清理了常见问题解答和回滚方案部分
- 移除了测试迁移和代码迁移工具介绍
2026-03-13 22:43:28 +08:00
gewuyou
fc2f9ebf1a
Merge pull request #109 from GeWuYou/chore/resharper-namespace-suppression
chore(abstractions): 添加 ReSharper 禁用检查命名空间注释
2026-03-13 22:36:58 +08:00
GeWuYou
0640a06e44 chore(abstractions): 添加 ReSharper 禁用检查命名空间注释
- 在 GFramework.Core.Abstractions 中添加 // ReSharper disable CheckNamespace 注释
- 在 GFramework.Game.Abstractions 中添加 // ReSharper disable CheckNamespace 注释
- 解决代码分析工具对命名空间检查的警告问题
2026-03-13 22:29:29 +08:00
gewuyou
94f75bfa03
Merge pull request #108 from GeWuYou/chore/cleanup-refactor-scripts
chore(build): 删除文件夹映射配置和命名空间更新脚本
2026-03-13 10:03:24 +08:00
GeWuYou
10640f1c73 refactor(scripts): 将 C# 命名验证脚本从 Python 重写为 Bash
- 将验证逻辑从 Python 代码转换为 Bash 脚本实现
- 使用 grep 和正则表达式替换 Python 的字符串匹配功能
- 实现 PascalCase 验证的正则表达式模式
- 添加目录路径和命名空间段的验证逻辑
- 保持原有的排除规则和错误报告格式
- 移除对 Python3 的依赖,仅使用系统内置命令
2026-03-13 09:53:50 +08:00
GeWuYou
cb0d0682b0 refactor(core): 统一C#命名规范并添加校验脚本
- 将所有IoC相关命名空间从"IoC"重命名为"Ioc"
- 将所有CQRS相关命名空间从"CQRS"重命名为"Cqrs"
- 更新所有受影响的using语句以匹配新的命名空间
- 在CI工作流中添加C#命名规范校验步骤
- 修正了测试文件中的命名空间引用
2026-03-13 09:41:43 +08:00
GeWuYou
8b5efc69ec chore(build): 删除文件夹映射配置和命名空间更新脚本
- 移除 folder-mappings.json 配置文件
- 删除 update-namespaces.sh 自动化脚本
- 清理项目中的文件夹重命名映射关系
- 移除自动生成命名空间更新的功能
- 完成代码库结构规范化清理工作
2026-03-12 21:35:50 +08:00
dependabot[bot]
54103c21a4 chore(deps): bump trufflesecurity/trufflehog from 3.93.7 to 3.93.8
Bumps [trufflesecurity/trufflehog](https://github.com/trufflesecurity/trufflehog) from 3.93.7 to 3.93.8.
- [Release notes](https://github.com/trufflesecurity/trufflehog/releases)
- [Commits](https://github.com/trufflesecurity/trufflehog/compare/v3.93.7...v3.93.8)

---
updated-dependencies:
- dependency-name: trufflesecurity/trufflehog
  dependency-version: 3.93.8
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-12 21:33:15 +08:00
dependabot[bot]
7aa009ab06 Bump coverlet.collector from 6.0.2 to 6.0.4
---
updated-dependencies:
- dependency-name: coverlet.collector
  dependency-version: 6.0.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-12 21:33:04 +08:00
dependabot[bot]
90bfa7200a Bump Meziantou.Analyzer from 2.0.264 to 2.0.302
---
updated-dependencies:
- dependency-name: Meziantou.Analyzer
  dependency-version: 2.0.302
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-12 21:32:51 +08:00
dependabot[bot]
e4cc0c7943 Bump Meziantou.Polyfill from 1.0.71 to 1.0.104
---
updated-dependencies:
- dependency-name: Meziantou.Polyfill
  dependency-version: 1.0.104
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-12 21:32:41 +08:00
dependabot[bot]
0b7d5c8f0c Bump Microsoft.Extensions.DependencyInjection from 10.0.3 to 10.0.4
---
updated-dependencies:
- dependency-name: Microsoft.Extensions.DependencyInjection
  dependency-version: 10.0.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-12 21:32:28 +08:00
dependabot[bot]
920a2c519e Bump NUnit from 4.5.0 to 4.5.1
---
updated-dependencies:
- dependency-name: NUnit
  dependency-version: 4.5.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: NUnit
  dependency-version: 4.5.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: NUnit
  dependency-version: 4.5.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-12 21:32:16 +08:00
gewuyou
f48a8db094
Merge pull request #99 from GeWuYou/docs/coroutine-system-refactor
Docs/coroutine system refactor
2026-03-12 12:58:51 +08:00
GeWuYou
4362989056 docs(coroutine): 更新协程相关文档
- 添加了 AsCoroutineInstruction()、ToCoroutineEnumerator() 和 StartTaskAsCoroutine()
  的使用场景说明
- 优化了等待异步方法的文档描述,明确不同 API 的适用场景
- 详细说明了 CancelWith 方法的节点有效性判断机制和停止条件
- 补充了 Godot 协程中 Task 转协程的具体使用建议
2026-03-12 12:49:29 +08:00
GeWuYou
1c30149ebd docs(coroutine): 更新协程系统文档内容
- 重新描述协程系统功能,强调基于 IEnumerator<IYieldInstruction> 的调度能力
- 更新核心概念介绍,明确协程系统的组成部分和架构设计
- 修改 CoroutineScheduler 使用示例,添加统计信息启用说明
- 完善 CoroutineHandle 的控制方法说明,包括暂停、恢复和终止操作
- 优化协程状态控制示例代码,展示标签和分组管理功能
- 重构等待指令说明,按时间帧、条件等待、Task桥接等方式分类
- 更新事件等待相关示例,改进超时处理和多事件等待功能
- 完善协程组合功能说明,包括子协程等待和多句柄等待
- 优化扩展方法介绍,按组合扩展、协程生成扩展、Task扩展等分类
- 更新命令、查询和Mediator扩展使用说明
- 修订异常处理机制说明,明确调度器异常处理方式
- 更新常见问题解答,澄清协程执行时机和线程模型概念
- 精简相关文档链接,移除冗余的系统集成说明
2026-03-12 12:41:53 +08:00
GeWuYou
4156839bd9 docs(godot): 更新协程系统文档内容
- 重构协程系统架构说明,明确核心组件和入口点
- 更新协程启动方式和基本用法示例代码
- 添加 Segment 分段调度机制详细说明
- 补充节点生命周期绑定和延迟调用功能介绍
- 完善常用等待指令和协程控制方法文档
- 优化事件总线集成和上下文感知集成说明
2026-03-12 12:41:22 +08:00
gewuyou
d038b67e29
Merge pull request #98 from GeWuYou/refactor/storage-async-safety
refactor(storage): 重构文件存储实现以支持异步安全锁和原子写入
2026-03-11 23:08:09 +08:00
GeWuYou
820cdcf0fa refactor(storage): 统一文件存储模块的依赖注入
- 在 FileStorage 中添加 System.IO 和 System.Text 引用
- 在 GodotFileStorage 中整合所有必要的命名空间引用
- 统一并发和序列化接口的依赖注入方式
- 添加 Godot 特定的 FileAccess 类型别名
- 优化 Godot 扩展功能的引用结构
2026-03-11 22:34:30 +08:00
GeWuYou
b01867b231 fix(storage): 修复文件存储组件的资源管理和死锁问题
- 添加了内部锁管理器所有权标识,防止外部传入的锁管理器被错误释放
- 在构造函数中正确初始化锁管理器的所有权状态
- 在Dispose方法中只释放内部创建的锁管理器,避免重复释放异常
- 为所有同步包装方法添加了ConfigureAwait(false)以避免死锁
- 更新了读取、写入、删除和检查存在的同步方法实现
- 为所有异步操作添加了适当的配置避免上下文切换问题
- 改进了Godot文件存储类的相同资源管理逻辑
- 为所有阻塞式同步方法添加了详细的XML注释警告说明
2026-03-11 22:26:01 +08:00
GeWuYou
494c341c08 refactor(storage): 重构文件存储实现以支持异步安全锁和原子写入
- 替换同步锁机制为异步键锁管理器,提升并发性能
- 实现原子写入功能,通过临时文件防止写入过程中的数据损坏
- 添加资源释放接口(IDisposable)和对象销毁检查
- 集成异步IO操作,包括缓冲区大小配置选项
- 更新Godot文件存储适配器以匹配新的异步安全机制
- 优化文件读取操作,支持异步文本读取避免阻塞
- 移除旧的并发字典锁实现,统一使用新的锁管理器
2026-03-11 21:57:04 +08:00
gewuyou
9c2e63f0e1
Merge pull request #96 from GeWuYou/feat/concurrency-add-async-key-lock-manager
feat(concurrency): 添加工业级异步键锁管理器
2026-03-11 19:41:07 +08:00
GeWuYou
378d7afb23 fix(concurrency): 修复异步锁管理器中的超时单位错误和资源泄漏问题
- 修正 _lockTimeoutTicks 为 _lockTimeoutMs,统一使用毫秒作为时间单位
- 在 AcquireLockAsync 方法中添加异常处理,防止锁等待失败时的资源泄漏
- 为同步 AcquireLock 方法添加 ConfigureAwait(false) 避免死锁风险
- 更新锁统计信息中的 WaitingCount 字段为近似值说明
- 修正清理逻辑中使用正确的超时单位进行比较
2026-03-11 19:17:03 +08:00
gewuyou
00a687168f
Merge pull request #97 from GeWuYou/refactor/scoped-array-optimization
refactor(core): 优化ScopedArray结构体实现
2026-03-11 12:53:44 +08:00
GeWuYou
b6c13088cd refactor(GFramework.Core): 移除ScopedArray的IDisposable接口实现
- 从ScopedArray结构体中移除IDisposable接口
- 保留数组池管理和自动释放功能
- 简化类型定义以提高性能表现
2026-03-11 12:44:32 +08:00
GeWuYou
ea79df232b refactor(GFramework.Core): 优化ScopedArray实现并添加资源清理功能
- 为ScopedArray<T>实现IDisposable接口以支持资源清理
- 修改Array属性访问方式,通过GetArray方法确保对象未被释放
- 更新Length属性实现,依赖Array属性而非直接访问私有字段
- 调整AsSpan方法实现,统一通过Array属性获取数组实例
- 重写索引器实现,使用Array属性替代直接字段访问
- 新增GetArray私有方法,用于检查对象状态并返回内部数组
- 添加ObjectDisposedException异常处理,防止访问已释放对象
2026-03-11 12:34:08 +08:00
GeWuYou
ffda10be86 refactor(core): 优化ScopedArray结构体实现
- 将ScopedArray从readonly struct改为ref struct以提高性能
- 添加_array字段存储数组引用并移除公共Array属性
- 在Dispose方法中添加空值检查避免重复释放
- 添加Span属性和索引器支持直接访问数组元素
- 使用#pragma warning禁用CA1819警告并优化代码风格
2026-03-11 08:58:33 +08:00
GeWuYou
b37873a67c feat(concurrency): 添加工业级异步键锁管理器
- 实现了基于键的细粒度异步锁机制
- 提供自动清理未使用锁的功能,避免内存泄漏
- 集成了统计信息收集功能,便于监控和调试
- 支持同步和异步两种锁获取方式
- 实现了锁句柄的自动释放机制
- 添加了完整的单元测试覆盖各种并发场景
2026-03-10 23:11:35 +08:00
gewuyou
11c7bc1457
Merge pull request #93 from GeWuYou/feat/result-add-try-map-bind-methods
feat(Result): 扩展Result结构体功能并优化实现
2026-03-10 21:16:41 +08:00
GeWuYou
c6024bf94a feat(GFramework.Core.Functional.Result): 增强Result类的安全性和健壮性
- 在构造函数中添加强制不变式检查,确保失败状态必须携带非空异常
- 为Try方法添加空值验证,防止传入空委托导致异常
- 为Map方法添加空值验证,增强方法调用的安全性
- 为Bind方法添加空值验证,提升代码健壮性
- 重构Map和Bind方法结构,使其更清晰易读
2026-03-10 21:09:58 +08:00
gewuyou
248a29b4df
Merge pull request #92 from GeWuYou/deepsource-autofix-834b3193
refactor: use ternary operator for conditional assignments
2026-03-10 20:25:35 +08:00
gewuyou
1f0eb55288
Merge pull request #94 from GeWuYou/refactor/pool-simplify-warning-messages
refactor(pool): 简化对象池释放警告消息
2026-03-10 20:24:58 +08:00
deepsource-autofix[bot]
caeb1ab80f
refactor: use ternary operator for conditional assignments
This PR refactors code that used multi-line if/else statements to use the ternary operator for more concise and readable assignments.

- if statement can be rewritten using the ternary operator: The original code assigned values based on Storage.ExistsAsync(key) with separate if and else blocks, leading to verbose multi-line statements. We have replaced these with single-line ternary expressions in both the generic GetAsync<T> method and the UnifiedSettingsFile loader, reducing code duplication and improving clarity.

> This Autofix was generated by AI. Please review the change before merging.
2026-03-10 11:21:39 +00:00
GeWuYou
4750910675 feat(Result): 扩展Result结构体功能并优化实现
- 添加StructLayout特性优化内存布局
- 将Failure方法中的Exception替换为InvalidOperationException
- 重构Equals方法提高比较逻辑的可读性
- 简化GetHashCode方法的哈希计算逻辑
- 更新ToString方法移除空值检查
- 新增Try方法用于安全执行可能抛出异常的操作
- 添加Map方法支持将Result成功状态映射到其他类型
- 实现Bind方法用于链式调用Result操作
2026-03-10 19:20:52 +08:00
GeWuYou
43b88e7573 refactor(pool): 简化对象池释放警告消息
- 移除冗余的 'Attempting to release object for key' 文本
- 删除重复的 'or incorrect key' 描述
- 简化警告消息以提高可读性
- 保持核心警告信息不变
2026-03-10 19:13:39 +08:00
gewuyou
8e4e794661
Merge pull request #91 from GeWuYou/refactor/namespace-pascalcase
Refactor/namespace pascalcase
2026-03-10 19:07:33 +08:00
GeWuYou
52f95c7e5f refactor(tests): 将Architecture目录重命名为Architectures
- 重命名GFramework.Core.Tests/Architecture目录为GFramework.Core.Tests/Architectures
- 更新所有相关文件中的命名空间引用
- 修复GameContextTests中TestArchitecture类的基类引用
- 修复TestArchitectureBase类的基类引用
- 修复ArchitectureTestsBase泛型约束中的类型引用
- 更新其他测试文件中的命名空间导入路径
2026-03-10 19:01:50 +08:00
GeWuYou
8ea462de28 test(architecture): 更新架构上下文测试以验证未注册组件抛出异常
- 修改 GetSystem 方法测试用例,验证未注册系统时抛出 InvalidOperationException
- 修改 GetModel 方法测试用例,验证未注册模型时抛出 InvalidOperationException
- 修改 GetUtility 方法测试用例,验证未注册工具时抛出 InvalidOperationException
- 更新异步架构测试中的系统销毁验证逻辑
- 移除对已销毁系统的空值检查断言,改为验证异步测试系统的销毁状态
2026-03-10 10:16:04 +08:00
GeWuYou
95de78efae refactor(architecture): 优化架构上下文中的服务缓存和空值处理
- 将服务缓存从 Dictionary 替换为 ConcurrentDictionary 以提高线程安全性
- 移除所有 GetService 相关方法的可空返回类型,统一改为非空返回
- 修改 GetOrCache 方法实现,使用 GetOrAdd 方法简化缓存逻辑
- 更新命令和事件总线调用方式,移除空值检查操作符
- 调整接口契约,明确服务不存在时抛出异常而非返回 null
- 优化依赖注入容器的服务获取流程,增强错误处理机制
2026-03-10 09:08:13 +08:00
GeWuYou
aeed1f903c refactor(GFramework.Ecs.Arch): 移除未使用的抽象依赖
- 从 ArchEcsModule.cs 中移除未使用的 GFramework.Ecs.Arch.Abstractions 引用
- 清理项目中不必要的命名空间引用以优化代码结构
2026-03-10 08:48:35 +08:00
GeWuYou
027a214479 refactor(core): 将System命名空间重命名为Systems
- 更新所有GFramework.Core.Abstractions.System引用为GFramework.Core.Abstractions.Systems
- 重命名GFramework.Core/System目录为GFramework.Core/Systems
- 重命名GFramework.Core.Tests/System目录为GFramework.Core.Tests/Systems
- 更新所有相关using语句和命名空间声明
- 修复测试文件中的命名空间引用
- 添加全局using引用GFramework.Core.Systems
2026-03-10 08:42:53 +08:00
GeWuYou
fb14d7122c docs(style): 更新文档中的命名空间导入格式
- 将所有小写的命名空间导入更正为首字母大写格式
- 统一 GFramework 框架的命名空间引用规范
- 修复 core、ecs、godot 等模块的命名空间导入错误
- 标准化文档示例代码中的 using 语句格式
- 确保所有文档中的命名空间引用保持一致性
- 更新 global using 语句以匹配正确的命名空间格式
2026-03-10 07:18:49 +08:00
gewuyou
53b04c12f0
Merge pull request #90 from GeWuYou/docs/ecs-documentation-improvements-
docs(ecs): 更新文档中的类型参数表示和相关链接
2026-03-08 21:54:44 +08:00
GeWuYou
f5d1985a59 docs(ecs): 更新文档中的类型参数表示和相关链接
- 将文档中的 `ArchSystemAdapter<T>` 替换为 `ArchSystemAdapter&lt;T&gt;` 以正确显示尖括号
- 移除重复的许可证信息和分隔线
- 删除过时的文档链接,保持导航结构简洁
2026-03-08 21:37:37 +08:00
gewuyou
05d7557fa1
Merge pull request #89 from GeWuYou/refactor/extract-ecs-to-independent-module
Refactor/extract ecs to independent module
2026-03-08 21:27:34 +08:00
GeWuYou
f771b7dbef chore(ci): 添加 GFramework.Ecs.Arch.Tests 测试步骤
- 为 CI 工作流添加新的测试步骤
- 配置 GFramework.Ecs.Arch.Tests 的测试运行命令
- 设置测试结果输出目录为 TestResults
- 使用 trx 格式记录测试日志文件
- 保持与现有测试配置一致的结构和格式
2026-03-08 21:01:13 +08:00
GeWuYou
f35c9309f3 docs(menu): 重构 ECS 文档导航结构
- 将 ECS 相关菜单项从 Core 部分独立出来
- 新增 ECS 概述页面和 Arch ECS 集成文档
- 删除旧的 Core/ECS 集成文档文件
- 更新侧边栏配置以支持新的 ECS 导航结构
2026-03-08 20:55:03 +08:00
GeWuYou
5c5525e3e9 refactor(architecture): 简化模块注册接口并增强配置管理
- 移除 RegisterBuiltInModules 方法中的 ArchitectureProperties 参数
- 更新 ArchitectureModuleRegistry 使用 ConcurrentDictionary 存储模块工厂
- 实现模块注册的幂等性检查,相同模块名只注册一次
- 为 ArchEcsModule 添加 ArchOptions 配置类支持
- 更新 UseArch 扩展方法传递配置选项给 ArchEcsModule
- 移除废弃的 properties 命名空间引用
- 添加显式注册集成测试验证模块配置功能
2026-03-08 20:47:26 +08:00
GeWuYou
ac2a9759e1 refactor(ArchEcsModule): 优化系统适配器管理
- 将 _systems 字段类型从 List 改为 IReadOnlyList
- 使用 GetAllByPriority 方法按优先级获取适配器
- 移除手动 AddRange 操作,直接赋值适配器列表
- 销毁时将 _systems 设置为空数组而非 Clear() 操作
2026-03-08 20:38:12 +08:00
GeWuYou
4257d58f86 feat(GFramework.Ecs.Arch): 注册模块自身到容器中
- 在 ArchEcsModule 初始化时注册模块自身到容器
- 移除不必要的空行以保持代码整洁
2026-03-08 20:33:00 +08:00
GeWuYou
bca92e52a3 refactor(ecs): 重构 Arch ECS 模块注册机制
- 移除自动初始化器,改用显式注册方式
- 修改 UseArch 扩展方法支持可选配置参数
- 更新文档说明新的集成方式和配置选项
- 删除自动注册相关的测试代码
- 调整 README 中的使用示例和架构说明
2026-03-08 20:19:24 +08:00
GeWuYou
af76e0ab0b refactor(ecs): 移除Arch ECS模块及相关组件和系统
- 删除Position组件结构体定义
- 删除Velocity组件结构体定义
- 删除MovementSystem移动系统实现
- 移除ArchEcsModule ECS模块管理器
- 删除ArchSystemAdapter适配器基类
- 从ServiceModuleManager中移除ECS模块注册逻辑
- 从ArchitectureProperties中移除EnableEcs配置选项
- 删除ECS相关的单元测试文件
- 从项目文件中移除Arch和Arch.System包引用
- 从解决方案文件中移除ECS相关项目引用
- 更新项目配置文件中的目标框架和测试项目属性
2026-03-08 19:45:36 +08:00
gewuyou
23f186d395
Merge pull request #88 from GeWuYou/refactor/controllers-to-context-aware-architecture-access
refactor(docs): 修正文档中关于IController的描述
2026-03-08 11:39:51 +08:00
GeWuYou
25f7779b4e refactor(docs): 将 Context 属性访问替换为扩展方法访问
- 将 Context.GetModel<T>() 调用替换为 this.GetModel<T>()
- 将 Context.GetSystem<T>() 调用替换为 this.GetSystem<T>()
- 将 Context.GetUtility<T>() 调用替换为 this.GetUtility<T>()
- 将 Context.SendCommand() 调用替换为 this.SendCommand()
- 将 Context.SendQuery() 调用替换为 this.SendQuery()
- 将 Context.SendEvent() 调用替换为 this.SendEvent()
- 将 Context.RegisterEvent<T>() 调用替换为 this.RegisterEvent<T>()
2026-03-08 11:37:31 +08:00
GeWuYou
1b9e81bbdb refactor(docs): 将控制器实现转换为上下文感知模式
- 将 IController 实现改为使用 [ContextAware] 特性和 partial 类
- 移除手动实现的 GetArchitecture 方法
- 将架构交互方法从 this 调用改为 Context 调用
- 添加必要的 using 语句以支持新的架构访问方式
- 更新所有涉及模型、系统、工具和事件的架构访问代码
- 统一架构访问模式以提高代码一致性和可维护性
2026-03-08 11:03:02 +08:00
gewuyou
5190b7a463
Merge pull request #87 from GeWuYou/docs/technical-documentation-update
docs(config): 更新文档导航结构并添加新章节
2026-03-07 23:37:01 +08:00
GeWuYou
0d20a28385 fix(docs): 修正 API 参考链接路径并移除重复侧边栏配置
- 修正了 API 参考链接路径,移除了末尾多余的斜杠
- 移除了重复的 API 参考侧边栏配置项
- 确保导航链接的一致性和正确性
2026-03-07 23:34:11 +08:00
GeWuYou
eaa59c03c3 docs(config): 更新文档导航结构并添加新章节
- 添加最佳实践导航菜单和相关页面链接
- 在核心模块侧边栏增加生命周期、CQRS模式、协程系统等新条目
- 为游戏模块添加数据管理、场景系统、UI系统等功能链接
- 在Godot集成部分新增暂停系统、对象池和日志系统文档
- 将规则生成器重命名为ContextAware生成器
- 在教程部分增加暂停系统实践、数据迁移和单元测试等内容
- 新增API参考、常见问题、故障排查等文档分类
- 为最佳实践页面配置详细的子菜单项
2026-03-07 23:30:15 +08:00
gewuyou
8a070af51b
Merge pull request #86 from GeWuYou/docs/technical-documentation-update
docs(guide): 添加 ContextAware 生成器文档并更新相关链接
2026-03-07 23:15:06 +08:00
GeWuYou
740cc66ac4 docs: 更新源生成器文档并调整配置
- 移除 .claude 设置文件
- 重构枚举扩展生成器文档,更新 API 使用方式和配置选项
- 调整日志生成器文档,更新属性使用方式和配置参数
- 修改 Git 忽略规则添加 .claude/settings.json
- 更新代码示例和最佳实践指南
2026-03-07 23:13:21 +08:00
GeWuYou
4804b75215 test(PlayerController): 将测试方法转换为异步任务
- 将 TestPlayerController 方法从同步改为异步
- 使用 Task 类型替代 void 返回类型
- 为测试方法添加 async 关键字修饰符
2026-03-07 22:56:58 +08:00
GeWuYou
3dce243bcd docs(source-generators): 修复上下文感知生成器文档中的错别字和链接
- 修复了代码注释中的错别字"生命期"为"生命周期"
- 移除了文档末尾的规则验证生成器链接引用
2026-03-07 22:55:37 +08:00
GeWuYou
6d398a515b docs(guide): 添加 ContextAware 生成器文档并更新相关链接
- 新增 ContextAware 生成器完整文档,介绍自动实现 IContextAware 接口的功能
- 更新索引页面中的相关链接,替换规则生成器为 ContextAware 生成器
- 修改基础使用示例中的命名空间引用和代码实现细节
- 补充测试场景配置和多架构场景的使用说明
- 添加最佳实践和诊断信息相关内容
2026-03-07 22:51:42 +08:00
gewuyou
575dcdf27b
Merge pull request #85 from GeWuYou/docs/technical-documentation-update
docs(guidelines): 更新错误处理和移动端优化最佳实践
2026-03-07 22:12:35 +08:00
GeWuYou
28ad02dc80 docs(best-practices): 更新移动端优化代码示例
- 添加了图形 API 和多线程渲染的配置说明
- 增加了运行时可调整的性能设置选项
- 优化了纹理质量和阴影设置参数
- 添加了目标帧率和 VSync 配置
- 实现了基于设备性能的质量等级自动调整
- 改进了垃圾回收优化策略和相关注释说明
- 添加了设备性能检测的辅助方法
2026-03-07 22:10:14 +08:00
GeWuYou
8554f01423 docs(guidelines): 更新错误处理和移动端优化最佳实践
- 添加完整的错误处理最佳实践指南,涵盖Result<T>和Option<T>使用方式
- 补充移动端性能优化策略,包括纹理压缩、对象池、内存管理和电池优化
- 更新单元测试教程中的相关文档链接
- 完善错误处理层次结构和测试示例代码
- 增加移动端UI优化和平台适配最佳实践
2026-03-07 22:05:48 +08:00
gewuyou
519e3a480b
Merge pull request #84 from GeWuYou/docs/technical-documentation-update
Docs/technical documentation update
2026-03-07 17:45:19 +08:00
GeWuYou
9edf64193f docs(architecture): 更新架构设计模式指南文档
- 将标题从"架构模式最佳实践"改为"架构设计模式指南"
- 添加全面的架构设计模式介绍和概述
- 新增MVC模式详细说明,包括概念、GFramework实现示例和最佳实践
- 新增MVVM模式详细说明,包括概念、GFramework实现示例和最佳实践
- 新增命令模式详细说明,包括概念、实现示例和撤销功能支持
- 新增查询模式详细说明,包括CQRS概念和复杂查询示例
- 新增事件驱动模式详细说明,包括事件定义和监听实现
- 新增依赖注入模式详细说明,包括构造函数注入示例
- 新增服务定位器模式详细说明,包括与依赖注入对比
- 新增对象池模式详细说明,包括通用对象池实现
- 新增状态模式详细说明,包括异步状态和状态机系统
- 补充模式选择与组合建议,针对小型、中型、大型项目提供不同方案
- 更新代码示例中的泛型语法格式,统一使用尖括号表示法
2026-03-07 17:32:26 +08:00
GeWuYou
739565d278 chore(build): 更新.gitignore配置以忽略AI相关和文档构建缓存文件
- 添加ai相关目录到忽略列表
- 忽略.omc/目录及其内容
- 忽略docs/.omc/目录
- 忽略docs/.vitepress/cache/目录
- 移除已删除的依赖文件和缓存文件
2026-03-07 17:12:11 +08:00
GeWuYou
a021941cab docs(guidelines): 添加文档编写规范和配置设置
- 创建 DOCUMENTATION_STANDARDS.md 文件定义 Markdown 语法规范
- 添加泛型标记转义规则和 HTML 标签转义说明
- 提供内部链接验证规则和已存在文档路径列表
- 定义代码块规范和 Frontmatter 规范
- 添加文档结构规范和验证清单
- 配置 .claude/settings.json 启用 oh-my-claudecode 插件
2026-03-07 15:52:08 +08:00
GeWuYou
c969a9a022 docs(core): 修复文档中的泛型符号显示问题
- 修复了配置模块文档中 GetConfig、SetConfig、WatchConfig 方法的泛型符号
- 修复了 ECS 模块文档中 ArchSystemAdapter 的泛型符号显示
- 修复了函数式编程文档中 Option 和 Result 类型的泛型符号
- 修复了序列化和存储模块中各类方法的泛型符号显示
- 修正了存储模块文档中的序列化系统链接路径
- 修复了函数式编程教程中 Option 和 Result 的泛型符号显示
2026-03-07 15:51:47 +08:00
GeWuYou
84d7408bef docs(tutorials): 添加系统实现教程并完善核心组件文档
- 新增协程系统、状态机、暂停系统、资源管理和存档系统教程
- 添加 Configuration 包详细使用说明文档
- 创建 ECS 系统集成指南,介绍 Arch.Core 集成方案
- 提供完整的组件定义、系统创建和实体管理示例
- 包含性能优化建议和最佳实践指导
2026-03-07 15:44:34 +08:00
GeWuYou
b4ef62c731 docs: 更新文档链接和相关资源引用
- 修改 resource.md 中 Godot 资源仓储链接为 Godot 扩展
- 更新 data.md 中相关文档链接,将存储和序列化系统替换为设置系统和 Godot 集成
- 将多个教程文档中的架构概览链接替换为快速开始链接
- 调整 save-system.md 中的相关文档列表,更新数据迁移和系统依赖链接
- 为 bun.lock 添加 configVersion 字段
2026-03-07 14:00:35 +08:00
GeWuYou
b3838ce8c7 docs(godot): 添加 Godot 架构集成和场景系统文档
- 新增 Godot 架构集成文档,介绍 AbstractArchitecture 和 ArchitectureAnchor
- 添加 Godot 场景系统文档,涵盖 SceneBehavior 和场景生命周期管理
- 包含数据与存档系统文档,介绍 IDataRepository 和 ISaveRepository 接口
- 提供完整的代码示例和最佳实践指南
- 覆盖多架构支持、热重载和场景参数传递等高级功能
- 包含常见问题解答和相关文档链接
2026-03-07 13:02:19 +08:00
gewuyou
23f70a6e5a
Merge pull request #83 from GeWuYou/feat/events-enhanced-bus
引入增强版事件总线,支持可过滤事件与弱事件,并可选地对事件发布与处理进行统计。

新特性:

新增 EnhancedEventBus,支持标准、优先级、可过滤和弱事件的发布与订阅,并提供可选的统计功能。
引入可过滤事件,支持可插拔的 IEventFilter 实现,包括基于谓词的过滤器和采样过滤器。
新增事件统计抽象及实现,用于跟踪发布/处理/失败计数和监听器指标,并支持生成统计报告。
测试:

新增全面的单元测试覆盖弱事件行为,包括与 GC 的交互、清理、注销以及与统计功能的集成。
新增基于谓词和采样事件过滤器的测试,包括多个过滤器、移除/清空行为以及对无效配置的校验。
新增事件统计测试,用于验证计数器、按事件类型的指标、重置行为、报告输出以及线程安全性。
2026-03-06 17:04:22 +08:00
GeWuYou
c5bd08acfd fix(events): 修正优先级事件触发传播行为
- 将优先级事件的传播模式从 Continue 修改为 All
- 确保事件能够正确传递到所有监听器
2026-03-06 16:58:27 +08:00
GeWuYou
5ef464c484 feat(event): 添加事件统计功能和优化性能
- 在EasyEventGeneric中添加GetListenerCount方法获取监听器数量
- 重新排列EnhancedEventBus中字段顺序以优化内存布局
- 为所有Send方法添加发布统计记录功能
- 实现事件处理器包装以添加统计功能,包括成功处理和失败记录
- 添加监听器数量统计更新机制,自动跟踪注册和注销事件
- 重构FilterableEvent中的过滤逻辑以减少锁持有时间
- 在PriorityEvent中添加GetListenerCount方法获取总监听器数量
- 移除EventStatistics中的过时字段并优化ActiveEventTypes和ActiveListeners计算
- 清理StatisticsEventDecorator中的并发问题和实现装饰器模式
2026-03-06 16:40:54 +08:00
GeWuYou
e738e59a58 feat(events): 添加增强事件总线支持过滤器和统计功能
- 实现 EnhancedEventBus 支持过滤器、弱引用事件和统计功能
- 添加 FilterableEvent 和 WeakEvent 支持事件过滤和弱引用订阅
- 实现 PredicateEventFilter 和 SamplingEventFilter 事件过滤器
- 添加 EventStatistics 统计事件发布、处理和失败次数
- 实现完整的单元测试验证过滤器和统计功能
2026-03-06 16:09:40 +08:00
gewuyou
1b92bda8ba
Merge pull request #82 from GeWuYou/feat/coroutine-enhancements
为调度器新增协程分组、优先级与统计能力,以及相应的抽象与测试。

New Features:

引入协程优先级等级,并在调度器中按优先级顺序执行协程。
添加协程分组支持,用于批量暂停、恢复、终止以及计数操作。
提供协程统计接口及实现,用于跟踪数量、执行时间指标以及按优先级/标签划分的数据,并可在调度器上按需启用。
暴露一个可控的 FakeTimeSource 实现,用于驱动可确定性的协程测试。
Enhancements:

扩展协程元数据和槽位以存储优先级、分组信息以及开始时间戳,并相应更新调度器生命周期处理逻辑。
Tests:

添加单元测试,覆盖协程统计行为与报告、分组管理操作以及基于优先级的执行顺序。
2026-03-06 13:13:54 +08:00
GeWuYou
e5bd972ee7 fix(coroutine): 修复协程调度器中的潜在异常问题
- 在KillByTag方法中创建句柄数组副本以避免集合被修改的异常
- 修复Complete方法的缩进格式问题
- 为WaitCommandSwitch添加默认分支以处理未知类型的等待指令
2026-03-06 13:07:18 +08:00
GeWuYou
74f27ddfd5 refactor(coroutine): 优化协程调度器中的暂停计数统计
- 引入 _pausedCount 字段直接跟踪暂停协程数量
- 将统计信息中的 ActiveCount 和 PausedCount 改为线程安全的原子操作
- 在暂停和恢复协程时直接更新 _pausedCount 计数
- 修复 KillGroup 方法中的并发修改异常问题
- 重置统计信息时使用原子操作清零计数字段
2026-03-06 12:59:05 +08:00
GeWuYou
06114db8bd refactor(coroutine): 修改协程优先级枚举的基础类型
- 将 CoroutinePriority 枚举的基础类型从 byte 移除
- 优化枚举类型的定义方式
2026-03-06 12:36:50 +08:00
GeWuYou
e5e3a1c0ca feat(coroutine): 添加协程分组管理和优先级支持
- 实现协程分组功能,支持批量暂停、恢复和终止协程
- 添加协程优先级系统,支持从最低到最高的5个优先级级别
- 引入协程统计功能,跟踪启动、完成、失败数量及执行时间
- 添加FakeTimeSource用于协程测试的时间控制
- 实现按优先级排序的协程执行机制
- 添加协程执行时间戳记录功能
- 实现完整的协程统计报告生成功能
2026-03-06 12:34:12 +08:00
GeWuYou
16d8cad4f3 refactor(ioc): 优化依赖注入容器的优先级排序实现
- 修改 MicrosoftDiContainer 中 GetAllByPriority 方法的排序逻辑,使用 OrderBy 确保稳定排序
- 修正注释中的中文描述,明确优先级排序规则
- 将 PriorityUsageAnalyzer 中的硬编码诊断规则替换为统一的 PriorityDiagnostic
- 在 PriorityGenerator 中添加对嵌套类的支持检查,报告 GF_Priority_005 错误
- 改进生成文件的命名策略,使用完整元数据名称避免冲突
- 更新 AnalyzerReleases.Unshipped.md 文档,添加新的诊断规则说明
- 移除 PriorityGeneratorSnapshotTests 中关于嵌套类的测试用例
2026-03-05 22:52:59 +08:00
GeWuYou
330bd8b0b0 feat(generator): 添加优先级源代码生成器和相关分析器
- 新增 PriorityGenerator 源生成器,自动生成 IPrioritized 接口实现
- 添加 PriorityAttribute 特性,用于标记类的优先级值
- 实现 PriorityUsageAnalyzer 分析器,检测优先级使用建议
- 添加预定义的 PriorityGroup 常量,提供标准优先级分组
- 在 AnalyzerReleases.Unshipped.md 中注册新的诊断规则
- 更新项目依赖,升级 Meziantou.Analyzer 和 Polyfill 版本
- 为测试项目添加源生成器项目引用
- 添加 PriorityGenerator 的快照测试用例
2026-03-05 22:52:59 +08:00
GeWuYou
f8c39e46a5 feat(architecture): 添加按优先级获取服务实例的功能
- 在 ArchitectureContext 中添加 GetServicesByPriority、GetSystemsByPriority、
  GetModelsByPriority 和 GetUtilitiesByPriority 方法
- 在 ContextAwareServiceExtensions 中添加对应的扩展方法支持按优先级获取实例
- 在 MicrosoftDiContainer 中实现 GetAllByPriority 方法和 SortByPriority 排序逻辑
- 在抽象层定义 IPrioritized 接口用于标记可排序的服务组件
- 为 PauseToken 添加完整的相等性比较和字符串转换方法
- 添加全面的单元测试验证优先级排序功能的正确性
2026-03-05 22:52:59 +08:00
GeWuYou
b4d17edeee refactor(core): 移除废弃的同步命令查询扩展方法并简化类型引用
- 移除了 ContextAwareCommandExtensions 中废弃的 SendCommand 同步方法
- 移除了 ContextAwareQueryExtensions 中废弃的 SendQuery 同步方法
- 简化了 ICommand 和 IQuery 的类型引用,移除冗长的命名空间前缀
- 保持了异步命令和查询方法的功能完整性
2026-03-05 22:52:39 +08:00
dependabot[bot]
71b5831261 Bump Meziantou.Polyfill from 1.0.101 to 1.0.103
---
updated-dependencies:
- dependency-name: Meziantou.Polyfill
  dependency-version: 1.0.103
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Polyfill
  dependency-version: 1.0.103
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Polyfill
  dependency-version: 1.0.103
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Polyfill
  dependency-version: 1.0.103
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Polyfill
  dependency-version: 1.0.103
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-05 21:59:59 +08:00
dependabot[bot]
a5d3289f5c Bump Meziantou.Analyzer from 3.0.17 to 3.0.19
---
updated-dependencies:
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.19
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.19
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.19
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.19
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.19
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-05 21:59:46 +08:00
dependabot[bot]
9deae03da0 chore(deps): bump actions/upload-artifact from 6 to 7
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 6 to 7.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-05 21:59:23 +08:00
dependabot[bot]
6d67a125cb chore(deps): bump trufflesecurity/trufflehog from 3.93.4 to 3.93.7
Bumps [trufflesecurity/trufflehog](https://github.com/trufflesecurity/trufflehog) from 3.93.4 to 3.93.7.
- [Release notes](https://github.com/trufflesecurity/trufflehog/releases)
- [Commits](https://github.com/trufflesecurity/trufflehog/compare/v3.93.4...v3.93.7)

---
updated-dependencies:
- dependency-name: trufflesecurity/trufflehog
  dependency-version: 3.93.7
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-05 21:59:15 +08:00
dependabot[bot]
90796543b7 chore(deps): bump oxsecurity/megalinter from 9.3.0 to 9.4.0
Bumps [oxsecurity/megalinter](https://github.com/oxsecurity/megalinter) from 9.3.0 to 9.4.0.
- [Release notes](https://github.com/oxsecurity/megalinter/releases)
- [Changelog](https://github.com/oxsecurity/megalinter/blob/main/CHANGELOG.md)
- [Commits](https://github.com/oxsecurity/megalinter/compare/v9.3.0...v9.4.0)

---
updated-dependencies:
- dependency-name: oxsecurity/megalinter
  dependency-version: 9.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-05 21:59:05 +08:00
GeWuYou
bbb91d597a docs: 添加协程系统、CQRS与Mediator、生命周期管理、资源管理系统文档
- 新增协程系统文档,介绍协程调度器、等待指令、基本用法和最佳实践
- 新增CQRS与Mediator文档,涵盖命令查询职责分离、处理器实现和管道行为
- 新增生命周期管理文档,说明同步异步初始化和销毁机制
- 新增资源管理系统文档,介绍资源加载、缓存和引用计数管理功能
2026-03-05 21:53:55 +08:00
GeWuYou
ae8c3e4fc4 feat(logging): 扩展ILogAppender接口并实现时间提供者注入
- 将ILogAppender接口继承IDisposable以支持资源释放
- 添加ITimeProvider和SystemTimeProvider接口及实现类
- 创建FakeTimeProvider用于测试时间控制
- 修改SamplingFilter支持时间提供者注入和最大日志记录器数量限制
- 为SamplingFilter添加过期状态清理功能
- 修改StatisticsAppender使用时间提供者并实现IDisposable
- 更新相关单元测试以使用FakeTimeProvider进行精确时间控制
- 在测试类中为模拟追加器添加Dispose方法实现
2026-03-05 16:26:47 +08:00
GeWuYou
cd407dc93c test(logging): 添加采样过滤器和统计附加器的单元测试
- 为SamplingFilter添加完整的单元测试覆盖采样率、时间窗口、线程安全等功能
- 为StatisticsAppender添加全面的单元测试验证统计计算、错误率跟踪、报告生成功能
- 测试各个日志级别和记录器的独立状态维护
- 验证多线程环境下的数据一致性
- 包含边界条件和异常情况的测试用例
2026-03-05 16:26:47 +08:00
GeWuYou
c5ed053f2c feat(logging): 添加日志采样过滤器和统计追加器功能
- 实现 SamplingFilter 类用于限制高频日志输出,支持线程安全的采样控制
- 添加 StatisticsAppender 类用于收集日志指标,包括总数量、错误率、级别分布等统计信息
- 提供时间窗口内的采样机制,可配置采样率和时间窗口参数
- 实现完整的统计报告生成功能,支持按级别和日志记录器分类展示
- 添加线程安全的数据结构确保并发环境下的数据一致性
- 提供统计重置和数据查询接口便于监控和调试
2026-03-05 16:26:47 +08:00
deepsource-autofix[bot]
c9617fba8a refactor: use equality operators when evaluating bool?
This PR replaces the use of null-coalescing defaults on nullable booleans with explicit equality checks across instance control methods. The changes make the intent clearer by ensuring only a true result is treated as a positive outcome.

- Consider using the equality operators when evaluating `bool?`: DeepSource flagged instances where `GetInstance(...)?... ?? false` was used to coerce a nullable bool to false implicitly. We replaced these patterns in `PauseOnInstance`, `ResumeOnInstance`, and `KillOnInstance` with `== true` comparisons. Using `== true` clearly indicates that only an explicit true value returns a positive result and avoids ambiguity when the value is null.

> This Autofix was generated by AI. Please review the change before merging.
2026-03-05 14:01:42 +08:00
GeWuYou
41592013ec refactor(GFramework.Core): 移除 ResultState 枚举的字节类型声明
- 移除了 ResultState 枚举的 byte 类型声明,改用默认整型
- 简化了枚举类型的定义,提高代码可读性
2026-03-05 13:12:21 +08:00
GeWuYou
e96b5f24b4 refactor(godot): 将异步方法重命名为遵循Async约定的方法名
- 将WaitUntilReady方法重命名为WaitUntilReadyAsync
- 将AddChildX方法重命名为AddChildXAsync
- 更新所有相关文档中的方法调用引用
- 修改架构层锚点等待方法调用为异步版本
- 更新测试代码中的方法调用以匹配新的方法名
- 调整函数式异步扩展方法命名约定
- 统一所有异步扩展方法的命名规范
2026-03-05 12:54:59 +08:00
GeWuYou
8db379c53f refactor(mediator): 移除自动生成的程序集引用和中介者实现代码
- 删除了 AssemblyReference.g.cs 中的程序集引用生成代码
- 移除了 Mediator.g.cs 中的中介者依赖注入扩展实现
- 清理了内部消息处理器基类和包装器的自动生成代码
- 移除了容器探测器和元数据相关的生成代码
- 删除了中介者主类的自动生成实现
2026-03-05 08:52:38 +08:00
GeWuYou
54bed12056 fix(config): 修复配置管理器变更检测和资源配置优化
- 修改 ConfigurationManager 中的 AddOrUpdate 逻辑,先获取旧值再更新以正确检测变更
- 只有在配置值真正发生变化时才触发监听器回调
- 更新异常日志记录方式,移除冗余的标签前缀
- 将 ConfigWatcherUnRegister 移动到正确的命名空间
- 修复 ResourceManager 中的引用计数逻辑,移除重复的 AddReference 调用
- 优化资源加载和卸载时的异常处理和日志记录
- 更新测试注释以反映正确的引用计数行为
2026-03-05 08:34:05 +08:00
GeWuYou
7919c93f44 feat(resource): 添加资源管理系统和日志集成
- 实现了完整的资源管理系统,包括资源加载、缓存和卸载功能
- 添加了 IResourceHandle、IResourceLoader、IResourceManager 和 IResourceReleaseStrategy 接口定义
- 实现了 AutoReleaseStrategy 和 ManualReleaseStrategy 两种资源释放策略
- 创建了 ResourceCache 缓存系统和 ResourceHandle 资源句柄管理
- 在 ConfigurationManager 和 CoroutineScheduler 中集成了 ILogger 日志功能
- 添加了全面的 ResourceManagerTests 单元测试覆盖各种使用场景
2026-03-05 08:34:05 +08:00
GeWuYou
d8cd22a424 feat(configuration): 添加配置管理器功能
- 实现了 IConfigurationManager 接口定义配置管理契约
- 创建 ConfigurationManager 类提供线程安全的配置存储和访问
- 添加配置的增删改查功能支持泛型类型转换
- 实现配置变更监听机制和取消注册功能
- 提供 JSON 格式导入导出和文件读写功能
- 添加完整的单元测试覆盖并发场景和边界条件
- 实现 ConfigWatcherUnRegister 类处理监听器注销逻辑
2026-03-05 08:34:05 +08:00
GeWuYou
ffaace4538 refactor(core): 重构上下文感知命令和查询扩展方法
- 将原有的 ContextAwareCommandExtensions 中的 Mediator 相关方法分离到新的 ContextAwareMediatorCommandExtensions 类中
- 将原有的 ContextAwareQueryExtensions 中的 Mediator 相关方法分离到新的 ContextAwareMediatorQueryExtensions 类中
- 移除 ContextAwareCommandExtensions 中的异步命令方法 SendCommandAsync
- 移除 ContextAwareQueryExtensions 中的异步查询方法 SendQueryAsync
- 修复了 ContextAwareCommandExtensions 中的泛型类型参数引用问题
- 统一了代码格式和命名空间引用
- 保持了原有功能的向后兼容性
2026-03-05 08:18:57 +08:00
GeWuYou
bde1af2c2e feat(architecture): 添加批量获取组件实例的功能
- 在 ArchitectureContext 中添加 GetServices、GetSystems、GetModels 和 GetUtilities 方法
- 扩展 IArchitectureContext 接口以支持批量获取各类组件实例
- 在测试类中实现相应的批量获取功能
- 将原有的 ContextAwareExtensions 拆分为多个专门的扩展类文件
- 新增 ContextAwareCommandExtensions、ContextAwareEnvironmentExtensions 和 ContextAwareEventExtensions 等扩展类
- 提供了更完善的架构上下文组件访问能力
2026-03-05 08:18:57 +08:00
GeWuYou
d88aa12014 fix(logging): 修复异步日志输出器刷新机制并增强线程安全性
- 实现了基于信号量的可靠Flush完成通知机制
- 添加了OnFlushCompleted事件用于监控刷新操作结果
- 修复了BindaleProperty的线程安全问题,添加锁保护
- 将协程异常回调改为异步执行,防止阻塞调度器主循环
- 优化了AsyncLogAppender的资源清理逻辑
- 增强了Flush方法的超时处理机制
2026-03-04 11:04:59 +08:00
GeWuYou
f984f4a600 refactor(core): 优化核心组件的线程安全性和错误处理
- 重构 AsyncLogAppender 的 Flush 方法,添加超时控制和 SpinWait 优化
- 为 BindableProperty 添加线程安全锁保护,确保并发访问的安全性
- 在 BindableProperty 中实现回调外部调用以避免死锁问题
- 为 EasyEvents 使用 ConcurrentDictionary 替代 Dictionary 提高并发性能
- 添加协程调度器异常处理回调机制,防止异常传播导致调度器崩溃
- 为 FileAppender 添加初始化异常处理和资源清理逻辑
- 补充完整的单元测试覆盖并发场景下的线程安全性验证
2026-03-04 11:04:59 +08:00
GeWuYou
b417ece73a chore(dependencies): 移除 LanguageExt 相关依赖和引用
- 从 GFramework.Game 项目中移除 LanguageExt.Core 包引用
- 从 GFramework.Godot 项目中移除 LanguageExt.Core 包引用
- 从全局引用文件中移除 LanguageExt.Common 引用
- 从全局引用文件中移除 LanguageExt.Effects 引用
- 从全局引用文件中移除 LanguageExt.Pretty 引用
- 保留必要的 System.Threading.Tasks 引用
2026-03-03 22:11:13 +08:00
GeWuYou
1df4e78cdc style(tests): 统一事件测试中的lambda表达式格式
- 在EasyEvent_UnRegister_Should_Remove_Handler方法中将lambda表达式改为块状格式
- 在OrEventTests测试中将lambda表达式改为块状格式
- 保持代码风格一致性,所有lambda表达式都使用大括号包围
2026-03-02 22:01:22 +08:00
deepsource-autofix[bot]
a30abdb4c3 refactor: simplify lambda expressions
This PR refactors numerous lambda expressions by removing unnecessary braces and streamlining single-statement lambdas throughout the codebase, improving readability and maintainability.

- Consider simplifying lambda when its body has a single statement: DeepSource flagged lambdas written with a block body for only one statement, causing extra verbosity. This update converts those to concise expression-bodied lambdas by stripping out the curly braces, applied across test assertions, event registrations, and unregister logic. The code is now cleaner and more consistent.

> This Autofix was generated by AI. Please review the change before merging.
2026-03-02 22:01:22 +08:00
GeWuYou
50c73a7d7c fix(pause): 修复暂停管理器销毁时的并发问题
- 在销毁过程中收集暂停组和处理器快照,避免并发修改异常
- 在锁外通知所有之前暂停的组恢复,保持生命周期信号一致性
- 添加异常处理确保单个处理器失败不影响其他处理器的通知
- 修改文件过滤规则以正确包含测试文件路径
2026-03-02 21:51:35 +08:00
GeWuYou
ccc3d046ca fix(pause): 修复暂停管理器的并发安全和资源清理问题
- 添加了_disposed标志位用于跟踪对象销毁状态
- 实现了完整的DestroyAsync方法进行资源清理和数据结构清空
- 添加了ThrowIfDisposed方法防止对象销毁后被使用
- 将状态变更通知移到锁外部以避免死锁问题
- 在多个公共方法中添加了销毁状态检查
- 修复了ClearGroup和ClearAll方法中的死锁风险
- 改进了异常处理机制,确保线程安全
2026-03-02 21:51:35 +08:00
GeWuYou
7734fba56f feat(pause): 添加暂停栈管理系统
- 实现了 PauseStackManager 核心管理器,支持嵌套暂停和分组管理
- 添加了 PauseToken 暂停令牌和 PauseGroup 暂停组枚举
- 创建了 PauseScope 作用域类,支持 using 语法自动管理暂停生命周期
- 实现了线程安全的暂停栈操作,包括 Push、Pop 和状态查询
- 添加了暂停处理器接口 IPauseHandler 和 Godot 平台具体实现
- 提供了完整的单元测试覆盖基础功能、嵌套暂停、分组管理和线程安全场景
2026-03-02 21:51:35 +08:00
GeWuYou
aa13760748 refactor(functional): 统一功能模块命名空间格式
- 将 GFramework.Core.Functional 命名空间统一改为 GFramework.Core.functional
- 更新 AsyncFunctionalExtensions.cs 中的命名空间声明
- 移除不必要的 using 指令,包括 GFramework.Core.Functional 的导入
- 调整测试文件中的命名空间引用以匹配新的命名空间格式
- 确保所有相关文件都使用一致的小写命名空间约定
2026-03-02 21:51:35 +08:00
GeWuYou
e391bab1ee refactor(ecs): 更新 ArchSystemAdapter 中 OnUpdate 方法的文档注释
- 修改了核心更新逻辑方法的文档描述
- 明确说明该方法为受保护虚方法,默认不执行任何操作
- 详细说明子类可以按需选择性重写此方法来实现具体系统逻辑
- 更新了参数说明文档
2026-03-02 21:20:50 +08:00
GeWuYou
db716a63cb fix(ecs): 修复异步销毁方法返回值问题
- 移除 DestroyAsync 方法中的 async 关键字
- 修改条件判断逻辑,确保返回正确的 ValueTask.CompletedTask
- 删除不必要的 await 关键字,直接返回 ValueTask.CompletedTask
- 保持方法的异步操作正确性
2026-03-02 21:20:50 +08:00
GeWuYou
155ca3024b fix(ecs): 修复模块重复初始化和系统更新问题
- 添加 _isInitialized 标志防止 ArchEcsModule 重复初始化
- 在 Initialize 方法中检查是否已初始化避免重复执行
- 设置初始化标志在所有系统初始化完成后
- 修改 DestroyAsync 方法确保仅在已初始化时执行销毁
- 重置 _isInitialized 标志为 false 在销毁时
- 修正 ArchSystemAdapter 注释描述 OnUpdate 为虚方法而非抽象方法
- 简化 EcsAdvancedTests 中的断言语法移除不必要的大括号
2026-03-02 21:20:50 +08:00
GeWuYou
43dc5a4d11 refactor(ecs): 将 ECS 系统重构为基于 Arch 的原生实现
- 将 MovementSystem 从继承 EcsSystemBase 改为继承 ArchSystemAdapter
- 更新 MovementSystem 的初始化和更新方法以适配 Arch 架构
- 移除测试代码中的 ECS 相关接口实现和抽象层
- 将测试用例从 GFramework ECS API 迁移到 Arch 原生 API
- 更新 ECS 测试类以使用 Arch World 和实体操作方法
- 重构 ECS 模块初始化流程以支持 Arch 系统注册和管理
2026-03-02 21:20:50 +08:00
GeWuYou
40ba109671 refactor(ecs): 优化位置和速度组件的内存布局
- 为 Position 结构体添加 StructLayout 特性以确保顺序布局
- 为 Velocity 结构体添加 StructLayout 特性以确保顺序布局
- 更新 Velocity 组件的 XML 文档注释,提供更详细的描述
- 优化 Velocity 组件属性的文档注释,明确单位信息
- 添加 System.Runtime.InteropServices 命名空间引用
2026-03-02 21:20:50 +08:00
GeWuYou
d7bd9fc569 refactor(ecs): 将ECS系统重构为Arch适配器模式
- 移除原有的ECS基础实现和接口定义
- 添加ArchEcsModule作为新的ECS模块实现
- 创建ArchSystemAdapter基类用于桥接Arch系统
- 修改MovementSystem继承ArchSystemAdapter适配新架构
- 更新ServiceModuleManager使用新的ArchECS模块
- 移除ArchitectureContext中的ECS相关方法
- 从项目中移除对Arch包的直接依赖引用
2026-03-02 21:20:50 +08:00
GeWuYou
3675666e13 refactor(core): 重命名EcsModule为EcsServiceModule以提高命名一致性
- 将EcsModule类重命名为EcsServiceModule
- 更新构造函数名称以匹配新的类名
- 修改ModuleName属性中的类型引用
- 在服务模块管理器中更新模块实例化调用
2026-03-02 21:20:50 +08:00
GeWuYou
fc93ab6e4c chore(config): 添加测试文件排除配置到 deepsource
- 排除 **/*.Tests.cs 模式
- 排除 **/*Test.cs 模式
- 排除 **/tests/** 目录
- 排除 **/*Tests.cs 模式
- 排除 **/Tests/** 目录
2026-03-02 12:42:09 +08:00
GeWuYou
a53898dd43 feat(rule): 添加上下文提供者重置功能
- 添加 ResetContextProvider 方法用于重置上下文提供者为默认值
- 为方法添加 XML 文档注释说明用途
- 实现测试清理相关的上下文管理功能
2026-03-02 12:42:09 +08:00
GeWuYou
3ecce110ed feat(architecture): 添加架构上下文提供者和相关测试
- 新增 IArchitectureContextProvider 接口定义
- 实现 GameContextProvider 类提供上下文获取功能
- 添加 GameContext 静态类用于获取架构上下文
- 创建 ContextProviderTests 测试上下文提供者功能
- 实现 RegistryInitializationHookBase 抽象基类的完整测试
- 修改 IArchitectureContext.GetUtility 方法为虚拟方法以支持重写
2026-03-02 12:42:09 +08:00
GeWuYou
0ed8edf015 refactor(context): 重构上下文管理实现
- 引入 IArchitectureContextProvider 接口解耦上下文获取逻辑
- 创建 GameContextProvider 作为默认上下文提供者
- 添加 ScopedContextProvider 支持多架构实例场景
- 修改源代码生成器使用上下文提供者模式
- 增加 SetContextProvider 方法支持测试和多架构场景
- 添加 RegistryInitializationHookBase 简化注册表初始化逻辑
2026-03-02 12:42:09 +08:00
dependabot[bot]
f98c7f16cf chore(deps): bump trufflesecurity/trufflehog from 3.93.3 to 3.93.4
Bumps [trufflesecurity/trufflehog](https://github.com/trufflesecurity/trufflehog) from 3.93.3 to 3.93.4.
- [Release notes](https://github.com/trufflesecurity/trufflehog/releases)
- [Commits](https://github.com/trufflesecurity/trufflehog/compare/v3.93.3...v3.93.4)

---
updated-dependencies:
- dependency-name: trufflesecurity/trufflehog
  dependency-version: 3.93.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-26 21:54:36 +08:00
dependabot[bot]
88e65bc276 Bump Meziantou.Analyzer from 3.0.12 to 3.0.17
---
updated-dependencies:
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.17
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.17
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.17
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.17
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Meziantou.Analyzer
  dependency-version: 3.0.17
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-26 21:53:47 +08:00
dependabot[bot]
d8ac30d1b6 Bump Microsoft.NET.Test.Sdk from 18.0.1 to 18.3.0
---
updated-dependencies:
- dependency-name: Microsoft.NET.Test.Sdk
  dependency-version: 18.3.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
- dependency-name: Microsoft.NET.Test.Sdk
  dependency-version: 18.3.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-26 21:52:42 +08:00
GeWuYou
13229f1c91 refactor(logging): 优化文件追加器测试中的资源管理
- 重构 Constructor_ShouldCreateDirectoryIfNotExists 测试方法名称为更描述性的格式
- 使用 using 语句块确保 FileAppender 资源得到正确释放
- 改进测试代码结构以提高可读性和资源清理可靠性
2026-02-26 19:57:42 +08:00
GeWuYou
e94e4890cd fix(logging): 统一使用UTC时间戳记录日志
- 将所有DateTime.Now替换为DateTime.UtcNow以确保时区一致性
- 修复文档中的时间戳记录方式
- 更新测试代码中的时间戳生成逻辑
- 统一框架各模块的时间记录标准
2026-02-26 19:57:42 +08:00
GeWuYou
7d0e5931d1 refactor(logging): 优化日志系统的时间戳和代码实现
- 将时间戳从本地时间改为UTC时间以提高一致性
- 使用ToUpperInvariant替代ToUpper提高文化区域安全性
- 简化LogContext中的空值检查逻辑
- 重构CompositeDisposable类以使用主构造函数语法
- 更新测试代码中的时间戳处理方式
2026-02-26 19:57:42 +08:00
GeWuYou
466aae49ec feat(logging): 增强日志配置加载器功能
- 添加 JsonStringEnumConverter 支持枚举的驼峰命名转换
- 实现 ConfigurableLoggerFactory 的 IDisposable 接口确保资源正确释放
- 支持日志级别配置的前缀匹配功能(命名空间层级匹配)
- 优化测试代码中的资源管理,使用 using 语句确保对象正确释放
- 修复 JsonLogFormatter 测试中的属性访问逻辑,使用 TryGetProperty 安全访问
- 将测试中的异常断言从 ArgumentNullException 更新为 ArgumentException
2026-02-26 19:57:42 +08:00
GeWuYou
abdf4cc690 test(logging): 添加日志系统单元测试
- 为 AsyncLogAppender 添加完整功能测试,包括异步写入、缓冲区管理、并发处理等场景
- 为 CachedLoggerFactory 添加缓存机制测试,验证相同名称和级别的日志记录器重用
- 为 CompositeFilter 添加过滤器组合测试,验证多个过滤器的逻辑组合功能
- 为 CompositeLogger 添加复合日志记录器测试,验证多追加器写入和级别过滤功能
- 为 ConsoleAppender 添加控制台追加器测试,验证格式化输出和过滤器支持
- 为 DefaultLogFormatter 添加默认格式化器测试,验证基本格式化和异常处理功能
- 为 FileAppender 添加文件追加器测试,验证文件写入、目录创建和追加模式功能
- 为 JsonLogFormatter 添加 JSON 格式化器测试,验证 JSON 输出和属性序列化功能
- 为 LogContext 添加日志上下文测试,验证属性推送和作用域管理功能
2026-02-26 19:57:42 +08:00
GeWuYou
1ba771e13a feat(logging): 实现结构化日志记录和异步日志输出功能
- 将 AbstractLogger 实现从 ILogger 扩展为 IStructuredLogger 接口
- 添加通用日志方法 Log(LogLevel, string, params object[]) 支持格式化参数
- 实现结构化日志方法支持属性键值对记录
- 添加 ConsoleAppender、FileAppender 和 AsyncLogAppender 日志输出器
- 实现 CompositeFilter 过滤器和 DefaultLogFormatter、JsonLogFormatter 格式化器
- 在 ConsoleLogger 和 GodotLogger 中使用预缓存的日志级别字符串提升性能
- 使用 ANSI 颜色代码替代 ConsoleColor 实现跨平台日志着色
- 在 ConsoleLoggerFactoryProvider 和 GodotLoggerFactoryProvider 中添加日志工厂缓存
- 优化 FileStorage 中目录遍历使用 OfType<string>() 类型转换
- 添加 LogContext 支持异步流中的结构化属性传递
2026-02-26 19:57:42 +08:00
GeWuYou
445513b784 docs(tests): 为测试文件添加XML文档注释
- 为AsyncExtensionsTests中的所有测试方法添加描述性注释
- 为CollectionExtensionsTests中的所有测试方法添加描述性注释
- 为DelayTests类和其中的测试方法添加描述性注释
- 为GuardExtensionsTests中的所有测试方法添加描述性注释
- 为MediatorComprehensiveTests中的所有测试方法添加描述性注释
- 为NumericExtensionsTests中的所有测试方法添加描述性注释
- 为OptionTests中的所有测试方法添加描述性注释
- 为PipeExtensionsTests中的所有测试方法添加描述性注释
2026-02-26 14:45:39 +08:00
GeWuYou
59fbb2253b feat(tests): 添加函数式编程扩展和Option类型测试
- 添加ControlExtensions的TakeIfValue、TakeUnlessValue、When、RepeatUntil和Retry方法测试
- 添加FunctionExtensions的Compose、AndThen、Curry、Uncurry、Defer和Once方法测试
- 添加Option<T>类型的完整测试套件,包括工厂方法、取值、变换、过滤、模式匹配等功能
- 添加PipeExtensions的Tap、Pipe、Let、PipeIf方法测试
- 移除AsyncExtensionsTests中的WhenAll相关测试
- 移除NumericExtensionsTests中的Clamp测试
- 更新ObjectExtensionsTests中Do方法为Also方法的测试
- 修复ControlExtensions文档中的XML代码标签格式
- 在AsyncExtensionsTests中添加对GFramework.Core.Functional.Async的引用
- 在ObjectExtensionsTests中添加对GFramework.Core.functional.pipe的引用
2026-02-26 14:45:39 +08:00
GeWuYou
28ce315d29 feat(functional): 添加函数式编程扩展方法
- 在 ControlExtensions 中添加 TakeIfValue 和 TakeUnlessValue 方法,支持值类型的条件判断
- 在 ControlExtensions 中添加 When 方法,支持条件执行操作
- 在 ControlExtensions 中添加 RepeatUntil 方法,支持重复执行直到条件满足
- 在 ControlExtensions 中添加 Retry 方法,支持同步重试机制
- 在 FunctionExtensions 中添加 Compose 和 AndThen 方法,支持函数组合
- 在 FunctionExtensions 中添加 Curry 和 Uncurry 方法,支持函数柯里化
- 在 FunctionExtensions 中添加 Defer 和 Once 方法,支持延迟执行和单次执行
- 在 PipeExtensions 中添加 Tap 方法,作为 Also 的别名
- 在 PipeExtensions 中添加 Pipe 方法,支持管道操作
- 在 PipeExtensions 中添加 Let 方法,支持作用域函数
- 在 PipeExtensions 中添加 PipeIf 方法,支持条件管道操作
2026-02-26 14:45:39 +08:00
GeWuYou
df0f00bd9e refactor(core): 重构核心库代码结构
- 将异步扩展方法移至新的 AsyncFunctionalExtensions 类中
- 删除重复的数值扩展、对象扩展和字符串扩展方法
- 添加 Option 函数式编程类型实现
- 重命名 ResultExtensions 文件路径
- 修复 ResultExtensions 中的错误处理逻辑
- 更新命名空间以符合新的包结构
2026-02-26 14:45:39 +08:00
GeWuYou
c454fa1acf perf(GFramework.Core): 优化PriorityEvent事件处理器性能
- 在MergeAndSortHandlers方法中创建_handlers和_contextHandlers的快照副本
- 避免在迭代期间直接访问集合可能发生的修改问题
- 提高事件处理时的性能表现和稳定性
2026-02-25 21:39:53 +08:00
GeWuYou
78e0c75641 refactor(events): 重构PriorityEvent事件处理逻辑
- 将原有的大块switch语句拆分为独立的方法
- 提取TriggerAll、TriggerUntilHandled和TriggerHighest方法
- 新增MergeAndSortHandlers方法用于合并和排序处理器
- 添加GetHighestPriority方法获取最高优先级值
- 分离普通事件处理器和上下文事件处理器的执行逻辑
- 提高代码可读性和维护性
2026-02-25 21:39:53 +08:00
GeWuYou
eec50ab45b feat(events): 添加事件上下文支持和线程安全改进
- 在EventBus中添加RegisterWithContext方法支持事件上下文
- 实现EventContext<T>类包装事件数据并提供处理控制
- 在PriorityEvent中添加上下文事件处理器和相关管理逻辑
- 改进事件触发机制支持普通和上下文处理器混合使用
- 优化MicrosoftDiContainer的线程安全性和并发访问
- 修复SpanExtensions中TryParseValue的返回值类型问题
- 添加全面的单元测试覆盖新功能和边界情况
2026-02-25 21:39:53 +08:00
GeWuYou
e2dca4f5a6 feat(events): 添加事件优先级和传播控制功能
- 实现了事件优先级机制,支持按优先级顺序执行事件处理器
- 新增EventPropagation枚举,支持All、UntilHandled和Highest三种传播模式
- 添加Register方法的重载版本,支持指定事件处理器优先级
- 实现Send方法的重载版本,支持指定事件传播模式
- 新增PriorityEvent类处理带优先级的事件逻辑
- 添加IocContainer的CreateScope方法支持服务作用域管理
- 实现RegisterTransient和RegisterScoped方法完善依赖注入生命周期
- 新增SpanExtensions扩展方法提供高性能的span操作功能
- 添加全面的单元测试覆盖事件优先级、IoC容器生命周期和span扩展功能
2026-02-25 21:39:53 +08:00
GeWuYou
e2cfa7bffa fix(pool): 修复对象池系统中的双重释放和线程安全问题
- 修复 ActiveCount 在双重释放时可能变为负数的问题
- 添加对错误 key 释放的防护和警告日志
- 优化 StringBuilderPool 使用 ConcurrentBag 实现线程安全
- 改进池容量限制逻辑,超过最大容量的对象将被销毁
- 添加完整的单元测试验证双重释放、错误释放和线程安全场景
2026-02-25 20:40:02 +08:00
GeWuYou
eb763a9bc4 feat(pool): 重构对象池系统增加统计和容量控制功能
- 引入 PoolInfo 类来管理对象池的核心数据结构和统计信息
- 添加对象池容量限制功能,超过容量时自动销毁多余对象
- 实现对象池统计功能,跟踪创建、获取、释放、销毁等操作计数
- 新增 GetPoolSize 和 GetActiveCount 方法获取池状态信息
- 添加 SetMaxCapacity 方法设置池的最大容量限制
- 实现 Prewarm 功能用于预创建对象提高性能
- 提供 GetStatistics 方法获取详细的池统计信息
- 添加 IsExternalInit 支持旧版 .NET 框架的 init-only 属性
- 扩展 ArrayPool 添加便捷的扩展方法和自动释放功能
- 新增 StringBuilderPool 提供高性能的字符串构建器复用
- 完善单元测试覆盖新增的所有功能特性
2026-02-25 20:40:02 +08:00
GeWuYou
1d50dc2224 fix(result): 修复Result扩展和异常处理逻辑
- 在Combine方法中添加对Bottom状态的检查和处理
- 使用IfSucc方法简化成功状态下的值添加逻辑
- 修正泛型绑定示例中的语法错误
- 在FromNullable和FromNullableStruct方法中使用nameof获取参数名称
- 改进Exception属性的文档说明并优化异常消息
- 在Try方法中添加对空函数的验证
2026-02-25 20:21:37 +08:00
GeWuYou
61349a83ab feat(functional): 增强Result类型功能并添加完整测试覆盖
- 为Result.Failure方法添加参数验证,确保异常和消息参数不为空
- 重构Result<T>内部状态枚举顺序以优化比较逻辑
- 为Result<T>的Map、Bind和MapAsync方法添加参数验证和异常处理
- 在Result<T>比较逻辑中添加类型不可比较时的安全处理
- 添加ResultExtensions.BindAsync扩展方法支持异步绑定操作
- 重写Combine扩展方法中对失败结果的处理逻辑
- 添加完整的Result相关类型单元测试覆盖所有功能场景
- 为Result类型添加详细的XML文档注释和使用示例
2026-02-25 20:21:37 +08:00
GeWuYou
1cb7dfdb14 feat(functional): 添加函数式编程支持和Result类型实现
- 实现了Result和Result<T>结构体,提供函数式错误处理
- 添加了AsyncExtensions中的函数式编程命名空间引用
- 在FunctionExtensions中添加函数式编程相关引用
- 从项目文件中移除LanguageExt.Core依赖包
- 重构GlobalUsings.cs移除不必要的全局引用
- 添加ResultExtensions扩展方法支持函数式操作
- 实现Map、Bind、Match等核心函数式编程方法
- 添加异步操作支持和安全执行委托功能
2026-02-25 20:21:37 +08:00
GeWuYou
ee3f8c97df fix(tests): 修正异步扩展测试中的异常类型断言
- 将 OperationCanceledException 替换为 TaskCanceledException 进行正确的异常断言
2026-02-25 17:28:52 +08:00
GeWuYou
cddd1fa627 test(extensions): 更新异步扩展方法测试以使用直接调用方式
- 移除旧的Arrange步骤,直接在Act步骤中调用AsyncExtensions.WithTimeout方法
- 添加新的测试用例验证超时时内部任务能够被正确取消
- 修改现有测试用例适配新的方法调用方式
- 简化异常处理相关的断言逻辑
2026-02-25 17:28:52 +08:00
GeWuYou
afbff7127d refactor(extensions): 重构异步扩展中的超时处理机制
- 将参数从直接传入Task改为传入接收取消令牌的任务工厂方法
- 更新XML文档注释以反映新的参数设计
- 优化取消令牌处理逻辑,统一管理超时和外部取消信号
- 改进异常处理机制,确保超时情况下正确抛出TimeoutException
- 简化代码结构并提高可读性
2026-02-25 17:28:52 +08:00
GeWuYou
850fecdff4 fix(async): 修复异步扩展中的超时和重试逻辑问题
- 修复TimeoutAfter方法中的取消令牌处理逻辑,避免OperationCanceledException被意外捕获
- 修复RetryAsync方法中的参数验证,移除对可空值类型的空值检查
- 为RetryAsync方法添加throwOriginal参数以控制异常抛出行为
- 统一超时处理中的令牌取消方式,使用linkedCts.Cancel()替代timeoutCts.CancelAsync()
2026-02-25 17:28:52 +08:00
GeWuYou
475f301d9f feat(extensions): 添加多个扩展方法类和对应测试
- 新增 AsyncExtensions 提供异步任务超时、重试、安全执行等功能
- 新增 CollectionExtensions 提供集合遍历、空值检查、过滤等扩展功能
- 新增 GuardExtensions 提供参数验证的 Guard 模式扩展方法
- 新增 NumericExtensions 提供数值范围限制、插值计算等数学扩展功能
- 为所有扩展方法添加完整的单元测试覆盖正常和异常情况
- 包含详细的 XML 文档注释和使用示例代码
2026-02-25 17:28:52 +08:00
GeWuYou
66da08e3e1 docs(skill): 更新技能文档
- 修改了 SKILL.md 文件内容移除了BOM
2026-02-25 09:28:33 +08:00
GeWuYou
8aba6c6fad refactor(scripts): 重构脚本以使用共享模块配置
- 将模块配置提取到共享的 module-config.sh 文件中
- 在 batch-generate.sh 中使用 get_source_dir 和 is_valid_module 函数
- 更新可用模块列表显示为动态获取
- 在 generate-examples.sh 中添加命名空间参数和详细的示例生成指南
- 优化 update-vitepress-nav.sh 中的用户界面和添加重复检查
- 修改 validate-all.sh 中的代码块验证以避免中断流程
- 改进 validate-frontmatter.sh 中的 frontmatter 检测逻辑
- 将 find 命令结果存储为数组以提高处理准确性
2026-02-25 09:28:33 +08:00
GeWuYou
bb449259d3 feat(docs): 添加 VitePress 文档生成技能系统
- 新增 .claude/skills 目录及完整的文档生成技能系统
- 添加批量 API 文档生成脚本支持模块化文档创建
- 添加 API 文档、功能指南和教程生成模板与示例
- 添加 C# XML 注释解析和代码示例生成工具
- 添加文档验证和导航更新脚本确保质量
- 更新 .gitignore 配置排除本地设置文件
2026-02-25 09:28:33 +08:00
GeWuYou
7c71ed154e chore(docs): 更新 .NET 版本标识从 6.0+ 到 8.0+
- 修改 README.md 中的 .NET badge 版本号
- 将 .NET 支持版本更新为最新的 8.0+ 标准
2026-02-24 15:20:31 +08:00
GeWuYou
94d3f0ba27 fix(storage): 修复文件存储和存档仓库中的路径处理问题
- 在 FileStorage 中过滤掉以点开头的隐藏目录
- 优化 SaveRepository 中的存档存在性检查逻辑
- 移除冗余的 ScopedStorage 创建操作
- 删除过时的 SaveRepository 使用指南文档
2026-02-24 15:20:31 +08:00
GeWuYou
2d4527d066 feat(storage): 添加目录操作功能和存档仓库系统
- 在IStorage接口中添加目录操作相关方法:ListDirectoriesAsync、
  ListFilesAsync、DirectoryExistsAsync、CreateDirectoryAsync
- 为FileStorage和GodotFileStorage实现目录操作功能
- 添加ScopedStorage的目录操作委托实现
- 新增ISaveRepository接口定义基于槽位的存档系统
- 实现SaveRepository类提供完整的存档管理功能
- 添加SaveConfiguration类用于存档系统配置
2026-02-24 15:20:31 +08:00
818 changed files with 84385 additions and 40959 deletions

View File

@ -0,0 +1,62 @@
schema_version: 1
generated_at_utc: "2026-03-21T04:47:58Z"
generated_from: ".ai/environment/tools.raw.yaml"
generator: "scripts/generate-ai-environment.py"
platform:
family: "wsl-linux"
os: "Linux"
distro: "Ubuntu 24.04.4 LTS"
shell: "bash"
capabilities:
dotnet: true
python: true
node: true
bun: true
docker: true
fast_search: true
json_cli: true
tool_selection:
search:
preferred: "rg"
fallback: "grep"
use_for: "Repository text search."
json:
preferred: "jq"
fallback: "python3"
use_for: "Inspecting or transforming JSON command output."
shell:
preferred: "bash"
fallback: "sh"
use_for: "Repository shell scripts and command execution."
scripting:
preferred: "python3"
fallback: "bash"
use_for: "Non-trivial local automation and helper scripts."
docs_package_manager:
preferred: "bun"
fallback: "npm"
use_for: "Installing and previewing the docs site."
build_and_test:
preferred: "dotnet"
fallback: "unavailable"
use_for: "Build, test, restore, and solution validation."
python:
available: true
helper_packages:
requests: true
rich: true
openai: false
tiktoken: false
pydantic: false
pytest: false
preferences:
prefer_project_listed_tools: true
prefer_python_for_non_trivial_automation: true
avoid_unlisted_system_tools: true
rules:
- "Use rg instead of grep for repository search when rg is available."
- "Use jq for JSON inspection; fall back to python3 if jq is unavailable."
- "Prefer python3 over complex bash for non-trivial scripting when python3 is available."
- "Use bun for docs preview workflows when bun is available; otherwise fall back to npm."
- "Use dotnet for repository build and test workflows."
- "Do not assume unrelated system tools are part of the supported project environment."

View File

@ -0,0 +1,89 @@
schema_version: 1
generated_at_utc: "2026-03-21T04:47:28Z"
generator: "scripts/collect-dev-environment.sh"
platform:
os: "Linux"
distro: "Ubuntu 24.04.4 LTS"
version: "24.04"
kernel: "5.15.167.4-microsoft-standard-WSL2"
wsl: true
wsl_version: "2.4.13"
shell: "bash"
required_runtimes:
dotnet:
installed: true
version: "10.0.104"
path: "/usr/bin/dotnet"
purpose: "Builds and tests the GFramework solution."
python3:
installed: true
version: "Python 3.12.3"
path: "/usr/bin/python3"
purpose: "Runs local automation and environment collection scripts."
node:
installed: true
version: "v20.20.1"
path: "/usr/bin/node"
purpose: "Provides the JavaScript runtime used by docs tooling."
bun:
installed: true
version: "1.3.10"
path: "/root/.bun/bin/bun"
purpose: "Installs and previews the VitePress documentation site."
required_tools:
git:
installed: true
version: "git version 2.43.0"
path: "/usr/bin/git"
purpose: "Source control and patch review."
bash:
installed: true
version: "GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)"
path: "/usr/bin/bash"
purpose: "Executes repository scripts and shell automation."
rg:
installed: true
version: "ripgrep 15.1.0 (rev af60c2de9d)"
path: "/root/.bun/install/global/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/path/rg"
purpose: "Fast text search across the repository."
jq:
installed: true
version: "jq-1.7"
path: "/usr/bin/jq"
purpose: "Inspecting and transforming JSON outputs."
project_tools:
docker:
installed: true
version: "Docker version 29.2.1, build a5c7197"
path: "/usr/bin/docker"
purpose: "Runs MegaLinter and other containerized validation tools."
python_packages:
requests:
installed: true
version: "2.31.0"
purpose: "Simple HTTP calls in local helper scripts."
rich:
installed: true
version: "13.7.1"
purpose: "Readable CLI output for local Python helpers."
openai:
installed: false
version: "not-installed"
purpose: "Optional scripted access to OpenAI APIs."
tiktoken:
installed: false
version: "not-installed"
purpose: "Optional token counting for prompt and context inspection."
pydantic:
installed: false
version: "not-installed"
purpose: "Optional typed config and schema validation for helper scripts."
pytest:
installed: false
version: "not-installed"
purpose: "Optional lightweight testing for Python helper scripts."

469
.claude/skills/README.md Normal file
View File

@ -0,0 +1,469 @@
# VitePress 文档生成 Skills 系统
为 GFramework 项目提供自动化的 VitePress 文档生成能力。
## 概述
这是一套专门为 GFramework 项目设计的文档生成 skills能够根据 C# 源代码自动生成高质量的 VitePress 文档。系统采用模块化设计,每个 skill 专注于特定的文档生成任务。
## 可用 Skills
### 1. vitepress-api-doc - API 文档生成
为单个 C# 文件生成 API 参考文档。
**用途**
- 类、接口、枚举的 API 文档
- 方法、属性、事件的详细说明
- 基于 XML 注释生成文档
**调用方式**
```bash
/vitepress-api-doc <C# 文件路径>
```
**示例**
```bash
/vitepress-api-doc GFramework.Core/architecture/Architecture.cs
```
**输出位置**`docs/zh-CN/api-reference/<模块>/<文件名>.md`
[详细文档](./vitepress-api-doc/SKILL.md)
---
### 2. vitepress-guide - 功能指南生成
生成功能模块的使用指南文档。
**用途**
- 核心功能模块的使用说明
- 设计模式和架构概念
- 最佳实践和常见问题
**调用方式**
```bash
/vitepress-guide <主题> <目标模块>
```
**示例**
```bash
/vitepress-guide "事件系统" Core
/vitepress-guide "IoC 容器" Core
```
**输出位置**`docs/zh-CN/<模块>/<主题>.md`
[详细文档](./vitepress-guide/SKILL.md)
---
### 3. vitepress-tutorial - 分步教程生成
生成分步教程文档,适合初学者学习。
**用途**
- 框架入门教程
- 功能实现教程
- 问题解决方案
**调用方式**
```bash
/vitepress-tutorial <教程主题>
```
**示例**
```bash
/vitepress-tutorial "创建第一个 System"
/vitepress-tutorial "使用事件系统"
```
**输出位置**`docs/zh-CN/tutorials/<主题>.md`
[详细文档](./vitepress-tutorial/SKILL.md)
---
### 4. vitepress-batch-api - 批量 API 文档生成
为整个模块批量生成 API 文档。
**用途**
- 初始化模块文档
- 更新整个模块的文档
- 快速生成大量文档
**调用方式**
```bash
/vitepress-batch-api <模块名>
```
**示例**
```bash
/vitepress-batch-api Core
/vitepress-batch-api Godot
```
**输出位置**`docs/zh-CN/api-reference/<模块>/`
[详细文档](./vitepress-batch-api/SKILL.md)
---
### 5. vitepress-validate - 文档验证
验证文档的质量和规范性。
**用途**
- Frontmatter 格式验证
- 内部链接有效性检查
- 代码块语法验证
- 标点符号规范检查
**调用方式**
```bash
/vitepress-validate <文件或目录路径>
```
**示例**
```bash
/vitepress-validate docs/zh-CN/api-reference/core/architecture.md
/vitepress-validate docs/zh-CN/
```
[详细文档](./vitepress-validate/SKILL.md)
---
## 快速开始
### 1. 生成单个 API 文档
```bash
# 为 Architecture 类生成文档
/vitepress-api-doc GFramework.Core/architecture/Architecture.cs
```
### 2. 批量生成模块文档
```bash
# 为整个 Core 模块生成文档
/vitepress-batch-api Core
```
### 3. 生成功能指南
```bash
# 生成事件系统使用指南
/vitepress-guide "事件系统" Core
```
### 4. 生成教程
```bash
# 生成创建 Model 的教程
/vitepress-tutorial "创建第一个 Model"
```
### 5. 验证文档
```bash
# 验证生成的文档
/vitepress-validate docs/zh-CN/api-reference/core/
```
## 工作流程
### 典型工作流程
```mermaid
graph TD
A[开始] --> B{文档类型?}
B -->|API 文档| C[/vitepress-api-doc]
B -->|功能指南| D[/vitepress-guide]
B -->|教程| E[/vitepress-tutorial]
C --> F[/vitepress-validate]
D --> F
E --> F
F --> G{验证通过?}
G -->|是| H[完成]
G -->|否| I[修复问题]
I --> F
```
### 推荐流程
1. **初始化模块文档**
```bash
/vitepress-batch-api Core
```
2. **生成功能指南**
```bash
/vitepress-guide "IoC 容器" Core
/vitepress-guide "事件系统" Core
```
3. **生成教程**
```bash
/vitepress-tutorial "创建第一个 Model"
/vitepress-tutorial "使用命令系统"
```
4. **验证所有文档**
```bash
/vitepress-validate docs/zh-CN/
```
## 目录结构
```
.claude/skills/
├── README.md # 本文件
├── _shared/ # 共享资源
│ └── scripts/ # 共享脚本
│ ├── update-vitepress-nav.sh # 更新导航配置
│ ├── parse-csharp-xml.sh # 解析 XML 注释
│ └── generate-examples.sh # 生成代码示例
├── vitepress-api-doc/ # API 文档生成
│ ├── SKILL.md # Skill 说明
│ ├── template.md # 文档模板
│ └── examples/ # 示例文档
│ ├── class-example.md
│ ├── interface-example.md
│ └── enum-example.md
├── vitepress-guide/ # 功能指南生成
│ ├── SKILL.md
│ ├── template.md
│ └── examples/
│ └── guide-example.md
├── vitepress-tutorial/ # 教程生成
│ ├── SKILL.md
│ ├── template.md
│ └── examples/
│ └── tutorial-example.md
├── vitepress-batch-api/ # 批量 API 文档生成
│ ├── SKILL.md
│ └── scripts/
│ └── batch-generate.sh
└── vitepress-validate/ # 文档验证
├── SKILL.md
└── scripts/
├── validate-frontmatter.sh
├── validate-links.sh
├── validate-code-blocks.sh
└── validate-all.sh
```
## 设计原则
### 1. 单一职责
每个 skill 专注于一个特定任务:
- `vitepress-api-doc` - 单文件 API 文档
- `vitepress-guide` - 功能指南
- `vitepress-tutorial` - 分步教程
- `vitepress-batch-api` - 批量生成
- `vitepress-validate` - 质量验证
### 2. 模块化设计
- 共享脚本放在 `_shared/scripts/`
- 每个 skill 独立维护
- 可以单独使用或组合使用
### 3. 基于源代码
- 仅使用 XML 注释,不添加 AI 补充
- 保持文档与代码同步
- 代码示例由 AI 自动生成
### 4. 质量保证
- 所有生成的文档都应通过验证
- 遵循 VitePress 规范
- 保持一致的文档风格
## 文档规范
### Frontmatter 格式
```yaml
---
title: 文档标题
description: 简短描述1-2 句话)
outline: deep # 可选
---
```
### 代码块标记
- C# 代码使用 `csharp`
- Bash 脚本使用 `bash`
- JSON 使用 `json`
- YAML 使用 `yaml`
### 泛型符号转义
在正文中使用 HTML 实体:
- `List<T>``List&lt;T&gt;`
- 代码块内保持原样
### 中文标点符号
- 中文句子使用全角标点:,。!?
- 英文句子使用半角标点:,.!?
- 代码周围使用半角符号
## 共享脚本
### update-vitepress-nav.sh
更新 VitePress 侧边栏导航配置。
**用法**
```bash
.claude/skills/_shared/scripts/update-vitepress-nav.sh <文件路径> <标题>
```
### parse-csharp-xml.sh
解析 C# XML 文档注释。
**用法**
```bash
.claude/skills/_shared/scripts/parse-csharp-xml.sh <C# 文件路径>
```
### generate-examples.sh
生成代码示例。
**用法**
```bash
.claude/skills/_shared/scripts/generate-examples.sh <类型名> <命名空间>
```
## 最佳实践
### 1. 文档生成顺序
1. 先生成 API 文档(基础)
2. 再生成功能指南(概念)
3. 最后生成教程(实践)
### 2. 保持文档同步
- 修改代码后及时更新文档
- 使用单文件生成更新特定文档
- 定期批量验证所有文档
### 3. 质量控制
- 生成后立即验证
- 修复所有错误和警告
- 确保链接有效
### 4. 版本控制
- 将生成的文档提交到 Git
- 在 PR 中包含文档更新
- 保持文档与代码版本一致
## 故障排除
### 问题:生成的文档缺少内容
**原因**:源代码缺少 XML 注释
**解决方案**
1. 在源代码中添加 XML 注释
2. 重新生成文档
### 问题:验证失败
**原因**:文档格式不符合规范
**解决方案**
1. 查看验证错误信息
2. 根据提示修复问题
3. 重新验证
### 问题:链接损坏
**原因**:文件路径错误或文件不存在
**解决方案**
1. 检查链接的目标文件是否存在
2. 修正文件路径
3. 重新验证
### 问题:批量生成速度慢
**原因**:文件数量多
**解决方案**
1. 使用 `--parallel` 选项(如果支持)
2. 分批生成
3. 仅生成修改的文件
## 扩展开发
### 添加新 Skill
1. 在 `.claude/skills/` 下创建新目录
2. 创建 `SKILL.md` 说明文档
3. 创建必要的模板和脚本
4. 在本 README 中添加说明
### 修改现有 Skill
1. 更新 `SKILL.md` 文档
2. 修改模板或脚本
3. 更新示例文档
4. 测试修改后的功能
## 贡献指南
### 报告问题
在 GitHub Issues 中报告问题,包含:
- 使用的 skill 名称
- 输入参数
- 预期结果
- 实际结果
- 错误信息
### 提交改进
1. Fork 项目
2. 创建功能分支
3. 提交修改
4. 创建 Pull Request
## 版本历史
- v1.0.0 (2025-01-XX) - 初始版本
- 5 个核心 skills
- 3 个共享脚本
- 完整的文档和示例
## 许可证
与 GFramework 项目保持一致。
## 联系方式
如有问题或建议,请通过以下方式联系:
- GitHub Issues
- 项目讨论区
---
**注意**:本 skills 系统专为 GFramework 项目设计,使用前请确保了解项目结构和文档规范。

View File

@ -0,0 +1,205 @@
# GFramework 文档编写规范
## Markdown 语法规范
### 1. 泛型标记转义
在 Markdown 文档中,所有泛型标记必须转义,否则会被 VitePress 误认为 HTML 标签。
**错误示例**:
```markdown
`Option<T>` 是一个泛型类型
`Result<TValue, TError>` 表示结果
public class Repository<TData> { }
```
**正确示例**:
```markdown
`Option&lt;T&gt;` 是一个泛型类型
`Result&lt;TValue, TError&gt;` 表示结果
public class Repository&lt;TData&gt; { }
```
**常见泛型标记**:
- `<T>``&lt;T&gt;`
- `<TResult>``&lt;TResult&gt;`
- `<TValue>``&lt;TValue&gt;`
- `<TError>``&lt;TError&gt;`
- `<TSaveData>``&lt;TSaveData&gt;`
- `<TData>``&lt;TData&gt;`
- `<TNode>``&lt;TNode&gt;`
### 2. HTML 标签转义
如果需要在文档中显示 HTML 标签,必须转义:
- `<summary>``&lt;summary&gt;`
- `<param>``&lt;param&gt;`
- `<returns>``&lt;returns&gt;`
### 3. 链接验证
**内部链接规则**:
- 使用相对路径: `/zh-CN/core/events`
- 确保目标文件存在
- 不要链接到尚未创建的页面
**已存在的文档路径**:
**Core 模块**:
- `/zh-CN/core/architecture` - 架构系统
- `/zh-CN/core/ioc` - IoC 容器
- `/zh-CN/core/events` - 事件系统
- `/zh-CN/core/command` - 命令系统
- `/zh-CN/core/query` - 查询系统
- `/zh-CN/core/model` - Model 系统
- `/zh-CN/core/system` - System 系统
- `/zh-CN/core/utility` - Utility 系统
- `/zh-CN/core/controller` - Controller 系统
- `/zh-CN/core/logging` - 日志系统
- `/zh-CN/core/pool` - 对象池
- `/zh-CN/core/property` - 可绑定属性
- `/zh-CN/core/lifecycle` - 生命周期管理
- `/zh-CN/core/coroutine` - 协程系统
- `/zh-CN/core/resource` - 资源管理
- `/zh-CN/core/state-machine` - 状态机
- `/zh-CN/core/cqrs` - CQRS 与 Mediator
- `/zh-CN/core/functional` - 函数式编程
- `/zh-CN/core/pause` - 暂停管理
- `/zh-CN/core/configuration` - 配置管理
- `/zh-CN/core/ecs` - ECS 系统集成
- `/zh-CN/core/extensions` - 扩展方法
- `/zh-CN/core/rule` - 规则系统
- `/zh-CN/core/environment` - 环境系统
- `/zh-CN/core/context` - 上下文系统
- `/zh-CN/core/async-initialization` - 异步初始化
**Game 模块**:
- `/zh-CN/game/scene` - 场景系统
- `/zh-CN/game/ui` - UI 系统
- `/zh-CN/game/data` - 数据与存档
- `/zh-CN/game/storage` - 存储系统
- `/zh-CN/game/serialization` - 序列化系统
- `/zh-CN/game/setting` - 设置系统
**Godot 模块**:
- `/zh-CN/godot/architecture` - Godot 架构集成
- `/zh-CN/godot/scene` - Godot 场景系统
- `/zh-CN/godot/ui` - Godot UI 系统
- `/zh-CN/godot/pool` - Godot 节点池
- `/zh-CN/godot/resource` - Godot 资源仓储
- `/zh-CN/godot/logging` - Godot 日志系统
- `/zh-CN/godot/pause` - Godot 暂停处理
- `/zh-CN/godot/extensions` - Godot 扩展
- `/zh-CN/godot/coroutine` - Godot 协程
- `/zh-CN/godot/signal` - Godot 信号
- `/zh-CN/godot/storage` - Godot 存储
**教程**:
- `/zh-CN/tutorials/coroutine-tutorial` - 协程系统教程
- `/zh-CN/tutorials/state-machine-tutorial` - 状态机教程
- `/zh-CN/tutorials/resource-management` - 资源管理教程
- `/zh-CN/tutorials/save-system` - 存档系统教程
- `/zh-CN/tutorials/godot-complete-project` - Godot 完整项目
- `/zh-CN/tutorials/functional-programming` - 函数式编程实践
- `/zh-CN/tutorials/pause-system` - 暂停系统实现
- `/zh-CN/tutorials/data-migration` - 数据迁移实践
- `/zh-CN/tutorials/godot-integration` - Godot 集成
- `/zh-CN/tutorials/advanced-patterns` - 高级模式
**其他**:
- `/zh-CN/getting-started/quick-start` - 快速开始
- `/zh-CN/getting-started/installation` - 安装指南
- `/zh-CN/best-practices/architecture-patterns` - 架构模式
**不存在的路径** (不要链接):
- `/zh-CN/best-practices/performance` - 尚未创建
- `/zh-CN/core/serializer` - 错误路径,应使用 `/zh-CN/game/serialization`
## 代码块规范
### 1. 代码块语言标识
始终指定代码块的语言:
```markdown
\`\`\`csharp
public class Example { }
\`\`\`
\`\`\`bash
npm install
\`\`\`
```
### 2. 代码注释
代码示例应包含中文注释:
```csharp
// 创建玩家实体
var player = new Player
{
Name = "玩家1", // 玩家名称
Level = 1 // 初始等级
};
```
## Frontmatter 规范
每个文档必须包含正确的 frontmatter:
```yaml
---
title: 文档标题
description: 简短描述1-2 句话)
---
```
## 文档结构规范
### 指南文档结构
1. 概述
2. 核心概念
3. 基本用法
4. 高级用法
5. 最佳实践
6. 常见问题
7. 相关文档
### 教程文档结构
1. 学习目标
2. 前置条件
3. 步骤 1-N (3-7 步)
4. 完整代码
5. 运行结果
6. 下一步
7. 相关文档
## 验证清单
生成文档后,必须检查:
- [ ] 所有泛型标记已转义 (`<T>``&lt;T&gt;`)
- [ ] 所有内部链接指向存在的页面
- [ ] Frontmatter 格式正确
- [ ] 代码块指定了语言
- [ ] 代码包含中文注释
- [ ] 文档结构完整
- [ ] 没有 HTML 标签错误
## 自动修复脚本
如果文档已生成,可以使用以下脚本修复常见问题:
```bash
# 修复泛型标记
sed -i 's/<T>/\&lt;T\&gt;/g' file.md
sed -i 's/<TResult>/\&lt;TResult\&gt;/g' file.md
sed -i 's/<TValue>/\&lt;TValue\&gt;/g' file.md
sed -i 's/<TError>/\&lt;TError\&gt;/g' file.md
# 验证构建
cd docs && bun run build
```

View File

@ -0,0 +1,84 @@
#!/bin/bash
# 共享的模块配置
# 用于统一管理 GFramework 项目的模块映射关系
# 根据模块名获取源代码目录
get_source_dir() {
local MODULE="$1"
case "$MODULE" in
Core)
echo "GFramework.Core"
;;
Game)
echo "GFramework.Game"
;;
Godot)
echo "GFramework.Godot"
;;
SourceGenerators)
echo "GFramework.SourceGenerators"
;;
*)
echo ""
return 1
;;
esac
}
# 根据模块名获取文档输出目录
get_docs_dir() {
local MODULE="$1"
case "$MODULE" in
Core)
echo "docs/zh-CN/api-reference/core"
;;
Game)
echo "docs/zh-CN/api-reference/game"
;;
Godot)
echo "docs/zh-CN/api-reference/godot"
;;
SourceGenerators)
echo "docs/zh-CN/api-reference/source-generators"
;;
*)
echo ""
return 1
;;
esac
}
# 根据命名空间推断模块名
infer_module_from_namespace() {
local NAMESPACE="$1"
if [[ "$NAMESPACE" == GFramework.Core* ]]; then
echo "Core"
elif [[ "$NAMESPACE" == GFramework.Game* ]]; then
echo "Game"
elif [[ "$NAMESPACE" == GFramework.Godot* ]]; then
echo "Godot"
elif [[ "$NAMESPACE" == GFramework.SourceGenerators* ]]; then
echo "SourceGenerators"
else
echo ""
return 1
fi
}
# 获取所有可用模块列表
get_all_modules() {
echo "Core Game Godot SourceGenerators"
}
# 验证模块名是否有效
is_valid_module() {
local MODULE="$1"
case "$MODULE" in
Core|Game|Godot|SourceGenerators)
return 0
;;
*)
return 1
;;
esac
}

View File

@ -0,0 +1,121 @@
#!/bin/bash
# 生成代码示例辅助脚本
# 用法: generate-examples.sh <类型> <类名> [命名空间]
set -e
TYPE="$1" # class/interface/enum
CLASS_NAME="$2"
NAMESPACE="$3"
if [ -z "$TYPE" ] || [ -z "$CLASS_NAME" ]; then
echo "用法: $0 <类型> <类名> [命名空间]"
echo "类型: class, interface, enum"
exit 1
fi
echo "=========================================="
echo "代码示例生成指南"
echo "=========================================="
echo "类型: $TYPE"
echo "类名: $CLASS_NAME"
if [ -n "$NAMESPACE" ]; then
echo "命名空间: $NAMESPACE"
fi
echo ""
# 根据类型提供示例生成指南
case "$TYPE" in
class)
echo "## 类示例生成建议"
echo ""
echo "1. 基本用法示例:"
echo " - 实例化对象"
echo " - 调用主要方法"
echo " - 访问公共属性"
echo ""
echo "2. 常见场景示例:"
echo " - 实际应用案例"
echo " - 与其他组件的集成"
echo ""
echo "3. 高级用法示例(如适用):"
echo " - 复杂配置"
echo " - 扩展和自定义"
echo ""
echo "示例模板:"
echo '```csharp'
echo "// 创建实例"
echo "var instance = new $CLASS_NAME();"
echo ""
echo "// 使用主要功能"
echo "instance.MainMethod();"
echo '```'
;;
interface)
echo "## 接口示例生成建议"
echo ""
echo "1. 实现接口:"
echo " - 展示如何实现该接口"
echo " - 实现所有必需成员"
echo ""
echo "2. 使用接口:"
echo " - 通过接口类型使用实例"
echo " - 依赖注入场景"
echo ""
echo "示例模板:"
echo '```csharp'
echo "// 实现接口"
echo "public class My$CLASS_NAME : $CLASS_NAME"
echo "{"
echo " // 实现成员"
echo "}"
echo ""
echo "// 使用接口"
echo "$CLASS_NAME instance = new My$CLASS_NAME();"
echo '```'
;;
enum)
echo "## 枚举示例生成建议"
echo ""
echo "1. 基本用法:"
echo " - 枚举值赋值"
echo " - 值比较"
echo ""
echo "2. Switch 语句:"
echo " - 根据枚举值执行不同逻辑"
echo ""
echo "3. 枚举转换:"
echo " - 字符串转枚举"
echo " - 枚举转整数"
echo ""
echo "示例模板:"
echo '```csharp'
echo "// 使用枚举值"
echo "var value = $CLASS_NAME.SomeValue;"
echo ""
echo "// Switch 语句"
echo "switch (value)"
echo "{"
echo " case $CLASS_NAME.Value1:"
echo " // 处理逻辑"
echo " break;"
echo " case $CLASS_NAME.Value2:"
echo " // 处理逻辑"
echo " break;"
echo "}"
echo '```'
;;
*)
echo "错误: 不支持的类型: $TYPE"
exit 1
;;
esac
echo ""
echo "注意事项:"
echo "- 使用项目的命名约定"
echo "- 包含必要的 using 语句"
echo "- 确保示例代码可以编译运行"
echo "- 参考现有教程的代码风格"
exit 0

View File

@ -0,0 +1,48 @@
#!/bin/bash
# 解析 C# XML 文档注释
# 用法: parse-csharp-xml.sh <C# 文件路径>
set -e
FILE_PATH="$1"
if [ -z "$FILE_PATH" ]; then
echo "用法: $0 <C# 文件路径>"
exit 1
fi
if [ ! -f "$FILE_PATH" ]; then
echo "错误: 文件不存在: $FILE_PATH"
exit 1
fi
echo "解析 C# XML 文档注释: $FILE_PATH"
# 提取 summary 标签内容
echo "=== Summary ==="
grep -A 5 "/// <summary>" "$FILE_PATH" | grep "///" | sed 's/.*\/\/\/\s*//' | sed 's/<summary>//g' | sed 's/<\/summary>//g' || echo "未找到 summary"
# 提取 param 标签内容
echo ""
echo "=== Parameters ==="
grep "/// <param" "$FILE_PATH" | sed 's/.*\/\/\/\s*//' || echo "未找到 param"
# 提取 returns 标签内容
echo ""
echo "=== Returns ==="
grep "/// <returns>" "$FILE_PATH" | sed 's/.*\/\/\/\s*//' | sed 's/<returns>//g' | sed 's/<\/returns>//g' || echo "未找到 returns"
# 提取 exception 标签内容
echo ""
echo "=== Exceptions ==="
grep "/// <exception" "$FILE_PATH" | sed 's/.*\/\/\/\s*//' || echo "未找到 exception"
# 提取 example 标签内容
echo ""
echo "=== Examples ==="
grep -A 10 "/// <example>" "$FILE_PATH" | grep "///" | sed 's/.*\/\/\/\s*//' || echo "未找到 example"
echo ""
echo "解析完成"
exit 0

View File

@ -0,0 +1,57 @@
#!/bin/bash
# 更新 VitePress 侧边栏配置
# 用法: update-vitepress-nav.sh <文档路径> <文档标题>
set -e
DOC_PATH="$1"
DOC_TITLE="$2"
CONFIG_FILE="docs/.vitepress/config.mts"
if [ -z "$DOC_PATH" ] || [ -z "$DOC_TITLE" ]; then
echo "用法: $0 <文档路径> <文档标题>"
echo "示例: $0 /zh-CN/api-reference/core/architecture Architecture"
exit 1
fi
if [ ! -f "$CONFIG_FILE" ]; then
echo "错误: 找不到 VitePress 配置文件: $CONFIG_FILE"
exit 1
fi
# 提取模块名称core/game/godot/source-generators
MODULE=$(echo "$DOC_PATH" | grep -oP '(?<=/zh-CN/)[^/]+' | head -1)
if [ -z "$MODULE" ]; then
echo "错误: 无法从路径中提取模块名称: $DOC_PATH"
exit 1
fi
echo "=========================================="
echo "VitePress 导航配置更新"
echo "=========================================="
echo "模块: $MODULE"
echo "路径: $DOC_PATH"
echo "标题: $DOC_TITLE"
echo ""
# 检查配置文件中是否已存在该路径
if grep -q "link: '$DOC_PATH'" "$CONFIG_FILE"; then
echo "✓ 该文档已存在于导航配置中"
exit 0
fi
echo "提示: 需要在 VitePress 配置中添加新条目"
echo ""
echo "建议的配置条目:"
echo "{ text: '$DOC_TITLE', link: '$DOC_PATH' }"
echo ""
echo "请使用以下方式之一更新配置:"
echo "1. 让 AI 使用 Edit 工具直接修改 $CONFIG_FILE"
echo "2. 手动编辑配置文件并添加上述条目到对应的 sidebar 部分"
echo ""
# 输出相关的 sidebar 配置路径
echo "相关的 sidebar 配置路径: '/zh-CN/$MODULE/'"
exit 0

View File

@ -0,0 +1,210 @@
# VitePress API 文档生成
为单个 C# 类、接口或枚举生成符合 VitePress 标准的 API 参考文档。
## 用途
此 skill 用于从 C# 源代码文件自动生成结构化的 API 文档,包括:
- 类型概述和命名空间信息
- 构造函数、方法、属性的详细说明
- 基于 XML 文档注释的描述
- 自动生成的使用示例
- 相关类型的交叉引用
## 调用方式
```bash
/vitepress-api-doc <C# 文件路径>
```
**示例**
```bash
/vitepress-api-doc GFramework.Core/architecture/Architecture.cs
```
## 工作流程
1. **读取源代码文件**
- 验证文件存在且为 C# 文件
- 读取完整的源代码内容
2. **解析代码结构**
- 提取命名空间、类名、访问修饰符
- 识别类型class/interface/enum/struct
- 解析继承关系和实现的接口
- 提取所有公共成员(构造函数、方法、属性、事件、字段)
3. **提取 XML 文档注释**
- 解析 `/// <summary>` 标签(类型和成员描述)
- 解析 `/// <param>` 标签(参数说明)
- 解析 `/// <returns>` 标签(返回值说明)
- 解析 `/// <exception>` 标签(异常说明)
- 解析 `/// <example>` 标签(示例代码)
- 解析 `/// <see cref=""/>` 标签(交叉引用)
4. **生成 Markdown 文档**
- 根据 `template.md` 填充内容
- 转义泛型符号(`<T>``&lt;T&gt;`
- 生成使用示例(基于 API 签名)
- 添加相关文档链接
5. **确定输出路径**
- 根据命名空间确定模块Core/Game/Godot/SourceGenerators
- 输出到 `docs/zh-CN/api-reference/<模块>/<类名>.md`
6. **更新 VitePress 配置**
- 调用共享脚本 `update-vitepress-nav.sh`
- 在侧边栏配置中添加新文档条目
7. **验证文档质量**
- 检查 Frontmatter 格式
- 验证内部链接
- 确保代码块语法正确
## 输出规范
### Frontmatter 格式
```yaml
---
title: 类名
description: 从 XML <summary> 提取的简短描述
outline: deep
---
```
### 文档结构
1. **标题**:使用类名作为一级标题
2. **概述**XML summary 内容
3. **命名空间和程序集信息**
4. **继承链**(如果适用)
5. **构造函数**(如果有)
6. **公共方法**(按字母顺序)
7. **公共属性**(按字母顺序)
8. **公共事件**(如果有)
9. **使用示例**(自动生成)
10. **另请参阅**(相关类型链接)
### 代码块格式
所有 C# 代码块必须使用:
```markdown
\`\`\`csharp
// 代码内容
\`\`\`
```
### 泛型符号转义
- `List<T>``List&lt;T&gt;`
- `Dictionary<K, V>``Dictionary&lt;K, V&gt;`
- `IEnumerable<T>``IEnumerable&lt;T&gt;`
### 内部链接格式
- 相对路径:`[Architecture](./architecture.md)`
- 绝对路径:`[Core 架构](/zh-CN/core/architecture)`
- 锚点链接:`[构造函数](#构造函数)`
## 前置条件
1. 项目必须有 VitePress 配置文件(`docs/.vitepress/config.mts`
2. 目标 C# 文件必须存在且可读
3. C# 文件必须包含 XML 文档注释(`///`
4. 文件必须包含至少一个公共类型
## 配置选项
### 自动检测模块
根据命名空间自动确定模块:
- `GFramework.Core.*``core`
- `GFramework.Game.*``game`
- `GFramework.Godot.*``godot`
- `GFramework.SourceGenerators.*``source-generators`
### 示例生成策略
- **基本用法**:最简单的 API 调用
- **常见场景**:实际应用案例
- **高级用法**:复杂配置(如果适用)
## 示例输出
参考 `examples/` 目录中的示例文档:
- `class-example.md` - 类文档示例
- `interface-example.md` - 接口文档示例
- `enum-example.md` - 枚举文档示例
## 注意事项
1. **仅使用 XML 注释**:不对缺失的注释进行 AI 补充
2. **仅提取公共成员**:忽略 `internal``private``protected` 成员
3. **保持文档同步**:文档内容直接来源于代码,确保准确性
4. **遵循项目风格**:参考现有文档的格式和术语
## 相关 Skills
- `/vitepress-validate` - 验证生成的文档质量
- `/vitepress-batch-api` - 批量生成整个模块的 API 文档
## 技术细节
### XML 注释标签映射
| XML 标签 | Markdown 输出 |
|---------|--------------|
| `<summary>` | 概述章节 |
| `<param name="x">` | 参数列表 |
| `<returns>` | 返回值说明 |
| `<exception cref="T">` | 异常列表 |
| `<example>` | 示例代码块 |
| `<see cref="T"/>` | 内部链接 |
| `<remarks>` | 备注章节 |
### 成员签名格式
**方法**
```markdown
### MethodName
描述内容
**签名**
\`\`\`csharp
public ReturnType MethodName(ParamType param)
\`\`\`
**参数**
- `param` (ParamType): 参数说明
**返回值**
- (ReturnType): 返回值说明
```
**属性**
```markdown
### PropertyName
描述内容
**类型**`PropertyType`
**访问**get / set
```
## 故障排除
### 问题:找不到 XML 注释
**解决方案**:确保 C# 文件包含 `///` 注释,而不是 `//``/* */`
### 问题:泛型符号显示错误
**解决方案**VitePress 配置中已包含 `safeGenericEscapePlugin`,确保正确转义
### 问题:侧边栏未更新
**解决方案**:检查 `update-vitepress-nav.sh` 脚本是否正确执行
## 版本历史
- v1.0.0 - 初始版本,支持类、接口、枚举的文档生成

View File

@ -0,0 +1,252 @@
---
title: Architecture
description: 架构基类,提供系统、模型、工具等组件的注册与管理功能。专注于生命周期管理、初始化流程控制和架构阶段转换。
outline: deep
---
# Architecture
## 概述
架构基类,提供系统、模型、工具等组件的注册与管理功能。专注于生命周期管理、初始化流程控制和架构阶段转换。
**命名空间**`GFramework.Core.architecture`
**程序集**`GFramework.Core`
**继承**`Object``Architecture`
**实现**`IArchitecture`
## 构造函数
### Architecture
创建架构实例。
**签名**
```csharp
public Architecture(
IArchitectureConfiguration? configuration = null,
IEnvironment? environment = null,
IArchitectureServices? services = null,
IArchitectureContext? context = null
)
```
**参数**
- `configuration` (IArchitectureConfiguration?): 架构配置对象,为 null 时使用默认配置
- `environment` (IEnvironment?): 环境配置对象,为 null 时使用默认环境
- `services` (IArchitectureServices?): 架构服务对象,为 null 时创建新实例
- `context` (IArchitectureContext?): 架构上下文对象,为 null 时创建新实例
## 公共方法
### Initialize
同步初始化架构,阻塞当前线程直到初始化完成。
**签名**
```csharp
public void Initialize()
```
**特点**
- 阻塞式初始化
- 适用于简单场景或控制台应用
- 初始化失败时抛出异常并进入 `FailedInitialization` 阶段
### InitializeAsync
异步初始化架构,返回 Task 以便调用者可以等待初始化完成。
**签名**
```csharp
public async Task InitializeAsync()
```
**返回值**
- (Task): 表示异步初始化操作的任务
**特点**
- 非阻塞式初始化
- 支持异步组件初始化
- 适用于需要异步加载资源的场景
### InstallModule
安装架构模块,用于扩展架构功能。
**签名**
```csharp
public IArchitectureModule InstallModule(IArchitectureModule module)
```
**参数**
- `module` (IArchitectureModule): 要安装的模块实例
**返回值**
- (IArchitectureModule): 返回安装的模块实例
### RegisterSystem
注册系统组件到架构中。
**签名**
```csharp
public void RegisterSystem<TSystem>(TSystem system) where TSystem : ISystem
```
**类型参数**
- `TSystem`: 系统类型,必须实现 ISystem 接口
**参数**
- `system` (TSystem): 要注册的系统实例
### RegisterModel
注册模型组件到架构中。
**签名**
```csharp
public void RegisterModel<TModel>(TModel model) where TModel : IModel
```
**类型参数**
- `TModel`: 模型类型,必须实现 IModel 接口
**参数**
- `model` (TModel): 要注册的模型实例
### RegisterUtility
注册工具组件到架构中。
**签名**
```csharp
public void RegisterUtility<TUtility>(TUtility utility) where TUtility : IUtility
```
**类型参数**
- `TUtility`: 工具类型,必须实现 IUtility 接口
**参数**
- `utility` (TUtility): 要注册的工具实例
### SendCommand
发送并执行命令。
**签名**
```csharp
public void SendCommand(ICommand command)
```
**参数**
- `command` (ICommand): 要执行的命令实例
### SendCommand&lt;TResult&gt;
发送并执行带返回值的命令。
**签名**
```csharp
public TResult SendCommand<TResult>(ICommand<TResult> command)
```
**类型参数**
- `TResult`: 命令返回值类型
**参数**
- `command` (ICommand&lt;TResult&gt;): 要执行的命令实例
**返回值**
- (TResult): 命令执行结果
## 公共属性
### CurrentPhase
获取当前架构的阶段。
**类型**`ArchitecturePhase`
**访问**get
### Context
获取架构上下文,提供对架构服务的访问。
**类型**`IArchitectureContext`
**访问**get
### IsReady
获取一个布尔值,指示当前架构是否处于就绪状态。
**类型**`bool`
**访问**get
## 使用示例
### 基本用法
```csharp
// 1. 定义你的架构(继承 Architecture 基类)
public class GameArchitecture : Architecture
{
protected override void Init()
{
// 注册 Model
RegisterModel(new PlayerModel());
RegisterModel(new InventoryModel());
// 注册 System
RegisterSystem(new GameplaySystem());
RegisterSystem(new SaveSystem());
// 注册 Utility
RegisterUtility(new StorageUtility());
RegisterUtility(new TimeUtility());
}
}
// 2. 创建并初始化架构
var architecture = new GameArchitecture();
architecture.Initialize();
// 3. 等待架构就绪
await architecture.WaitUntilReadyAsync();
```
### 异步初始化
```csharp
var architecture = new GameArchitecture();
await architecture.InitializeAsync(); // 异步等待初始化完成
// 检查架构是否已就绪
if (architecture.IsReady)
{
Console.WriteLine("架构已就绪,可以开始游戏");
}
```
### 使用自定义配置
```csharp
var config = new ArchitectureConfiguration
{
ArchitectureProperties = new ArchitectureProperties
{
StrictPhaseValidation = true, // 启用严格阶段验证
AllowLateRegistration = false // 禁止就绪后注册组件
}
};
var architecture = new GameArchitecture(configuration: config);
architecture.Initialize();
```
## 另请参阅
- [IArchitecture](./iarchitecture.md) - 架构接口
- [ArchitecturePhase](./architecture-phase.md) - 架构阶段枚举
- [IArchitectureModule](./iarchitecture-module.md) - 架构模块接口
- [架构组件](/zh-CN/core/architecture) - 架构使用指南

View File

@ -0,0 +1,193 @@
---
title: ArchitecturePhase
description: 架构阶段枚举,定义了架构生命周期的各个阶段。
outline: deep
---
# ArchitecturePhase
## 概述
架构阶段枚举,定义了架构生命周期的各个阶段。
**命名空间**`GFramework.Core.Abstractions.enums`
**程序集**`GFramework.Core.Abstractions`
**基础类型**`Enum`
## 枚举值
### None
初始阶段,架构尚未开始初始化。
**值**`0`
### BeforeUtilityInit
工具初始化前阶段。
**值**`1`
### AfterUtilityInit
工具初始化后阶段。
**值**`2`
### BeforeModelInit
模型初始化前阶段。
**值**`3`
### AfterModelInit
模型初始化后阶段。
**值**`4`
### BeforeSystemInit
系统初始化前阶段。
**值**`5`
### AfterSystemInit
系统初始化后阶段。
**值**`6`
### Ready
就绪状态,架构已完全初始化并可以使用。
**值**`7`
### FailedInitialization
初始化失败状态。
**值**`8`
### Destroying
正在销毁阶段。
**值**`9`
### Destroyed
已销毁阶段。
**值**`10`
## 使用示例
### 检查架构阶段
```csharp
var architecture = new GameArchitecture();
architecture.Initialize();
// 检查架构是否已就绪
if (architecture.CurrentPhase == ArchitecturePhase.Ready)
{
Console.WriteLine("架构已就绪,可以开始游戏");
}
```
### 监听阶段变化
```csharp
public class PhaseMonitor : IArchitectureLifecycle
{
public void OnPhase(ArchitecturePhase phase, IArchitecture architecture)
{
switch (phase)
{
case ArchitecturePhase.BeforeUtilityInit:
Console.WriteLine("开始初始化工具");
break;
case ArchitecturePhase.AfterUtilityInit:
Console.WriteLine("工具初始化完成");
break;
case ArchitecturePhase.BeforeModelInit:
Console.WriteLine("开始初始化模型");
break;
case ArchitecturePhase.AfterModelInit:
Console.WriteLine("模型初始化完成");
break;
case ArchitecturePhase.BeforeSystemInit:
Console.WriteLine("开始初始化系统");
break;
case ArchitecturePhase.AfterSystemInit:
Console.WriteLine("系统初始化完成");
break;
case ArchitecturePhase.Ready:
Console.WriteLine("架构就绪");
break;
case ArchitecturePhase.FailedInitialization:
Console.WriteLine("架构初始化失败");
break;
case ArchitecturePhase.Destroying:
Console.WriteLine("架构正在销毁");
break;
case ArchitecturePhase.Destroyed:
Console.WriteLine("架构已销毁");
break;
}
}
}
// 注册监听器
var architecture = new GameArchitecture();
architecture.RegisterLifecycleHook(new PhaseMonitor());
architecture.Initialize();
```
### 等待特定阶段
```csharp
public async Task WaitForReady(IArchitecture architecture)
{
while (architecture.CurrentPhase != ArchitecturePhase.Ready)
{
if (architecture.CurrentPhase == ArchitecturePhase.FailedInitialization)
{
throw new Exception("架构初始化失败");
}
await Task.Delay(100);
}
Console.WriteLine("架构已就绪");
}
```
## 阶段转换顺序
正常初始化流程的阶段转换顺序:
1. `None``BeforeUtilityInit`
2. `BeforeUtilityInit``AfterUtilityInit`
3. `AfterUtilityInit``BeforeModelInit`
4. `BeforeModelInit``AfterModelInit`
5. `AfterModelInit``BeforeSystemInit`
6. `BeforeSystemInit``AfterSystemInit`
7. `AfterSystemInit``Ready`
销毁流程的阶段转换顺序:
1. `Ready``Destroying`
2. `Destroying``Destroyed`
异常流程:
- 任何阶段 → `FailedInitialization`(初始化过程中发生异常)
## 另请参阅
- [Architecture](./architecture.md) - 架构基类
- [IArchitectureLifecycle](./iarchitecture-lifecycle.md) - 生命周期钩子接口
- [架构组件](/zh-CN/core/architecture) - 架构使用指南

View File

@ -0,0 +1,290 @@
---
title: IArchitecture
description: 架构接口,定义了框架的核心功能契约。
outline: deep
---
# IArchitecture
## 概述
架构接口,定义了框架的核心功能契约。
**命名空间**`GFramework.Core.Abstractions.architecture`
**程序集**`GFramework.Core.Abstractions`
**实现类**[Architecture](./architecture.md)
## 公共方法
### RegisterSystem&lt;TSystem&gt;
注册系统组件到架构中。
**签名**
```csharp
void RegisterSystem<TSystem>(TSystem system) where TSystem : ISystem
```
**类型参数**
- `TSystem`: 系统类型,必须实现 ISystem 接口
**参数**
- `system` (TSystem): 要注册的系统实例
### RegisterModel&lt;TModel&gt;
注册模型组件到架构中。
**签名**
```csharp
void RegisterModel<TModel>(TModel model) where TModel : IModel
```
**类型参数**
- `TModel`: 模型类型,必须实现 IModel 接口
**参数**
- `model` (TModel): 要注册的模型实例
### RegisterUtility&lt;TUtility&gt;
注册工具组件到架构中。
**签名**
```csharp
void RegisterUtility<TUtility>(TUtility utility) where TUtility : IUtility
```
**类型参数**
- `TUtility`: 工具类型,必须实现 IUtility 接口
**参数**
- `utility` (TUtility): 要注册的工具实例
### GetModel&lt;T&gt;
从容器中获取已注册的模型。
**签名**
```csharp
T GetModel<T>() where T : class, IModel
```
**类型参数**
- `T`: 模型类型
**返回值**
- (T): 模型实例
### GetSystem&lt;T&gt;
从容器中获取已注册的系统。
**签名**
```csharp
T GetSystem<T>() where T : class, ISystem
```
**类型参数**
- `T`: 系统类型
**返回值**
- (T): 系统实例
### GetUtility&lt;T&gt;
从容器中获取已注册的工具。
**签名**
```csharp
T GetUtility<T>() where T : class, IUtility
```
**类型参数**
- `T`: 工具类型
**返回值**
- (T): 工具实例
### SendCommand
发送并执行命令。
**签名**
```csharp
void SendCommand(ICommand command)
```
**参数**
- `command` (ICommand): 要执行的命令实例
### SendCommand&lt;TResult&gt;
发送并执行带返回值的命令。
**签名**
```csharp
TResult SendCommand<TResult>(ICommand<TResult> command)
```
**类型参数**
- `TResult`: 命令返回值类型
**参数**
- `command` (ICommand&lt;TResult&gt;): 要执行的命令实例
**返回值**
- (TResult): 命令执行结果
### SendQuery&lt;TResult&gt;
发送并执行查询。
**签名**
```csharp
TResult SendQuery<TResult>(IQuery<TResult> query)
```
**类型参数**
- `TResult`: 查询返回值类型
**参数**
- `query` (IQuery&lt;TResult&gt;): 要执行的查询实例
**返回值**
- (TResult): 查询结果
### SendEvent&lt;T&gt;
发送事件(无参数)。
**签名**
```csharp
void SendEvent<T>() where T : new()
```
**类型参数**
- `T`: 事件类型,必须有无参构造函数
### SendEvent&lt;T&gt;
发送事件(带参数)。
**签名**
```csharp
void SendEvent<T>(T e)
```
**类型参数**
- `T`: 事件类型
**参数**
- `e` (T): 事件实例
### RegisterEvent&lt;T&gt;
注册事件监听器。
**签名**
```csharp
IUnRegister RegisterEvent<T>(Action<T> onEvent)
```
**类型参数**
- `T`: 事件类型
**参数**
- `onEvent` (Action&lt;T&gt;): 事件处理回调
**返回值**
- (IUnRegister): 用于注销事件的对象
### UnRegisterEvent&lt;T&gt;
注销事件监听器。
**签名**
```csharp
void UnRegisterEvent<T>(Action<T> onEvent)
```
**类型参数**
- `T`: 事件类型
**参数**
- `onEvent` (Action&lt;T&gt;): 要注销的事件处理回调
## 公共属性
### CurrentPhase
获取当前架构的阶段。
**类型**`ArchitecturePhase`
**访问**get
### Context
获取架构上下文。
**类型**`IArchitectureContext`
**访问**get
## 使用示例
### 在 Controller 中使用
```csharp
public class GameController : IController
{
public IArchitecture GetArchitecture() => GameArchitecture.Interface;
public void Start()
{
// 获取 Model
var playerModel = this.GetModel<PlayerModel>();
// 发送命令
this.SendCommand(new StartGameCommand());
// 发送查询
var score = this.SendQuery(new GetScoreQuery());
// 注册事件
this.RegisterEvent<PlayerDiedEvent>(OnPlayerDied);
}
private void OnPlayerDied(PlayerDiedEvent e)
{
// 处理玩家死亡事件
}
}
```
### 实现自定义架构
```csharp
public class GameArchitecture : Architecture
{
// 单例访问
public static IArchitecture Interface { get; private set; }
protected override void Init()
{
Interface = this;
// 注册组件
RegisterModel(new PlayerModel());
RegisterSystem(new GameplaySystem());
RegisterUtility(new StorageUtility());
}
}
```
## 另请参阅
- [Architecture](./architecture.md) - 架构基类实现
- [IModel](./imodel.md) - 模型接口
- [ISystem](./isystem.md) - 系统接口
- [IUtility](./iutility.md) - 工具接口
- [架构组件](/zh-CN/core/architecture) - 架构使用指南

View File

@ -0,0 +1,37 @@
---
title: {{CLASS_NAME}}
description: {{XML_SUMMARY}}
outline: deep
---
# {{CLASS_NAME}}
## 概述
{{XML_SUMMARY}}
**命名空间**`{{NAMESPACE}}`
**程序集**`{{ASSEMBLY}}`
{{INHERITANCE_CHAIN}}
## 构造函数
{{CONSTRUCTORS}}
## 公共方法
{{PUBLIC_METHODS}}
## 公共属性
{{PUBLIC_PROPERTIES}}
{{PUBLIC_EVENTS}}
## 使用示例
{{AUTO_GENERATED_EXAMPLES}}
## 另请参阅
{{RELATED_TYPES}}

View File

@ -0,0 +1,364 @@
# VitePress 批量 API 文档生成
为整个模块批量生成 API 参考文档,提高文档生成效率。
## 用途
此 skill 用于批量生成模块的 API 文档,适用于:
- 初始化模块文档
- 更新整个模块的文档
- 为新模块快速生成文档
- 重新生成所有 API 文档
## 调用方式
```bash
/vitepress-batch-api <模块名>
```
**示例**
```bash
/vitepress-batch-api Core
/vitepress-batch-api Game
/vitepress-batch-api Godot
/vitepress-batch-api SourceGenerators
```
## 工作流程
1. **扫描模块目录**
- 根据模块名确定源代码目录
- 递归扫描所有 C# 文件
2. **过滤目标文件**
- 仅包含公共类型public class/interface/enum/struct
- 排除内部类型internal
- 排除生成的代码(*.g.cs、*.Designer.cs
- 排除测试文件(*.Tests.cs
3. **批量生成文档**
- 为每个类型调用 `/vitepress-api-doc`
- 显示进度信息
- 收集生成结果
4. **生成模块索引页**
- 创建 `index.md` 列出所有 API
- 按类别分组(类、接口、枚举)
- 添加简短描述
5. **批量更新导航**
- 在 VitePress 配置中添加所有新文档
- 保持字母顺序
- 更新模块索引
6. **生成摘要报告**
- 统计生成的文档数量
- 列出成功和失败的文件
- 提供验证建议
## 输出规范
### 模块索引页格式
```markdown
---
title: Core API 参考
description: GFramework.Core 模块的 API 参考文档
---
# Core API 参考
## 概述
GFramework.Core 是框架的核心模块,提供架构基础、依赖注入、事件系统等核心功能。
## 类
- [Architecture](./architecture.md) - 架构基类
- [ArchitectureConfiguration](./architecture-configuration.md) - 架构配置
- [IocContainer](./ioc-container.md) - IoC 容器
## 接口
- [IArchitecture](./iarchitecture.md) - 架构接口
- [IModel](./imodel.md) - 模型接口
- [ISystem](./isystem.md) - 系统接口
## 枚举
- [ArchitecturePhase](./architecture-phase.md) - 架构阶段
```
### 目录结构
```
docs/zh-CN/api-reference/
├── core/
│ ├── index.md # 模块索引
│ ├── architecture.md
│ ├── iarchitecture.md
│ └── ...
├── game/
│ ├── index.md
│ └── ...
└── godot/
├── index.md
└── ...
```
## 模块映射
### 源代码目录映射
| 模块名 | 源代码目录 | 输出目录 |
|--------|-----------|---------|
| Core | `GFramework.Core/` | `docs/zh-CN/api-reference/core/` |
| Game | `GFramework.Game/` | `docs/zh-CN/api-reference/game/` |
| Godot | `GFramework.Godot/` | `docs/zh-CN/api-reference/godot/` |
| SourceGenerators | `GFramework.SourceGenerators/` | `docs/zh-CN/api-reference/source-generators/` |
### 命名空间映射
- `GFramework.Core.*` → Core 模块
- `GFramework.Game.*` → Game 模块
- `GFramework.Godot.*` → Godot 模块
- `GFramework.SourceGenerators.*` → SourceGenerators 模块
## 过滤规则
### 包含的文件
- 公共类public class
- 公共接口public interface
- 公共枚举public enum
- 公共结构体public struct
### 排除的文件
- 内部类型internal
- 生成的代码(`*.g.cs``*.Designer.cs`
- 测试文件(`*.Tests.cs``*Test.cs`
- 临时文件(`*.tmp.cs`
- 编译器生成的文件(`AssemblyInfo.cs`
### 排除的类型
- 编译器生成的类型(`<>c__DisplayClass`
- 匿名类型
- 嵌套的私有类型
## 批量处理脚本
### batch-generate.sh
```bash
#!/bin/bash
# 批量生成 API 文档
# 用法: batch-generate.sh <模块名>
set -e
MODULE="$1"
if [ -z "$MODULE" ]; then
echo "用法: $0 <模块名>"
echo "可用模块: Core, Game, Godot, SourceGenerators"
exit 1
fi
# 确定源代码目录
case "$MODULE" in
Core)
SOURCE_DIR="GFramework.Core"
;;
Game)
SOURCE_DIR="GFramework.Game"
;;
Godot)
SOURCE_DIR="GFramework.Godot"
;;
SourceGenerators)
SOURCE_DIR="GFramework.SourceGenerators"
;;
*)
echo "错误: 未知的模块: $MODULE"
exit 1
;;
esac
if [ ! -d "$SOURCE_DIR" ]; then
echo "错误: 源代码目录不存在: $SOURCE_DIR"
exit 1
fi
echo "=========================================="
echo "批量生成 $MODULE 模块的 API 文档"
echo "=========================================="
echo ""
# 查找所有 C# 文件
FILES=$(find "$SOURCE_DIR" -name "*.cs" -type f \
! -name "*.g.cs" \
! -name "*.Designer.cs" \
! -name "*Test.cs" \
! -name "*.Tests.cs" \
! -name "AssemblyInfo.cs")
FILE_COUNT=$(echo "$FILES" | wc -l)
echo "找到 $FILE_COUNT 个文件"
echo ""
GENERATED=0
SKIPPED=0
FAILED=0
for FILE in $FILES; do
echo "处理: $FILE"
# 检查是否包含公共类型
if ! grep -q "public \(class\|interface\|enum\|struct\)" "$FILE"; then
echo " ⊘ 跳过(无公共类型)"
SKIPPED=$((SKIPPED + 1))
continue
fi
# 调用 vitepress-api-doc由 AI 执行)
# /vitepress-api-doc "$FILE"
if [ $? -eq 0 ]; then
echo " ✓ 生成成功"
GENERATED=$((GENERATED + 1))
else
echo " ✗ 生成失败"
FAILED=$((FAILED + 1))
fi
echo ""
done
echo "=========================================="
echo "批量生成完成"
echo "=========================================="
echo "总文件数: $FILE_COUNT"
echo "生成成功: $GENERATED"
echo "跳过: $SKIPPED"
echo "失败: $FAILED"
echo ""
if [ $FAILED -eq 0 ]; then
echo "✓ 所有文档生成成功"
exit 0
else
echo "✗ 部分文档生成失败"
exit 1
fi
```
## 配置选项
### 过滤选项
```bash
# 包含内部类型
/vitepress-batch-api Core --include-internal
# 包含生成的代码
/vitepress-batch-api Core --include-generated
# 自定义过滤规则
/vitepress-batch-api Core --exclude "*.Tests.cs" --exclude "*.g.cs"
```
### 输出选项
```bash
# 指定输出目录
/vitepress-batch-api Core --output docs/zh-CN/api-reference/core/
# 覆盖现有文档
/vitepress-batch-api Core --force
# 仅生成索引页
/vitepress-batch-api Core --index-only
```
### 并行处理
```bash
# 并行生成(加快速度)
/vitepress-batch-api Core --parallel 4
```
## 进度显示
### 实时进度
```
========================================
批量生成 Core 模块的 API 文档
========================================
找到 45 个文件
[1/45] 处理: GFramework.Core/architecture/Architecture.cs
✓ 生成成功
[2/45] 处理: GFramework.Core/architecture/IArchitecture.cs
✓ 生成成功
[3/45] 处理: GFramework.Core/command/Command.cs
⊘ 跳过(无公共类型)
...
[45/45] 处理: GFramework.Core/utility/Utility.cs
✓ 生成成功
========================================
批量生成完成
========================================
总文件数: 45
生成成功: 38
跳过: 5
失败: 2
✗ 部分文档生成失败
失败的文件:
- GFramework.Core/internal/InternalClass.cs (缺少 XML 注释)
- GFramework.Core/legacy/LegacyClass.cs (解析错误)
```
## 前置条件
1. 模块源代码目录存在
2. 源代码文件包含 XML 文档注释
3. 有足够的磁盘空间存储生成的文档
## 相关 Skills
- `/vitepress-api-doc` - 单文件 API 文档生成
- `/vitepress-validate` - 验证生成的文档
- `/vitepress-guide` - 生成功能指南
## 最佳实践
1. **首次生成**:使用批量生成快速创建所有文档
2. **增量更新**:修改代码后使用单文件生成更新对应文档
3. **定期验证**:批量生成后运行验证确保质量
4. **版本控制**:将生成的文档提交到版本控制系统
## 故障排除
### 问题:部分文件生成失败
**解决方案**:检查失败文件的 XML 注释是否完整,手动修复后重新生成
### 问题:生成速度慢
**解决方案**:使用 `--parallel` 选项启用并行处理
### 问题:生成的文档过多
**解决方案**:使用过滤选项排除不需要的文件
## 版本历史
- v1.0.0 - 初始版本,支持批量 API 文档生成

View File

@ -0,0 +1,81 @@
#!/bin/bash
# 批量生成 API 文档
# 用法: batch-generate.sh <模块名>
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=../../_shared/module-config.sh
source "$SCRIPT_DIR/../../_shared/module-config.sh"
MODULE="$1"
if [ -z "$MODULE" ]; then
echo "用法: $0 <模块名>"
echo "可用模块: $(get_all_modules)"
exit 1
fi
# 验证模块名
if ! is_valid_module "$MODULE"; then
echo "错误: 未知的模块: $MODULE"
echo "可用模块: $(get_all_modules)"
exit 1
fi
# 获取源代码目录
SOURCE_DIR=$(get_source_dir "$MODULE")
if [ ! -d "$SOURCE_DIR" ]; then
echo "错误: 源代码目录不存在: $SOURCE_DIR"
exit 1
fi
echo "=========================================="
echo "批量生成 $MODULE 模块的 API 文档"
echo "=========================================="
echo ""
# 查找所有 C# 文件
mapfile -t FILES < <(find "$SOURCE_DIR" -name "*.cs" -type f \
! -name "*.g.cs" \
! -name "*.Designer.cs" \
! -name "*Test.cs" \
! -name "*.Tests.cs" \
! -name "AssemblyInfo.cs")
FILE_COUNT=${#FILES[@]}
echo "找到 $FILE_COUNT 个文件"
echo ""
GENERATED=0
SKIPPED=0
FAILED=0
for FILE in "${FILES[@]}"; do
echo "处理: $FILE"
# 检查是否包含公共类型
if ! grep -q "public \(class\|interface\|enum\|struct\)" "$FILE"; then
echo " ⊘ 跳过(无公共类型)"
SKIPPED=$((SKIPPED + 1))
continue
fi
# 注意: 实际的文档生成由 AI 调用 /vitepress-api-doc 完成
# 此脚本仅用于扫描和过滤文件
echo " → 待生成"
GENERATED=$((GENERATED + 1))
echo ""
done
echo "=========================================="
echo "扫描完成"
echo "=========================================="
echo "总文件数: $FILE_COUNT"
echo "待生成: $GENERATED"
echo "跳过: $SKIPPED"
echo ""
exit 0

View File

@ -0,0 +1,52 @@
---
name: vitepress-doc-generator
description: Generate standardized VitePress documentation from source code.
disable-model-invocation: true
---
# Role
You are a technical documentation generator specialized in VitePress.
# Objective
Analyze the provided code context and generate a structured VitePress-compatible Markdown document.
# Output Requirements
1. Output MUST be valid Markdown only.
2. Include frontmatter:
---
title: <Module Name>
outline: deep
---
3. No explanations.
4. No conversational text.
5. No emoji.
6. Use Chinese.
7. Use structured headings.
# Required Structure
# 模块概述
- 模块职责
- 设计目标
# 核心类说明
## 类名
### 职责
### 主要方法
### 依赖关系
# 设计模式分析
# 可扩展性说明
# 使用示例(如适用)
# Self-Validation
Before returning output, verify:
- Frontmatter exists
- All required sections exist
- No extra commentary text

View File

@ -0,0 +1,256 @@
# VitePress 功能指南生成
生成功能模块的使用指南文档,包括概念说明、用法示例和最佳实践。
## 用途
此 skill 用于生成结构化的功能指南文档,适用于:
- 核心功能模块的使用说明
- 设计模式和架构概念
- 系统功能的详细介绍
- 最佳实践和常见问题
## 调用方式
```bash
/vitepress-guide <主题> <目标模块>
```
**示例**
```bash
/vitepress-guide "事件系统" Core
/vitepress-guide "IoC 容器" Core
/vitepress-guide "Godot 节点扩展" Godot
```
## 工作流程
1. **收集需求**
- 询问用户指南主题
- 确定目标受众(初学者/进阶/专家)
- 了解重点内容(概念/用法/最佳实践)
2. **搜索相关资源**
- 搜索相关代码文件
- 查找现有文档
- 识别相关类型和接口
3. **生成指南结构**
- 根据 `template.md` 创建文档框架
- 填充概述和核心概念
- 添加基本用法和高级用法
- 补充最佳实践和常见问题
4. **生成代码示例**
- 基本用法示例(最简单的场景)
- 常见场景示例(实际应用)
- 高级用法示例(复杂配置)
5. **确定输出路径**
- 保存到 `docs/zh-CN/<模块>/`
- 文件名使用小写加连字符(如 `event-system.md`
6. **更新导航配置**
- 在 VitePress 侧边栏中添加新指南
## 输出规范
### Frontmatter 格式
```yaml
---
title: 指南标题
description: 简短描述1-2 句话)
---
```
### 文档结构
1. **概述**:功能的简介和用途
2. **核心概念**:关键概念和术语解释
3. **基本用法**:最简单的使用方式
4. **高级用法**:复杂场景和配置
5. **最佳实践**:推荐的使用方式
6. **常见问题**FAQ 和故障排除
### 章节示例
**概述**
```markdown
## 概述
事件系统提供了一种松耦合的组件间通信机制。通过事件,不同的组件可以在不直接引用彼此的情况下进行交互。
**主要特性**
- 类型安全的事件
- 自动内存管理
- 支持事件优先级
- 线程安全
```
**核心概念**
```markdown
## 核心概念
### 事件类型
事件是一个普通的 C# 类,用于携带事件数据:
\`\`\`csharp
public class PlayerDiedEvent
{
public int PlayerId { get; set; }
public string Reason { get; set; }
}
\`\`\`
### 事件发送
通过架构发送事件:
\`\`\`csharp
this.SendEvent(new PlayerDiedEvent
{
PlayerId = 1,
Reason = "Fall damage"
});
\`\`\`
### 事件监听
注册事件监听器:
\`\`\`csharp
this.RegisterEvent<PlayerDiedEvent>(OnPlayerDied);
\`\`\`
```
## 模板变量
- `{{GUIDE_TITLE}}` - 指南标题
- `{{GUIDE_DESCRIPTION}}` - 简短描述
- `{{OVERVIEW}}` - 概述内容
- `{{CORE_CONCEPTS}}` - 核心概念
- `{{BASIC_USAGE}}` - 基本用法
- `{{ADVANCED_USAGE}}` - 高级用法
- `{{BEST_PRACTICES}}` - 最佳实践
- `{{FAQ}}` - 常见问题
## 示例输出
参考 `examples/guide-example.md`,该示例基于现有的 IoC 容器文档创建。
## 内容要求
### 概述部分
- 1-2 段简介
- 列出主要特性3-5 个)
- 说明适用场景
### 核心概念部分
- 使用三级标题(###)分隔不同概念
- 每个概念包含简短说明和代码示例
- 解释关键术语
### 基本用法部分
- 提供完整的可运行示例
- 从最简单的场景开始
- 逐步增加复杂度
- 包含必要的 using 语句
### 高级用法部分
- 展示复杂场景
- 说明配置选项
- 提供性能优化建议
### 最佳实践部分
- 使用编号列表
- 每条实践包含简短说明
- 提供正反示例(✓ 推荐 / ✗ 不推荐)
### 常见问题部分
- 使用问答格式
- 提供具体的解决方案
- 包含相关链接
## 写作风格
### 语气
- 友好、专业
- 使用第二人称("你"
- 避免过于技术化的术语
### 代码示例
- 完整且可运行
- 包含注释说明关键步骤
- 使用有意义的变量名
- 遵循项目代码风格
### 格式
- 使用 Markdown 标准格式
- 代码块使用语法高亮
- 重要内容使用粗体或引用块
- 适当使用列表和表格
## 配置选项
### 目标受众
```bash
# 初学者(更多解释,简单示例)
/vitepress-guide "事件系统" Core --audience beginner
# 进阶(平衡解释和示例)
/vitepress-guide "事件系统" Core --audience intermediate
# 专家(简洁说明,复杂示例)
/vitepress-guide "事件系统" Core --audience expert
```
### 重点内容
```bash
# 侧重概念
/vitepress-guide "事件系统" Core --focus concepts
# 侧重用法
/vitepress-guide "事件系统" Core --focus usage
# 侧重最佳实践
/vitepress-guide "事件系统" Core --focus best-practices
```
## 前置条件
1. 了解指南主题的基本概念
2. 能够访问相关代码文件
3. 了解项目的代码风格和术语
## 相关 Skills
- `/vitepress-api-doc` - 生成 API 参考文档
- `/vitepress-tutorial` - 生成分步教程
- `/vitepress-validate` - 验证生成的文档
## 最佳实践
1. **先搜索后编写**:查看现有文档和代码,保持一致性
2. **使用真实示例**:基于项目实际代码创建示例
3. **保持简洁**:每个章节聚焦一个主题
4. **提供完整代码**:确保示例可以直接运行
5. **添加交叉引用**:链接到相关的 API 文档和其他指南
## 故障排除
### 问题:不确定指南应该包含哪些内容
**解决方案**:参考 `examples/guide-example.md` 和现有的指南文档
### 问题:代码示例过于复杂
**解决方案**:将复杂示例拆分为多个简单示例,逐步增加复杂度
### 问题:概念解释不清晰
**解决方案**:使用类比、图表或分步说明来辅助解释
## 版本历史
- v1.0.0 - 初始版本,支持功能指南生成

View File

@ -0,0 +1,283 @@
---
title: IoC 容器使用指南
description: IoC控制反转容器提供了轻量级的依赖注入功能用于管理框架中各种组件的注册和获取。
---
# IoC 容器使用指南
## 概述
IoCInversion of Control控制反转包提供了一个轻量级的依赖注入容器用于管理框架中各种组件的注册和获取。通过 IoC 容器,可以实现组件间的解耦,便于测试和维护。
IoC 容器是 GFramework 架构的核心组件之一,为整个框架提供依赖管理和组件解析服务。
**主要特性**
- 类型安全的依赖管理
- 支持单例和多实例注册
- 线程安全操作
- 容器冻结保护
- 自动接口注册
## 核心概念
### 依赖注入
依赖注入是一种设计模式,通过容器管理对象的创建和依赖关系,而不是在代码中直接创建对象。
```csharp
// 不使用依赖注入
public class GameController
{
private PlayerModel model = new PlayerModel(); // 硬编码依赖
}
// 使用依赖注入
public class GameController : IController
{
public IArchitecture GetArchitecture() => GameArchitecture.Interface;
public void Start()
{
var model = this.GetModel<PlayerModel>(); // 从容器获取
}
}
```
### 容器注册
在架构初始化时,将组件注册到容器中:
```csharp
public class GameArchitecture : Architecture
{
protected override void Init()
{
// 注册 Model
RegisterModel(new PlayerModel());
// 注册 System
RegisterSystem(new GameplaySystem());
// 注册 Utility
RegisterUtility(new StorageUtility());
}
}
```
### 容器解析
通过扩展方法从容器中获取已注册的组件:
```csharp
// 在 Controller 中
var playerModel = this.GetModel<PlayerModel>();
var gameplaySystem = this.GetSystem<GameplaySystem>();
var storageUtility = this.GetUtility<StorageUtility>();
```
## 基本用法
### 注册组件
```csharp
var container = new IocContainer();
// 注册单例(一个类型只能有一个实例)
container.RegisterSingleton<IPlayerModel>(new PlayerModel());
// 注册多实例(一个类型可以有多个实例)
container.RegisterPlurality<IEnemy>(new Goblin());
container.RegisterPlurality<IEnemy>(new Orc());
container.RegisterPlurality<IEnemy>(new Dragon());
```
### 获取组件
```csharp
// 获取单例
var playerModel = container.Get<IPlayerModel>();
// 获取多实例集合
var enemies = container.GetAll<IEnemy>(); // 返回 List<IEnemy>
```
### 在架构中使用
```csharp
public class GameArchitecture : Architecture
{
protected override void Init()
{
// 注册组件
RegisterModel(new PlayerModel());
RegisterModel(new InventoryModel());
RegisterSystem(new GameplaySystem());
}
}
// 在 Controller 中使用
public class GameController : IController
{
public IArchitecture GetArchitecture() => GameArchitecture.Interface;
public void Start()
{
// 通过扩展方法获取组件
var playerModel = this.GetModel<PlayerModel>();
var inventoryModel = this.GetModel<InventoryModel>();
var gameplaySystem = this.GetSystem<GameplaySystem>();
}
}
```
## 高级用法
### 容器冻结
容器在架构初始化完成后会被冻结,防止运行时修改:
```csharp
var container = new IocContainer();
container.Register<IPlayerModel>(new PlayerModel());
// 冻结容器
container.Freeze();
// 以下操作会抛出 InvalidOperationException
// container.Register<IGameSystem>(new GameSystem());
```
### 多实例管理
```csharp
// 注册多个同类型实例
container.RegisterPlurality<IWeapon>(new Sword());
container.RegisterPlurality<IWeapon>(new Bow());
container.RegisterPlurality<IWeapon>(new Staff());
// 获取所有实例
var allWeapons = container.GetAll<IWeapon>();
foreach (var weapon in allWeapons)
{
weapon.Attack();
}
```
### 接口自动注册
注册实例时,容器会自动将其注册到所有实现的接口:
```csharp
public class PlayerModel : IModel, IPlayerModel, IDisposable
{
// ...
}
// 注册实例
container.Register<PlayerModel>(new PlayerModel());
// 可以通过任何接口获取
var model1 = container.Get<IModel>();
var model2 = container.Get<IPlayerModel>();
var model3 = container.Get<IDisposable>();
// 以上三个变量指向同一个实例
```
### 线程安全操作
容器的所有操作都是线程安全的:
```csharp
// 多线程环境下安全使用
Parallel.For(0, 100, i =>
{
var model = container.Get<IPlayerModel>();
model.DoSomething();
});
```
## 最佳实践
1. **使用接口注册**:优先使用接口类型注册,而不是具体类型
```csharp
✓ container.Register<IPlayerModel>(new PlayerModel());
✗ container.Register<PlayerModel>(new PlayerModel());
```
2. **单例 vs 多实例**:根据需求选择合适的注册方式
- 单例:全局唯一的服务(如配置、管理器)
- 多实例:可以有多个实例的对象(如敌人、道具)
3. **避免循环依赖**:组件之间不应该相互依赖
```csharp
✗ System A 依赖 System BSystem B 又依赖 System A
✓ 使用事件系统进行通信,避免直接依赖
```
4. **在 Init 中注册**:所有组件应该在架构的 `Init()` 方法中注册
```csharp
protected override void Init()
{
// 在这里注册所有组件
RegisterModel(new PlayerModel());
RegisterSystem(new GameplaySystem());
}
```
5. **使用扩展方法**:通过扩展方法获取组件,代码更简洁
```csharp
✓ var model = this.GetModel<PlayerModel>();
✗ var model = this.GetArchitecture().GetModel<PlayerModel>();
```
6. **不要在运行时注册**:容器冻结后不应该再注册新组件
```csharp
✗ 在游戏运行时动态注册组件
✓ 在架构初始化时注册所有需要的组件
```
## 常见问题
### 问题:如何判断使用单例还是多实例?
**解答**
- 使用单例(`RegisterSingleton`):全局唯一的服务,如 PlayerModel、GameConfiguration
- 使用多实例(`RegisterPlurality`):可以有多个实例的对象,如 Enemy、Weapon
### 问题:容器冻结后如何添加新组件?
**解答**
容器冻结是为了保护架构稳定性。如果需要动态添加组件,应该:
1. 在架构初始化时预先注册所有可能需要的组件
2. 使用对象池模式管理动态对象
3. 考虑使用工厂模式创建临时对象
### 问题:如何处理组件的生命周期?
**解答**
- 实现 `IDisposable` 接口的组件会在架构销毁时自动释放
- 架构会按注册的逆序销毁组件
- 不需要手动管理组件的生命周期
### 问题:可以在容器中注册值类型吗?
**解答**
可以,但会发生装箱。建议将值类型包装在类中:
```csharp
// 不推荐
container.Register<int>(42);
// 推荐
public class GameConfig
{
public int MaxPlayers { get; set; } = 42;
}
container.Register<GameConfig>(new GameConfig());
```
## 相关文档
- [架构组件](/zh-CN/core/architecture) - 架构基础
- [Model 层](/zh-CN/core/model) - 数据模型
- [System 层](/zh-CN/core/system) - 业务系统
- [Utility 工具类](/zh-CN/core/utility) - 工具类

View File

@ -0,0 +1,34 @@
---
title: {{GUIDE_TITLE}}
description: {{GUIDE_DESCRIPTION}}
---
# {{GUIDE_TITLE}}
## 概述
{{OVERVIEW}}
## 核心概念
{{CORE_CONCEPTS}}
## 基本用法
{{BASIC_USAGE}}
## 高级用法
{{ADVANCED_USAGE}}
## 最佳实践
{{BEST_PRACTICES}}
## 常见问题
{{FAQ}}
## 相关文档
{{RELATED_DOCS}}

View File

@ -0,0 +1,253 @@
# VitePress 教程生成
生成分步教程文档,适合初学者学习框架功能。
## 用途
此 skill 用于生成结构化的分步教程,适用于:
- 框架入门教程
- 功能实现教程
- 最佳实践演示
- 问题解决方案
## 调用方式
```bash
/vitepress-tutorial <教程主题>
```
**示例**
```bash
/vitepress-tutorial "创建第一个 System"
/vitepress-tutorial "实现自定义命令"
/vitepress-tutorial "使用事件系统"
```
## 工作流程
1. **收集需求**
- 询问用户教程主题
- 确定学习目标
- 了解前置知识要求
2. **设计教程步骤**
- 将任务分解为 3-7 个步骤
- 每步聚焦一个具体任务
- 确保步骤之间逻辑连贯
3. **生成教程内容**
- 根据 `template.md` 创建文档框架
- 为每步编写详细说明和代码
- 添加完整的可运行代码
- 说明预期结果
4. **确定输出路径**
- 保存到 `docs/zh-CN/tutorials/`
- 文件名使用小写加连字符
5. **更新导航配置**
- 在 VitePress 侧边栏中添加新教程
## 输出规范
### Frontmatter 格式
```yaml
---
title: 教程标题
description: 简短描述1 句话说明学习内容)
---
```
### 文档结构
1. **学习目标**:完成教程后能够掌握的技能
2. **前置条件**:需要的前置知识和环境
3. **步骤 1-N**分步说明3-7 步)
4. **完整代码**:汇总所有代码
5. **运行结果**:预期输出和效果
6. **下一步**:后续学习建议
### 步骤格式
每个步骤应包含:
- 步骤标题(简短、动词开头)
- 步骤说明(为什么要这样做)
- 代码示例(完整且可运行)
- 代码解释(关键部分的说明)
**示例**
```markdown
## 步骤 1创建 Model 类
首先,我们需要创建一个 Model 来存储玩家数据。Model 负责管理应用的数据和状态。
\`\`\`csharp
using GFramework.Core.Abstractions.model;
using GFramework.Core.Abstractions.property;
public class PlayerModel : IModel
{
// 玩家名称(可绑定属性)
public BindableProperty<string> Name { get; } = new("Player");
// 玩家生命值
public BindableProperty<int> Health { get; } = new(100);
// 玩家金币
public BindableProperty<int> Gold { get; } = new(0);
public void Init() { }
}
\`\`\`
**代码说明**
- `BindableProperty<T>` 是可绑定属性,值变化时会自动通知监听者
- `Init()` 方法在 Model 注册到架构时被调用
- 使用属性初始化器设置默认值
```
## 模板变量
- `{{TUTORIAL_TITLE}}` - 教程标题
- `{{TUTORIAL_DESCRIPTION}}` - 简短描述
- `{{LEARNING_OBJECTIVES}}` - 学习目标
- `{{PREREQUISITES}}` - 前置条件
- `{{STEP_N_TITLE}}` - 步骤标题
- `{{STEP_N_CONTENT}}` - 步骤内容
- `{{FULL_CODE}}` - 完整代码
- `{{EXPECTED_OUTPUT}}` - 预期输出
- `{{NEXT_STEPS}}` - 下一步建议
## 示例输出
参考 `examples/tutorial-example.md`,该示例基于现有的教程文档创建。
## 内容要求
### 学习目标
- 使用列表格式
- 3-5 个具体的学习目标
- 使用"能够..."句式
**示例**
```markdown
## 学习目标
完成本教程后,你将能够:
- 创建自定义的 Model 类
- 在架构中注册 Model
- 从 Controller 中访问 Model
- 使用可绑定属性管理数据
```
### 前置条件
- 列出必需的知识
- 说明环境要求
- 提供相关文档链接
**示例**
```markdown
## 前置条件
- 已安装 GFramework.Core NuGet 包
- 了解 C# 基础语法
- 阅读过[架构概览](/zh-CN/getting-started)
```
### 步骤内容
- 每步 100-300 字说明
- 包含完整的代码示例
- 解释关键代码的作用
- 使用注释标注重要部分
### 完整代码
- 汇总所有步骤的代码
- 确保可以直接复制运行
- 包含必要的 using 语句
- 添加文件结构说明
### 运行结果
- 描述预期的输出
- 如果有界面,提供截图或描述
- 说明如何验证结果正确
### 下一步
- 推荐 2-3 个后续教程
- 提供相关文档链接
- 建议进阶学习方向
## 写作风格
### 语气
- 友好、鼓励性
- 使用第二人称("你"
- 避免假设读者已有高级知识
### 步骤说明
- 使用主动语态
- 步骤标题使用动词开头
- 说明"为什么"而不仅是"怎么做"
### 代码示例
- 完整且可运行
- 包含详细注释
- 使用有意义的变量名
- 遵循项目代码风格
## 配置选项
### 教程难度
```bash
# 初学者(更多解释,简单示例)
/vitepress-tutorial "创建第一个 System" --level beginner
# 中级(平衡解释和复杂度)
/vitepress-tutorial "实现自定义命令" --level intermediate
# 高级(简洁说明,复杂示例)
/vitepress-tutorial "架构模块开发" --level advanced
```
### 步骤数量
```bash
# 指定步骤数量3-7 步)
/vitepress-tutorial "使用事件系统" --steps 5
```
## 前置条件
1. 了解教程主题的基本概念
2. 能够访问相关代码文件
3. 了解目标受众的知识水平
## 相关 Skills
- `/vitepress-api-doc` - 生成 API 参考文档
- `/vitepress-guide` - 生成功能指南
- `/vitepress-validate` - 验证生成的文档
## 最佳实践
1. **从简单开始**:第一步应该是最简单的操作
2. **逐步增加复杂度**:每步在前一步基础上增加新内容
3. **提供完整代码**:确保每步的代码都可以运行
4. **解释关键概念**:不要假设读者已经了解所有术语
5. **测试教程**:确保按照步骤操作能够得到预期结果
## 故障排除
### 问题:步骤过多,教程太长
**解决方案**:将教程拆分为多个小教程,或合并相似的步骤
### 问题:代码示例不完整
**解决方案**:在"完整代码"章节提供所有文件的完整代码
### 问题:读者反馈步骤不清晰
**解决方案**:增加更多说明,使用截图或图表辅助
## 版本历史
- v1.0.0 - 初始版本,支持分步教程生成

View File

@ -0,0 +1,347 @@
---
title: 创建第一个 Model
description: 学习如何创建和使用 Model 来管理应用数据
---
# 创建第一个 Model
## 学习目标
完成本教程后,你将能够:
- 理解 Model 在架构中的作用
- 创建自定义的 Model 类
- 在架构中注册 Model
- 从 Controller 中访问 Model
- 使用可绑定属性管理数据
## 前置条件
- 已安装 GFramework.Core NuGet 包
- 了解 C# 基础语法
- 阅读过[架构概览](/zh-CN/getting-started)
## 步骤 1创建 Model 类
首先,我们需要创建一个 Model 来存储玩家数据。Model 负责管理应用的数据和状态。
```csharp
using GFramework.Core.Abstractions.model;
using GFramework.Core.Abstractions.property;
namespace MyGame.Models
{
/// <summary>
/// 玩家数据模型
/// </summary>
public class PlayerModel : IModel
{
// 玩家名称(可绑定属性)
public BindableProperty<string> Name { get; } = new("Player");
// 玩家生命值
public BindableProperty<int> Health { get; } = new(100);
// 玩家金币
public BindableProperty<int> Gold { get; } = new(0);
// 玩家等级
public BindableProperty<int> Level { get; } = new(1);
/// <summary>
/// Model 初始化方法
/// </summary>
public void Init()
{
// 在这里可以进行初始化操作
// 例如:从配置文件加载默认值
}
}
}
```
**代码说明**
- `IModel` 接口标识这是一个数据模型
- `BindableProperty<T>` 是可绑定属性,值变化时会自动通知监听者
- `Init()` 方法在 Model 注册到架构时被调用
- 使用属性初始化器设置默认值
## 步骤 2在架构中注册 Model
创建架构类并注册 Model
```csharp
using GFramework.Core.architecture;
using MyGame.Models;
namespace MyGame
{
/// <summary>
/// 游戏架构
/// </summary>
public class GameArchitecture : Architecture
{
// 单例访问点
public static IArchitecture Interface { get; private set; }
/// <summary>
/// 初始化架构
/// </summary>
protected override void Init()
{
Interface = this;
// 注册 Model
RegisterModel(new PlayerModel());
}
}
}
```
**代码说明**
- 继承 `Architecture` 基类
- 在 `Init()` 方法中注册 Model
- 提供静态属性 `Interface` 用于全局访问架构
## 步骤 3创建 Controller 访问 Model
创建 Controller 来使用 Model
```csharp
using GFramework.Core.Abstractions.architecture;
using GFramework.Core.Abstractions.controller;
using GFramework.Core.extensions;
using MyGame.Models;
namespace MyGame.Controllers
{
/// <summary>
/// 游戏控制器
/// </summary>
public class GameController : IController
{
/// <summary>
/// 获取架构实例
/// </summary>
public IArchitecture GetArchitecture() => GameArchitecture.Interface;
/// <summary>
/// 初始化玩家数据
/// </summary>
public void InitializePlayer()
{
// 获取 PlayerModel
var playerModel = this.GetModel<PlayerModel>();
// 设置玩家数据
playerModel.Name.Value = "勇者";
playerModel.Health.Value = 100;
playerModel.Gold.Value = 50;
playerModel.Level.Value = 1;
// 监听属性变化
playerModel.Health.RegisterOnValueChanged(health =>
{
Console.WriteLine($"玩家生命值变化: {health}");
if (health <= 0)
{
Console.WriteLine("玩家死亡!");
}
});
}
/// <summary>
/// 玩家受到伤害
/// </summary>
public void TakeDamage(int damage)
{
var playerModel = this.GetModel<PlayerModel>();
playerModel.Health.Value -= damage;
}
/// <summary>
/// 玩家获得金币
/// </summary>
public void AddGold(int amount)
{
var playerModel = this.GetModel<PlayerModel>();
playerModel.Gold.Value += amount;
}
}
}
```
**代码说明**
- 实现 `IController` 接口
- 通过 `this.GetModel<T>()` 扩展方法获取 Model
- 使用 `.Value` 访问和修改属性值
- 使用 `RegisterOnValueChanged` 监听属性变化
## 步骤 4初始化并使用架构
在程序入口点初始化架构:
```csharp
using MyGame;
using MyGame.Controllers;
// 1. 创建并初始化架构
var architecture = new GameArchitecture();
architecture.Initialize();
// 2. 等待架构就绪
await architecture.WaitUntilReadyAsync();
// 3. 创建 Controller 并使用
var gameController = new GameController();
// 初始化玩家
gameController.InitializePlayer();
// 玩家受到伤害
gameController.TakeDamage(20);
// 输出: 玩家生命值变化: 80
// 玩家获得金币
gameController.AddGold(100);
```
**代码说明**
- 创建架构实例并调用 `Initialize()`
- 使用 `WaitUntilReadyAsync()` 等待架构就绪
- 创建 Controller 实例并调用方法
## 完整代码
### PlayerModel.cs
```csharp
using GFramework.Core.Abstractions.model;
using GFramework.Core.Abstractions.property;
namespace MyGame.Models
{
public class PlayerModel : IModel
{
public BindableProperty<string> Name { get; } = new("Player");
public BindableProperty<int> Health { get; } = new(100);
public BindableProperty<int> Gold { get; } = new(0);
public BindableProperty<int> Level { get; } = new(1);
public void Init() { }
}
}
```
### GameArchitecture.cs
```csharp
using GFramework.Core.architecture;
using MyGame.Models;
namespace MyGame
{
public class GameArchitecture : Architecture
{
public static IArchitecture Interface { get; private set; }
protected override void Init()
{
Interface = this;
RegisterModel(new PlayerModel());
}
}
}
```
### GameController.cs
```csharp
using GFramework.Core.Abstractions.architecture;
using GFramework.Core.Abstractions.controller;
using GFramework.Core.extensions;
using MyGame.Models;
namespace MyGame.Controllers
{
public class GameController : IController
{
public IArchitecture GetArchitecture() => GameArchitecture.Interface;
public void InitializePlayer()
{
var playerModel = this.GetModel<PlayerModel>();
playerModel.Name.Value = "勇者";
playerModel.Health.Value = 100;
playerModel.Gold.Value = 50;
playerModel.Level.Value = 1;
playerModel.Health.RegisterOnValueChanged(health =>
{
Console.WriteLine($"玩家生命值变化: {health}");
if (health <= 0)
{
Console.WriteLine("玩家死亡!");
}
});
}
public void TakeDamage(int damage)
{
var playerModel = this.GetModel<PlayerModel>();
playerModel.Health.Value -= damage;
}
public void AddGold(int amount)
{
var playerModel = this.GetModel<PlayerModel>();
playerModel.Gold.Value += amount;
}
}
}
```
### Program.cs
```csharp
using MyGame;
using MyGame.Controllers;
var architecture = new GameArchitecture();
architecture.Initialize();
await architecture.WaitUntilReadyAsync();
var gameController = new GameController();
gameController.InitializePlayer();
gameController.TakeDamage(20);
gameController.AddGold(100);
```
## 运行结果
运行程序后,你将看到以下输出:
```
玩家生命值变化: 100
玩家生命值变化: 80
```
**验证步骤**
1. 程序成功启动,没有异常
2. 控制台输出生命值变化信息
3. 玩家数据正确更新
## 下一步
恭喜!你已经学会了如何创建和使用 Model。接下来可以学习
- [创建第一个 System](/zh-CN/tutorials/create-first-system) - 学习如何创建业务逻辑层
- [使用命令系统](/zh-CN/tutorials/use-command-system) - 学习如何封装操作
- [使用事件系统](/zh-CN/tutorials/use-event-system) - 学习组件间通信
## 相关文档
- [Model 层](/zh-CN/core/model) - Model 详细说明
- [属性系统](/zh-CN/core/property) - 可绑定属性详解
- [架构组件](/zh-CN/core/architecture) - 架构基础
- [Controller 层](/zh-CN/core/controller) - Controller 详细说明

View File

@ -0,0 +1,42 @@
---
title: {{TUTORIAL_TITLE}}
description: {{TUTORIAL_DESCRIPTION}}
---
# {{TUTORIAL_TITLE}}
## 学习目标
{{LEARNING_OBJECTIVES}}
## 前置条件
{{PREREQUISITES}}
## 步骤 1{{STEP_1_TITLE}}
{{STEP_1_CONTENT}}
## 步骤 2{{STEP_2_TITLE}}
{{STEP_2_CONTENT}}
## 步骤 3{{STEP_3_TITLE}}
{{STEP_3_CONTENT}}
## 完整代码
{{FULL_CODE}}
## 运行结果
{{EXPECTED_OUTPUT}}
## 下一步
{{NEXT_STEPS}}
## 相关文档
{{RELATED_DOCS}}

View File

@ -0,0 +1,297 @@
# VitePress 文档验证
验证 VitePress 文档的质量和规范性,确保文档符合项目标准。
## 用途
此 skill 用于验证 Markdown 文档的格式和内容,包括:
- Frontmatter 格式正确性
- 内部链接有效性
- 代码块语法标记
- 标题层级结构
- 中文标点符号规范
- 泛型符号转义
## 调用方式
```bash
# 验证单个文件
/vitepress-validate <文件路径>
# 验证整个目录
/vitepress-validate <目录路径>
# 验证所有文档
/vitepress-validate docs/zh-CN/
```
**示例**
```bash
/vitepress-validate docs/zh-CN/api-reference/core/architecture.md
/vitepress-validate docs/zh-CN/core/
```
## 验证项
### 1. Frontmatter 验证
**检查项**
- YAML 语法正确性
- 必需字段存在(`title``description`
- 字段值类型正确
- `outline` 字段值有效(`deep``[2,3]` 等)
**示例**
```yaml
---
title: Architecture # 必需
description: 架构基类说明 # 必需
outline: deep # 可选,但值必须有效
---
```
### 2. 内部链接验证
**检查项**
- 相对路径链接指向的文件存在
- 绝对路径链接格式正确
- 锚点链接对应的标题存在
- 没有损坏的链接
**有效链接格式**
- `[文本](./file.md)` - 相对路径
- `[文本](/zh-CN/core/architecture)` - 绝对路径
- `[文本](#标题)` - 锚点链接
- `[文本](./file.md#标题)` - 组合链接
### 3. 代码块验证
**检查项**
- 代码块有语法标记(```csharp、```bash 等)
- C# 代码块使用 `csharp` 标记(不是 `cs``c#`
- 代码块正确闭合
- 没有未闭合的反引号
**正确格式**
```markdown
\`\`\`csharp
public class Example { }
\`\`\`
```
**错误格式**
```markdown
\`\`\`cs // 应该使用 csharp
public class Example { }
\`\`\`
```
### 4. 标题层级验证
**检查项**
- 标题层级不跳级(不能从 `#` 直接跳到 `###`
- 每个文档只有一个一级标题(`#`
- 标题层级递增合理
**正确示例**
```markdown
# 一级标题
## 二级标题
### 三级标题
## 另一个二级标题
```
**错误示例**
```markdown
# 一级标题
### 三级标题 ❌ 跳过了二级标题
```
### 5. 中文标点符号验证
**检查项**
- 中文句子使用全角标点(,。!?)
- 英文句子使用半角标点(,.!?
- 代码和技术术语周围使用半角符号
- 括号使用规范
**规范示例**
- "这是一个示例。" ✓(中文全角句号)
- "This is an example." ✓(英文半角句号)
- "`Architecture` 类提供了..." ✓(代码周围半角)
### 6. 泛型符号验证
**检查项**
- 泛型符号正确转义(`<T>``&lt;T&gt;`
- 仅在代码块外转义
- 代码块内保持原样
**正确示例**
```markdown
`List&lt;T&gt;` 是一个泛型类。
\`\`\`csharp
List<T> items = new List<T>(); // 代码块内不转义
\`\`\`
```
## 验证脚本
### validate-frontmatter.sh
验证 Frontmatter 格式。
**用法**
```bash
.claude/skills/vitepress-validate/scripts/validate-frontmatter.sh <文件路径>
```
### validate-links.sh
验证内部链接有效性。
**用法**
```bash
.claude/skills/vitepress-validate/scripts/validate-links.sh <文件路径>
```
### validate-code-blocks.sh
验证代码块语法。
**用法**
```bash
.claude/skills/vitepress-validate/scripts/validate-code-blocks.sh <文件路径>
```
### validate-all.sh
执行所有验证。
**用法**
```bash
.claude/skills/vitepress-validate/scripts/validate-all.sh <文件或目录路径>
```
## 输出格式
### 验证通过
```
✓ docs/zh-CN/core/architecture.md
- Frontmatter: 通过
- 内部链接: 通过
- 代码块: 通过
- 标题层级: 通过
- 标点符号: 通过
- 泛型符号: 通过
```
### 验证失败
```
✗ docs/zh-CN/core/architecture.md
- Frontmatter: 失败
× 缺少必需字段: description
- 内部链接: 失败
× 损坏的链接: ./missing-file.md (第 45 行)
- 代码块: 警告
⚠ 使用了 'cs' 标记,建议使用 'csharp' (第 78 行)
- 标题层级: 通过
- 标点符号: 警告
⚠ 中文句子使用了半角句号 (第 102 行)
- 泛型符号: 失败
× 未转义的泛型符号: List<T> (第 120 行)
```
## 修复建议
验证失败时skill 会提供具体的修复建议:
**示例**
```
修复建议:
1. 在 Frontmatter 中添加 description 字段
2. 修复或删除损坏的链接: ./missing-file.md
3. 将代码块标记从 'cs' 改为 'csharp'
4. 将第 102 行的半角句号改为全角句号
5. 将第 120 行的 List<T> 改为 List&lt;T&gt;
```
## 配置选项
### 严格模式
启用严格模式时,警告也会导致验证失败。
```bash
/vitepress-validate --strict docs/zh-CN/
```
### 忽略特定检查
```bash
# 忽略标点符号检查
/vitepress-validate --ignore-punctuation docs/zh-CN/
# 忽略多个检查
/vitepress-validate --ignore-punctuation --ignore-generics docs/zh-CN/
```
## 集成到工作流
### 生成后自动验证
```bash
# 1. 生成 API 文档
/vitepress-api-doc GFramework.Core/architecture/Architecture.cs
# 2. 自动验证生成的文档
/vitepress-validate docs/zh-CN/api-reference/core/architecture.md
```
### 批量验证
```bash
# 验证所有 API 文档
/vitepress-validate docs/zh-CN/api-reference/
# 验证所有文档
/vitepress-validate docs/zh-CN/
```
## 退出代码
- `0` - 所有验证通过
- `1` - 存在错误
- `2` - 仅存在警告(非严格模式下仍返回 0
## 相关 Skills
- `/vitepress-api-doc` - 生成 API 文档后自动验证
- `/vitepress-guide` - 生成指南文档后自动验证
- `/vitepress-tutorial` - 生成教程文档后自动验证
## 最佳实践
1. **生成后立即验证**:每次生成文档后立即运行验证
2. **定期批量验证**:定期验证所有文档,确保一致性
3. **修复所有错误**:不要忽略验证错误,及时修复
4. **关注警告**:警告虽不致命,但应该重视并修复
5. **使用严格模式**:在 CI/CD 中使用严格模式确保质量
## 故障排除
### 问题:误报泛型符号错误
**解决方案**:确保泛型符号在代码块外正确转义,代码块内保持原样
### 问题:中文标点符号检查过于严格
**解决方案**:使用 `--ignore-punctuation` 选项,或手动调整规则
### 问题:链接验证失败但文件确实存在
**解决方案**:检查文件路径大小写,确保路径完全匹配
## 版本历史
- v1.0.0 - 初始版本,支持 6 项基本验证

View File

@ -0,0 +1,109 @@
#!/bin/bash
# 执行所有验证
# 用法: validate-all.sh <文件或目录路径>
set -e
TARGET="$1"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -z "$TARGET" ]; then
echo "用法: $0 <文件或目录路径>"
exit 1
fi
if [ ! -e "$TARGET" ]; then
echo "错误: 路径不存在: $TARGET"
exit 1
fi
echo "=========================================="
echo "VitePress 文档验证"
echo "=========================================="
echo ""
# 收集所有 Markdown 文件
if [ -f "$TARGET" ]; then
FILES=("$TARGET")
elif [ -d "$TARGET" ]; then
mapfile -t FILES < <(find "$TARGET" -name "*.md" -type f)
else
echo "错误: 无效的路径: $TARGET"
exit 1
fi
if [ ${#FILES[@]} -eq 0 ]; then
echo "未找到 Markdown 文件"
exit 0
fi
echo "找到 ${#FILES[@]} 个文件"
echo ""
TOTAL_ERRORS=0
TOTAL_WARNINGS=0
PASSED_FILES=0
FAILED_FILES=0
for FILE in "${FILES[@]}"; do
echo "验证: $FILE"
echo "----------------------------------------"
FILE_ERRORS=0
FILE_WARNINGS=0
# 1. Frontmatter 验证
if bash "$SCRIPT_DIR/validate-frontmatter.sh" "$FILE" 2>&1 | grep -q "✗"; then
FILE_ERRORS=$((FILE_ERRORS + 1))
fi
# 2. 链接验证
if bash "$SCRIPT_DIR/validate-links.sh" "$FILE" 2>&1 | grep -q "✗"; then
FILE_ERRORS=$((FILE_ERRORS + 1))
fi
# 3. 代码块验证
OUTPUT=$(bash "$SCRIPT_DIR/validate-code-blocks.sh" "$FILE" 2>&1 || true)
if echo "$OUTPUT" | grep -q "✗"; then
FILE_ERRORS=$((FILE_ERRORS + 1))
fi
if echo "$OUTPUT" | grep -q "⚠"; then
FILE_WARNINGS=$((FILE_WARNINGS + 1))
fi
# 统计结果
if [ $FILE_ERRORS -eq 0 ]; then
echo "✓ 验证通过"
PASSED_FILES=$((PASSED_FILES + 1))
else
echo "✗ 验证失败($FILE_ERRORS 个错误)"
FAILED_FILES=$((FAILED_FILES + 1))
fi
if [ $FILE_WARNINGS -gt 0 ]; then
echo "$FILE_WARNINGS 个警告"
fi
TOTAL_ERRORS=$((TOTAL_ERRORS + FILE_ERRORS))
TOTAL_WARNINGS=$((TOTAL_WARNINGS + FILE_WARNINGS))
echo ""
done
echo "=========================================="
echo "验证摘要"
echo "=========================================="
echo "总文件数: ${#FILES[@]}"
echo "通过: $PASSED_FILES"
echo "失败: $FAILED_FILES"
echo "总错误数: $TOTAL_ERRORS"
echo "总警告数: $TOTAL_WARNINGS"
echo ""
if [ $TOTAL_ERRORS -eq 0 ]; then
echo "✓ 所有验证通过"
exit 0
else
echo "✗ 验证失败"
exit 1
fi

View File

@ -0,0 +1,64 @@
#!/bin/bash
# 验证代码块语法
# 用法: validate-code-blocks.sh <文件路径>
set -e
FILE="$1"
if [ -z "$FILE" ]; then
echo "用法: $0 <文件路径>"
exit 1
fi
if [ ! -f "$FILE" ]; then
echo "错误: 文件不存在: $FILE"
exit 1
fi
echo "验证代码块语法: $FILE"
ERROR_COUNT=0
WARNING_COUNT=0
# 检查未闭合的代码块
OPEN_COUNT=$(grep -c '^```' "$FILE" || true)
if [ $((OPEN_COUNT % 2)) -ne 0 ]; then
echo "✗ 错误: 存在未闭合的代码块"
ERROR_COUNT=$((ERROR_COUNT + 1))
fi
# 检查 C# 代码块标记
LINE_NUM=0
while IFS= read -r LINE; do
LINE_NUM=$((LINE_NUM + 1))
# 检查是否使用了错误的 C# 标记
if echo "$LINE" | grep -qE '^```(cs|c#|C#)$'; then
echo "⚠ 警告: 第 $LINE_NUM 行使用了非标准标记,建议使用 'csharp'"
echo " 当前: $LINE"
WARNING_COUNT=$((WARNING_COUNT + 1))
fi
# 检查代码块是否有语言标记
if echo "$LINE" | grep -qE '^```$'; then
# 检查下一行是否是代码(简单启发式:不是空行且不是 ```
NEXT_LINE=$(sed -n "$((LINE_NUM + 1))p" "$FILE")
if [ -n "$NEXT_LINE" ] && ! echo "$NEXT_LINE" | grep -qE '^```'; then
echo "⚠ 警告: 第 $LINE_NUM 行的代码块缺少语言标记"
WARNING_COUNT=$((WARNING_COUNT + 1))
fi
fi
done < "$FILE"
# 输出结果
if [ $ERROR_COUNT -eq 0 ] && [ $WARNING_COUNT -eq 0 ]; then
echo "✓ 代码块验证通过"
exit 0
elif [ $ERROR_COUNT -eq 0 ]; then
echo "⚠ 代码块验证通过(有 $WARNING_COUNT 个警告)"
exit 0
else
echo "✗ 代码块验证失败($ERROR_COUNT 个错误,$WARNING_COUNT 个警告)"
exit 1
fi

View File

@ -0,0 +1,57 @@
#!/bin/bash
# 验证 Frontmatter 格式
# 用法: validate-frontmatter.sh <文件路径>
set -e
FILE="$1"
if [ -z "$FILE" ]; then
echo "用法: $0 <文件路径>"
exit 1
fi
if [ ! -f "$FILE" ]; then
echo "错误: 文件不存在: $FILE"
exit 1
fi
echo "验证 Frontmatter: $FILE"
# 检查是否有 Frontmatter限制在前几行避免匹配正文中的 '---'
if ! head -n 5 "$FILE" | grep -q "^---$"; then
echo "✗ 错误: 文件缺少 Frontmatter"
exit 1
fi
# 提取 Frontmatter 内容(第一个 --- 到第二个 --- 之间)
FRONTMATTER=$(sed -n '/^---$/,/^---$/p' "$FILE" | sed '1d;$d')
if [ -z "$FRONTMATTER" ]; then
echo "✗ 错误: Frontmatter 为空"
exit 1
fi
# 检查必需字段: title
if ! echo "$FRONTMATTER" | grep -q "^title:"; then
echo "✗ 错误: 缺少必需字段: title"
exit 1
fi
# 检查必需字段: description
if ! echo "$FRONTMATTER" | grep -q "^description:"; then
echo "✗ 错误: 缺少必需字段: description"
exit 1
fi
# 检查 outline 字段值(如果存在)
if echo "$FRONTMATTER" | grep -q "^outline:"; then
OUTLINE_VALUE=$(echo "$FRONTMATTER" | grep "^outline:" | sed 's/outline:\s*//')
if [ "$OUTLINE_VALUE" != "deep" ] && [ "$OUTLINE_VALUE" != "false" ] && ! echo "$OUTLINE_VALUE" | grep -qE '^\[.*\]$'; then
echo "⚠ 警告: outline 字段值可能无效: $OUTLINE_VALUE"
echo " 有效值: deep, false, [2,3]"
fi
fi
echo "✓ Frontmatter 验证通过"
exit 0

View File

@ -0,0 +1,85 @@
#!/bin/bash
# 验证内部链接有效性
# 用法: validate-links.sh <文件路径>
set -e
FILE="$1"
BASE_DIR="docs/zh-CN"
if [ -z "$FILE" ]; then
echo "用法: $0 <文件路径>"
exit 1
fi
if [ ! -f "$FILE" ]; then
echo "错误: 文件不存在: $FILE"
exit 1
fi
echo "验证内部链接: $FILE"
# 获取文件所在目录
FILE_DIR=$(dirname "$FILE")
# 提取所有 Markdown 链接
LINKS=$(grep -oP '\[([^\]]+)\]\(([^)]+)\)' "$FILE" | grep -oP '\(([^)]+)\)' | sed 's/[()]//g' || true)
if [ -z "$LINKS" ]; then
echo "✓ 未找到链接"
exit 0
fi
ERROR_COUNT=0
while IFS= read -r LINK; do
# 跳过外部链接
if [[ "$LINK" =~ ^https?:// ]]; then
continue
fi
# 跳过锚点链接(仅 #开头)
if [[ "$LINK" =~ ^# ]]; then
continue
fi
# 移除锚点部分
LINK_PATH=$(echo "$LINK" | sed 's/#.*//')
# 跳过空路径
if [ -z "$LINK_PATH" ]; then
continue
fi
# 处理相对路径
if [[ "$LINK_PATH" =~ ^\. ]]; then
TARGET="$FILE_DIR/$LINK_PATH"
# 处理绝对路径
elif [[ "$LINK_PATH" =~ ^/ ]]; then
TARGET="docs$LINK_PATH"
# 如果没有扩展名,尝试添加 .md
if [[ ! "$TARGET" =~ \. ]]; then
TARGET="$TARGET.md"
fi
else
TARGET="$FILE_DIR/$LINK_PATH"
fi
# 规范化路径
TARGET=$(realpath -m "$TARGET" 2>/dev/null || echo "$TARGET")
# 检查文件是否存在
if [ ! -f "$TARGET" ] && [ ! -d "$TARGET" ]; then
echo "✗ 损坏的链接: $LINK"
echo " 目标不存在: $TARGET"
ERROR_COUNT=$((ERROR_COUNT + 1))
fi
done <<< "$LINKS"
if [ $ERROR_COUNT -eq 0 ]; then
echo "✓ 内部链接验证通过"
exit 0
else
echo "✗ 发现 $ERROR_COUNT 个损坏的链接"
exit 1
fi

View File

@ -13,8 +13,9 @@ permissions:
security-events: write
jobs:
test:
name: Build and Test
# 代码质量检查 job并行执行不阻塞构建
code-quality:
name: Code Quality & Security
runs-on: ubuntu-latest
steps:
@ -23,6 +24,11 @@ jobs:
uses: actions/checkout@v6
with:
fetch-depth: 0
# 校验C#命名空间与源码目录是否符合命名规范
- name: Validate C# naming
run: bash scripts/validate-csharp-naming.sh
# 缓存MegaLinter
- name: Cache MegaLinter
uses: actions/cache@v5
@ -31,21 +37,22 @@ jobs:
key: ${{ runner.os }}-megalinter-v9
restore-keys: |
${{ runner.os }}-megalinter-
# MegaLinter扫描步骤
# 执行代码质量检查和安全扫描生成SARIF格式报告
- name: MegaLinter
uses: oxsecurity/megalinter@v9.3.0
uses: oxsecurity/megalinter@v9.4.0
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FAIL_ON_ERROR: ${{ github.ref == 'refs/heads/main' }}
# 上传SARIF格式的安全和代码质量问题报告到GitHub安全中心
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: megalinter-reports/sarif
# 缓存TruffleHog
- name: Cache TruffleHog
uses: actions/cache@v5
@ -57,7 +64,7 @@ jobs:
# 使用 TruffleHog 工具扫描代码库中的敏感信息泄露如API密钥、密码等
# 该步骤会比较基础分支和当前提交之间的差异,检测新增内容中是否包含敏感数据
- name: TruffleHog OSS
uses: trufflesecurity/trufflehog@v3.93.3
uses: trufflesecurity/trufflehog@v3.93.8
with:
# 扫描路径,. 表示扫描整个仓库
path: .
@ -65,6 +72,18 @@ jobs:
base: ${{ github.event.before }}
# 当前提交哈希,作为扫描的目标版本
head: ${{ github.sha }}
# 构建和测试 job并行执行
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
# 检出源代码
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
# 安装和配置.NET SDK版本
- name: Setup .NET 8
@ -110,21 +129,36 @@ jobs:
run: dotnet build -c Release --no-restore
# 运行单元测试输出TRX格式结果到TestResults目录
- name: Test - Core
# 在同一个 step 中并发执行所有测试以加快速度
- name: Test All Projects
run: |
dotnet test GFramework.Core.Tests \
-c Release \
--no-build \
--logger "trx;LogFileName=core-$RANDOM.trx" \
--results-directory TestResults
- name: Test - SourceGenerators
run: |
--results-directory TestResults &
dotnet test GFramework.Game.Tests \
-c Release \
--no-build \
--logger "trx;LogFileName=game-$RANDOM.trx" \
--results-directory TestResults &
dotnet test GFramework.SourceGenerators.Tests \
-c Release \
--no-build \
--logger "trx;LogFileName=sg-$RANDOM.trx" \
--results-directory TestResults
--results-directory TestResults &
dotnet test GFramework.Ecs.Arch.Tests \
-c Release \
--no-build \
--logger "trx;LogFileName=ecs-arch-$RANDOM.trx" \
--results-directory TestResults &
# 等待所有后台测试完成
wait
- name: Generate CTRF report
run: |
mkdir -p ctrf
@ -164,4 +198,4 @@ jobs:
fetch-previous-results: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: always()
if: always()

View File

@ -59,7 +59,7 @@ jobs:
# name: 工件名称,用于标识上传的文件集合
# path: 指定需要上传的文件路径列表(支持多行格式)
- name: Upload compliance artifacts
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: license-compliance
path: |

View File

@ -69,7 +69,7 @@ jobs:
dotnet pack -c Release -o ./packages -p:PackageVersion=${{ steps.tag_version.outputs.version }} -p:IncludeSymbols=false
# 上传许可证合规相关的工件文件包括通知文件、第三方许可证、SBOM文件及验证结果
- name: Upload compliance artifacts
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: license-compliance
path: |

12
.gitignore vendored
View File

@ -5,5 +5,13 @@ riderModule.iml
/_ReSharper.Caches/
GFramework.sln.DotSettings.user
.idea/
.opencode.json
.claude/
# ai
opencode.json
.claude/settings.local.json
.claude/settings.json
.omc/
docs/.omc/
docs/.vitepress/cache/
local-plan/
# tool
.venv/

220
AGENTS.md Normal file
View File

@ -0,0 +1,220 @@
# AGENTS.md
This document is the single source of truth for coding behavior in this repository.
All AI agents and contributors must follow these rules when writing, reviewing, or modifying code in `GFramework`.
## Environment Capability Inventory
- Before choosing runtimes or CLI tools, read `@.ai/environment/tools.ai.yaml`.
- Use `@.ai/environment/tools.raw.yaml` only when you need the full collected facts behind the AI-facing hints.
- Prefer the project-relevant tools listed there instead of assuming every installed system tool is fair game.
- If the real environment differs from the inventory, use the project-relevant installed tool and report the mismatch.
## Commenting Rules (MUST)
All generated or modified code MUST include clear and meaningful comments where required by the rules below.
### XML Documentation (Required)
- All public, protected, and internal types and members MUST include XML documentation comments (`///`).
- Use `<summary>`, `<param>`, `<returns>`, `<exception>`, and `<remarks>` where applicable.
- Comments must explain intent, contract, and usage constraints instead of restating syntax.
- If a member participates in lifecycle, threading, registration, or disposal behavior, document that behavior
explicitly.
### Inline Comments
- Add inline comments for:
- Non-trivial logic
- Concurrency or threading behavior
- Performance-sensitive paths
- Workarounds, compatibility constraints, or edge cases
- Registration order, lifecycle sequencing, or generated code assumptions
- Avoid obvious comments such as `// increment i`.
### Architecture-Level Comments
- Core framework components such as Architecture, Module, System, Context, Registry, Service Module, and Lifecycle types
MUST include high-level explanations of:
- Responsibilities
- Lifecycle
- Interaction with other components
- Why the abstraction exists
- When to use it instead of alternatives
### Source Generator Comments
- Generated logic and generator pipelines MUST explain:
- What is generated
- Why it is generated
- The semantic assumptions the generator relies on
- Any diagnostics or fallback behavior
### Complex Logic Requirement
- Methods with non-trivial logic MUST document:
- The core idea
- Key decisions
- Edge case handling, if any
### Quality Rules
- Comments MUST NOT be trivial, redundant, or misleading.
- Prefer explaining `why` and `when`, not just `what`.
- Code should remain understandable without requiring external context.
- Prefer slightly more explanation over too little for framework code.
### Enforcement
- Missing required documentation is a coding standards violation.
- Code that does not meet the documentation rules is considered incomplete.
## Code Style
### Language and Project Settings
- Follow the repository defaults:
- `ImplicitUsings` disabled
- `Nullable` enabled
- `GenerateDocumentationFile` enabled for shipped libraries
- `LangVersion` is generally `preview` in the main libraries and abstractions
- Do not rely on implicit imports. Declare every required `using` explicitly.
- Write null-safe code that respects nullable annotations instead of suppressing warnings by default.
### Naming and Structure
- Use the namespace pattern `GFramework.{Module}.{Feature}` with PascalCase segments.
- Follow standard C# naming:
- Types, methods, properties, events, and constants: PascalCase
- Interfaces: `I` prefix
- Parameters and locals: camelCase
- Private fields: `_camelCase`
- Keep abstractions projects free of implementation details and engine-specific dependencies.
- Preserve existing module boundaries. Do not introduce new cross-module dependencies without clear architectural need.
### Formatting
- Use 4 spaces for indentation. Do not use tabs.
- Use Allman braces.
- Keep `using` directives at the top of the file and sort them consistently.
- Separate logical blocks with blank lines when it improves readability.
- Prefer one primary type per file unless the surrounding project already uses a different local pattern.
- Keep line length readable. Around 120 characters is the preferred upper bound.
### C# Conventions
- Prefer explicit, readable code over clever shorthand in framework internals.
- Match existing async patterns and naming conventions (`Async` suffix for asynchronous methods).
- Avoid hidden side effects in property getters, constructors, and registration helpers.
- Preserve deterministic behavior in registries, lifecycle orchestration, and generated outputs.
- When adding analyzers or suppressions, keep them minimal and justify them in code comments if the reason is not
obvious.
### Analyzer and Validation Expectations
- The repository uses `Meziantou.Analyzer`; treat analyzer feedback as part of the coding standard.
- Naming must remain compatible with `scripts/validate-csharp-naming.sh`.
## Testing Requirements
### Required Coverage
- Every non-trivial feature, bug fix, or behavior change MUST include tests or an explicit justification for why a test
is not practical.
- Public API changes must be covered by unit or integration tests.
- Regression fixes should include a test that fails before the fix and passes after it.
### Test Organization
- Mirror the source structure in test projects whenever practical.
- Reuse existing architecture test infrastructure when relevant:
- `ArchitectureTestsBase<T>`
- `SyncTestArchitecture`
- `AsyncTestArchitecture`
- Keep tests focused on observable behavior, not implementation trivia.
### Source Generator Tests
- Source generator changes MUST be covered by generator tests.
- Preserve snapshot-based verification patterns already used in the repository.
- When generator behavior changes intentionally, update snapshots together with the implementation.
### Validation Commands
Use the smallest command set that proves the change, then expand if the change is cross-cutting.
```bash
# Build the full solution
dotnet build GFramework.sln -c Release
# Run all tests
dotnet test GFramework.sln -c Release
# Run a single test project
dotnet test GFramework.Core.Tests -c Release
dotnet test GFramework.Game.Tests -c Release
dotnet test GFramework.SourceGenerators.Tests -c Release
dotnet test GFramework.Ecs.Arch.Tests -c Release
# Run a single NUnit test or test group
dotnet test GFramework.Core.Tests -c Release --filter "FullyQualifiedName~CommandExecutorTests.Execute"
# Validate naming rules used by CI
bash scripts/validate-csharp-naming.sh
```
### Test Execution Expectations
- Run targeted tests for the code you changed whenever possible.
- Run broader solution-level validation for changes that touch shared abstractions, lifecycle behavior, source
generators, or dependency wiring.
- Do not claim completion if required tests were skipped; state what was not run and why.
## Security Rules
- Validate external or user-controlled input before it reaches file system, serialization, reflection, code generation,
or process boundaries.
- Do not build command strings, file paths, type names, or generated code from untrusted input without strict validation
or allow-listing.
- Avoid logging secrets, tokens, credentials, or machine-specific sensitive data.
- Keep source generators deterministic and free of hidden environment or network dependencies.
- Prefer least-privilege behavior for file, process, and environment access.
- Do not introduce unsafe deserialization, broad reflection-based activation, or dynamic code execution unless it is
explicitly required and tightly constrained.
- When adding caching, pooling, or shared mutable state, document thread-safety assumptions and failure modes.
- Minimize new package dependencies. Add them only when necessary and keep scope narrow.
## Documentation Rules
### Code Documentation
- Any change to public API, lifecycle semantics, module behavior, or extension points MUST update the related XML docs.
- If a framework abstraction changes meaning or intended usage, update the explanatory comments in code as part of the
same change.
### Repository Documentation
- Update the relevant `README.md` or `docs/` page when behavior, setup steps, architecture guidance, or user-facing
examples change.
- The main documentation site lives under `docs/`, with Chinese content under `docs/zh-CN/`.
- Keep code samples, package names, and command examples aligned with the current repository state.
- Prefer documenting behavior and design intent, not only API surface.
### Documentation Preview
When documentation changes need local preview, use:
```bash
cd docs && bun install && bun run dev
```
## Review Standard
Before considering work complete, confirm:
- Required comments and XML docs are present
- Code follows repository style and naming rules
- Relevant tests were added or updated
- Sensitive or unsafe behavior was not introduced
- User-facing documentation is updated when needed

134
CLAUDE.md Normal file
View File

@ -0,0 +1,134 @@
# CLAUDE.md
This file provides project understanding for AI agents working in this repository.
## Project Overview
GFramework 是面向游戏开发的模块化 C# 框架,核心能力与引擎解耦。项目灵感参考 QFramework并在模块边界、工程组织和可扩展性方面持续重构。
## AI Agent Instructions
All coding rules are defined in:
@AGENTS.md
Follow them strictly.
## Module Dependency Graph
```text
GFramework (meta package) ─→ Core + Game
GFramework.Core ─→ Core.Abstractions
GFramework.Game ─→ Game.Abstractions, Core, Core.Abstractions
GFramework.Godot ─→ Core, Game, Core.Abstractions, Game.Abstractions
GFramework.Ecs.Arch ─→ Ecs.Arch.Abstractions, Core, Core.Abstractions
GFramework.SourceGenerators ─→ SourceGenerators.Common, SourceGenerators.Abstractions
```
- **Abstractions projects** (`netstandard2.1`): 只包含接口和契约定义,不承载运行时实现逻辑。
- **Core / Game / Ecs.Arch** (`net8.0;net9.0;net10.0`): 平台无关的核心实现层。
- **Godot**: Godot 引擎集成层,负责与节点、场景和引擎生命周期对接。
- **SourceGenerators** (`netstandard2.1`): Roslyn 增量源码生成器及其公共基础设施。
## Architecture Pattern
框架核心采用 `Architecture / Model / System / Utility` 四层结构:
- **IArchitecture**: 顶层容器,负责生命周期管理、组件注册、模块安装和统一服务访问。
- **IContextAware**: 统一上下文访问接口,组件通过 `SetContext(IArchitectureContext)` 获取架构上下文。
- **IModel**: 数据与状态层,负责长期状态和业务数据建模。
- **ISystem**: 业务逻辑层,负责命令执行、流程编排和规则落地。
- **IUtility**: 通用无状态工具层,供其他层复用。
关键实现位于 `GFramework.Core/Architectures/Architecture.cs`,其职责是作为总协调器串联生命周期、组件注册和模块系统。
## Architecture Details
### Lifecycle
Architecture 负责统一生命周期编排,核心阶段包括:
- `Init`
- `Ready`
- `Destroy`
在实现层中,生命周期被拆分为更细粒度的初始化与销毁阶段,用于保证 Utility、Model、System、服务模块和钩子的顺序一致性。
### Component Coordination
框架通过独立组件协作完成架构编排:
- `ArchitectureLifecycle`: 管理生命周期阶段、阶段转换和生命周期钩子。
- `ArchitectureComponentRegistry`: 管理 Model、System、Utility 的注册与解析。
- `ArchitectureModules`: 管理模块安装、服务模块接入和扩展点注册。
这组拆分的目标是降低单个核心类的职责密度,同时保持对外 API 稳定。
### Context Propagation
`IArchitectureContext` 和相关 Provider 类型负责在组件之间传播上下文能力,使 Model、System
和外部扩展都能通过统一入口访问架构服务,而不直接耦合具体实现细节。
## Key Patterns
### CQRS
命令与查询分离支持同步与异步执行。Mediator 模式通过源码生成器集成,以减少模板代码并保持调用路径清晰。
### EventBus
类型安全事件总线支持事件发布、订阅、优先级、过滤器和弱引用订阅。它是模块之间松耦合通信的核心基础设施之一。
### BindableProperty
响应式属性模型通过值变化通知驱动界面或业务层更新,适合表达轻量级状态同步。
### Coroutine
帧驱动协程系统基于 `IYieldInstruction` 和调度器抽象,支持等待时间、事件和任务完成等常见模式。
### IoC
依赖注入通过 `MicrosoftDiContainer``Microsoft.Extensions.DependencyInjection` 进行封装,用于统一组件注册和服务解析体验。
### Service Modules
`IServiceModule` 模式用于向 Architecture 注册内置服务,例如 EventBus、CommandExecutor、QueryExecutor 等。这一模式承担“基础设施能力装配”的职责。
## Source Generators
当前仓库包含多类 Roslyn 增量源码生成器:
- `LoggerGenerator` (`[Log]`): 自动生成日志字段和日志辅助方法。
- `PriorityGenerator` (`[Priority]`): 生成优先级比较相关实现。
- `EnumExtensionsGenerator` (`[GenerateEnumExtensions]`): 生成枚举扩展能力。
- `ContextAwareGenerator` (`[ContextAware]`): 自动实现 `IContextAware` 相关样板逻辑。
这些生成器的目标是减少重复代码,同时保持框架层 API 的一致性与可维护性。
## Module Structure
仓库以“抽象层 + 实现层 + 集成层 + 生成器层”的方式组织:
- `GFramework.Core.Abstractions` / `GFramework.Game.Abstractions`: 约束接口和公共契约。
- `GFramework.Core` / `GFramework.Game`: 提供平台无关实现。
- `GFramework.Godot`: 提供与 Godot 运行时集成的适配实现。
- `GFramework.Ecs.Arch`: 提供 ECS Architecture 相关扩展。
- `GFramework.SourceGenerators` 及相关 Abstractions/Common: 提供代码生成能力。
这种结构的核心设计目标是让抽象稳定、实现可替换、引擎集成隔离、生成器能力可独立演进。
## Documentation Structure
项目文档位于 `docs/`,中文内容位于 `docs/zh-CN/`。文档内容覆盖:
- 入门与安装
- Core / Game / Godot / ECS 各模块能力
- Source Generator 使用说明
- 教程、最佳实践与故障排查
阅读顺序通常建议先看根目录 `README.md` 和各子模块 `README.md`,再进入 `docs/` 查阅专题说明。
## Design Intent
GFramework 的设计重点不是把所有能力堆进单一核心类,而是通过清晰的模块边界、可组合的服务注册方式、稳定的抽象契约以及适度自动化的源码生成,构建一个适合长期演进的游戏开发基础框架。

View File

@ -0,0 +1,42 @@
using System.Collections.Concurrent;
namespace GFramework.Core.Abstractions.Architectures;
/// <summary>
/// 架构模块注册表 - 用于外部模块的自动注册
/// </summary>
public static class ArchitectureModuleRegistry
{
private static readonly ConcurrentDictionary<string, Func<IServiceModule>> Factories = new(StringComparer.Ordinal);
/// <summary>
/// 注册模块工厂(幂等操作,相同模块名只会注册一次)
/// </summary>
/// <param name="factory">模块工厂函数</param>
public static void Register(Func<IServiceModule> factory)
{
// 创建临时实例以获取模块名(用于幂等性检查)
var tempModule = factory();
var moduleName = tempModule.ModuleName;
// 幂等注册:相同模块名只注册一次
Factories.TryAdd(moduleName, factory);
}
/// <summary>
/// 创建所有已注册的模块实例
/// </summary>
/// <returns>模块实例集合</returns>
public static IEnumerable<IServiceModule> CreateModules()
{
return Factories.Values.Select(f => f());
}
/// <summary>
/// 清空注册表(主要用于测试)
/// </summary>
public static void Clear()
{
Factories.Clear();
}
}

View File

@ -1,10 +1,10 @@
using GFramework.Core.Abstractions.lifecycle;
using GFramework.Core.Abstractions.model;
using GFramework.Core.Abstractions.system;
using GFramework.Core.Abstractions.utility;
using GFramework.Core.Abstractions.Lifecycle;
using GFramework.Core.Abstractions.Model;
using GFramework.Core.Abstractions.Systems;
using GFramework.Core.Abstractions.Utility;
using Microsoft.Extensions.DependencyInjection;
namespace GFramework.Core.Abstractions.architecture;
namespace GFramework.Core.Abstractions.Architectures;
/// <summary>
/// 架构接口,专注于生命周期管理,包括系统、模型、工具的注册和获取

View File

@ -1,6 +1,6 @@
using GFramework.Core.Abstractions.properties;
using GFramework.Core.Abstractions.Properties;
namespace GFramework.Core.Abstractions.architecture;
namespace GFramework.Core.Abstractions.Architectures;
/// <summary>
/// 定义架构配置的接口,提供日志工厂、日志级别和架构选项的配置功能

View File

@ -1,15 +1,14 @@
using GFramework.Core.Abstractions.command;
using GFramework.Core.Abstractions.ecs;
using GFramework.Core.Abstractions.environment;
using GFramework.Core.Abstractions.events;
using GFramework.Core.Abstractions.model;
using GFramework.Core.Abstractions.query;
using GFramework.Core.Abstractions.system;
using GFramework.Core.Abstractions.utility;
using GFramework.Core.Abstractions.Command;
using GFramework.Core.Abstractions.Environment;
using GFramework.Core.Abstractions.Events;
using GFramework.Core.Abstractions.Model;
using GFramework.Core.Abstractions.Query;
using GFramework.Core.Abstractions.Systems;
using GFramework.Core.Abstractions.Utility;
using Mediator;
using ICommand = GFramework.Core.Abstractions.command.ICommand;
using ICommand = GFramework.Core.Abstractions.Command.ICommand;
namespace GFramework.Core.Abstractions.architecture;
namespace GFramework.Core.Abstractions.Architectures;
/// <summary>
/// 架构上下文接口,提供对系统、模型、工具类的访问以及命令、查询、事件的发送和注册功能
@ -20,29 +19,89 @@ public interface IArchitectureContext
/// 获取指定类型的服务实例
/// </summary>
/// <typeparam name="TService">服务类型</typeparam>
/// <returns>服务实例如果不存在则返回null</returns>
TService? GetService<TService>() where TService : class;
/// <returns>服务实例,如果不存在则抛出异常</returns>
TService GetService<TService>() where TService : class;
/// <summary>
/// 获取指定类型的所有服务实例
/// </summary>
/// <typeparam name="TService">服务类型</typeparam>
/// <returns>所有符合条件的服务实例列表</returns>
IReadOnlyList<TService> GetServices<TService>() where TService : class;
/// <summary>
/// 获取指定类型的系统实例
/// </summary>
/// <typeparam name="TSystem">系统类型必须继承自ISystem接口</typeparam>
/// <returns>系统实例如果不存在则返回null</returns>
TSystem? GetSystem<TSystem>() where TSystem : class, ISystem;
/// <returns>系统实例,如果不存在则抛出异常</returns>
TSystem GetSystem<TSystem>() where TSystem : class, ISystem;
/// <summary>
/// 获取指定类型的所有系统实例
/// </summary>
/// <typeparam name="TSystem">系统类型必须继承自ISystem接口</typeparam>
/// <returns>所有符合条件的系统实例列表</returns>
IReadOnlyList<TSystem> GetSystems<TSystem>() where TSystem : class, ISystem;
/// <summary>
/// 获取指定类型的模型实例
/// </summary>
/// <typeparam name="TModel">模型类型必须继承自IModel接口</typeparam>
/// <returns>模型实例如果不存在则返回null</returns>
TModel? GetModel<TModel>() where TModel : class, IModel;
/// <returns>模型实例,如果不存在则抛出异常</returns>
TModel GetModel<TModel>() where TModel : class, IModel;
/// <summary>
/// 获取指定类型的所有模型实例
/// </summary>
/// <typeparam name="TModel">模型类型必须继承自IModel接口</typeparam>
/// <returns>所有符合条件的模型实例列表</returns>
IReadOnlyList<TModel> GetModels<TModel>() where TModel : class, IModel;
/// <summary>
/// 获取指定类型的工具类实例
/// </summary>
/// <typeparam name="TUtility">工具类类型必须继承自IUtility接口</typeparam>
/// <returns>工具类实例如果不存在则返回null</returns>
TUtility? GetUtility<TUtility>() where TUtility : class, IUtility;
/// <returns>工具类实例,如果不存在则抛出异常</returns>
TUtility GetUtility<TUtility>() where TUtility : class, IUtility;
/// <summary>
/// 获取指定类型的所有工具类实例
/// </summary>
/// <typeparam name="TUtility">工具类类型必须继承自IUtility接口</typeparam>
/// <returns>所有符合条件的工具类实例列表</returns>
IReadOnlyList<TUtility> GetUtilities<TUtility>() where TUtility : class, IUtility;
/// <summary>
/// 获取指定类型的所有服务实例,并按优先级排序
/// 实现 IPrioritized 接口的服务将按优先级排序(数值越小优先级越高)
/// </summary>
/// <typeparam name="TService">服务类型</typeparam>
/// <returns>按优先级排序后的服务实例列表</returns>
IReadOnlyList<TService> GetServicesByPriority<TService>() where TService : class;
/// <summary>
/// 获取指定类型的所有系统实例,并按优先级排序
/// 实现 IPrioritized 接口的系统将按优先级排序(数值越小优先级越高)
/// </summary>
/// <typeparam name="TSystem">系统类型必须继承自ISystem接口</typeparam>
/// <returns>按优先级排序后的系统实例列表</returns>
IReadOnlyList<TSystem> GetSystemsByPriority<TSystem>() where TSystem : class, ISystem;
/// <summary>
/// 获取指定类型的所有模型实例,并按优先级排序
/// 实现 IPrioritized 接口的模型将按优先级排序(数值越小优先级越高)
/// </summary>
/// <typeparam name="TModel">模型类型必须继承自IModel接口</typeparam>
/// <returns>按优先级排序后的模型实例列表</returns>
IReadOnlyList<TModel> GetModelsByPriority<TModel>() where TModel : class, IModel;
/// <summary>
/// 获取指定类型的所有工具类实例,并按优先级排序
/// 实现 IPrioritized 接口的工具将按优先级排序(数值越小优先级越高)
/// </summary>
/// <typeparam name="TUtility">工具类类型必须继承自IUtility接口</typeparam>
/// <returns>按优先级排序后的工具类实例列表</returns>
IReadOnlyList<TUtility> GetUtilitiesByPriority<TUtility>() where TUtility : class, IUtility;
/// <summary>
/// 发送一个命令
@ -56,7 +115,7 @@ public interface IArchitectureContext
/// <typeparam name="TResult">命令执行结果类型</typeparam>
/// <param name="command">要发送的命令</param>
/// <returns>命令执行结果</returns>
TResult SendCommand<TResult>(command.ICommand<TResult> command);
TResult SendCommand<TResult>(Command.ICommand<TResult> command);
/// <summary>
/// [Mediator] 发送命令的同步版本(不推荐,仅用于兼容性)
@ -99,7 +158,7 @@ public interface IArchitectureContext
/// <typeparam name="TResult">查询结果类型</typeparam>
/// <param name="query">要发送的查询</param>
/// <returns>查询结果</returns>
TResult SendQuery<TResult>(query.IQuery<TResult> query);
TResult SendQuery<TResult>(Query.IQuery<TResult> query);
/// <summary>
/// [Mediator] 发送查询的同步版本(不推荐,仅用于兼容性)
@ -206,18 +265,4 @@ public interface IArchitectureContext
/// </summary>
/// <returns>环境对象实例</returns>
IEnvironment GetEnvironment();
// === ECS 支持 ===
/// <summary>
/// 获取ECS世界实例
/// </summary>
/// <returns>ECS世界实例</returns>
IEcsWorld GetEcsWorld();
/// <summary>
/// 注册ECS系统
/// </summary>
/// <typeparam name="T">ECS系统类型</typeparam>
void RegisterEcsSystem<T>() where T : class, IEcsSystem;
}

View File

@ -0,0 +1,21 @@
namespace GFramework.Core.Abstractions.Architectures;
/// <summary>
/// 架构上下文提供者接口,用于解耦上下文获取逻辑
/// </summary>
public interface IArchitectureContextProvider
{
/// <summary>
/// 获取当前的架构上下文
/// </summary>
/// <returns>架构上下文实例</returns>
IArchitectureContext GetContext();
/// <summary>
/// 尝试获取指定类型的架构上下文
/// </summary>
/// <typeparam name="T">架构上下文类型</typeparam>
/// <param name="context">输出的上下文实例</param>
/// <returns>如果成功获取则返回true否则返回false</returns>
bool TryGetContext<T>(out T? context) where T : class, IArchitectureContext;
}

View File

@ -1,6 +1,6 @@
using GFramework.Core.Abstractions.enums;
using GFramework.Core.Abstractions.Enums;
namespace GFramework.Core.Abstractions.architecture;
namespace GFramework.Core.Abstractions.Architectures;
/// <summary>
/// 架构生命周期钩子接口,用于在架构的不同生命周期阶段执行自定义逻辑。

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.architecture;
namespace GFramework.Core.Abstractions.Architectures;
/// <summary>
/// 架构模块接口,继承自架构生命周期接口。

View File

@ -1,6 +1,6 @@
using GFramework.Core.Abstractions.enums;
using GFramework.Core.Abstractions.Enums;
namespace GFramework.Core.Abstractions.architecture;
namespace GFramework.Core.Abstractions.Architectures;
/// <summary>
/// 架构阶段监听器接口,用于监听和响应架构生命周期中的不同阶段变化。

View File

@ -1,10 +1,10 @@
using GFramework.Core.Abstractions.command;
using GFramework.Core.Abstractions.events;
using GFramework.Core.Abstractions.ioc;
using GFramework.Core.Abstractions.query;
using GFramework.Core.Abstractions.rule;
using GFramework.Core.Abstractions.Command;
using GFramework.Core.Abstractions.Events;
using GFramework.Core.Abstractions.Ioc;
using GFramework.Core.Abstractions.Query;
using GFramework.Core.Abstractions.Rule;
namespace GFramework.Core.Abstractions.architecture;
namespace GFramework.Core.Abstractions.Architectures;
/// <summary>
/// 架构服务接口,定义了框架核心架构所需的服务组件

View File

@ -1,7 +1,7 @@
using GFramework.Core.Abstractions.ioc;
using GFramework.Core.Abstractions.lifecycle;
using GFramework.Core.Abstractions.Ioc;
using GFramework.Core.Abstractions.Lifecycle;
namespace GFramework.Core.Abstractions.architecture;
namespace GFramework.Core.Abstractions.Architectures;
/// <summary>
/// 服务模块接口,定义了服务模块的基本契约。

View File

@ -1,7 +1,6 @@
using GFramework.Core.Abstractions.ioc;
using GFramework.Core.Abstractions.properties;
using GFramework.Core.Abstractions.Ioc;
namespace GFramework.Core.Abstractions.architecture;
namespace GFramework.Core.Abstractions.Architectures;
/// <summary>
/// 服务模块管理器接口,用于管理架构中的服务模块。
@ -18,8 +17,7 @@ public interface IServiceModuleManager
/// 注册内置的服务模块。
/// </summary>
/// <param name="container">IoC容器实例用于解析依赖。</param>
/// <param name="properties">架构属性配置,用于模块初始化。</param>
void RegisterBuiltInModules(IIocContainer container, ArchitectureProperties properties);
void RegisterBuiltInModules(IIocContainer container);
/// <summary>
/// 获取所有已注册的服务模块。

View File

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
namespace GFramework.Core.Abstractions.bases;
namespace GFramework.Core.Abstractions.Bases;
/// <summary>
/// 定义具有键值访问能力的接口契约

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.bases;
namespace GFramework.Core.Abstractions.Bases;
/// <summary>
/// 表示键值对的接口,定义了通用的键值对数据结构契约

View File

@ -0,0 +1,17 @@
namespace GFramework.Core.Abstractions.Bases;
/// <summary>
/// 定义具有优先级的对象接口。
/// 数值越小优先级越高,越先执行。
/// 用于控制服务、系统等组件的执行顺序。
/// </summary>
public interface IPrioritized
{
/// <summary>
/// 获取优先级值。
/// 数值越小优先级越高。
/// 默认优先级为 0。
/// 建议范围:-1000 到 1000。
/// </summary>
int Priority { get; }
}

View File

@ -0,0 +1,71 @@
namespace GFramework.Core.Abstractions.Bases;
/// <summary>
/// 预定义的优先级分组常量
/// </summary>
/// <remarks>
/// 提供标准化的优先级值,用于统一管理系统、服务等组件的执行顺序。
/// 优先级值越小,优先级越高(负数表示高优先级)。
/// </remarks>
public static class PriorityGroup
{
/// <summary>
/// 关键优先级 - 最高优先级,用于核心系统和基础设施
/// </summary>
/// <remarks>
/// 适用场景:
/// - 日志系统
/// - 配置管理
/// - IoC 容器初始化
/// - 架构核心组件
/// </remarks>
public const int Critical = -100;
/// <summary>
/// 高优先级 - 用于重要但非核心的系统
/// </summary>
/// <remarks>
/// 适用场景:
/// - 事件总线
/// - 资源管理器
/// - 输入系统
/// - 网络管理器
/// </remarks>
public const int High = -50;
/// <summary>
/// 普通优先级 - 默认优先级
/// </summary>
/// <remarks>
/// 适用场景:
/// - 游戏逻辑系统
/// - UI 系统
/// - 音频系统
/// - 大部分业务逻辑
/// </remarks>
public const int Normal = 0;
/// <summary>
/// 低优先级 - 用于非关键系统
/// </summary>
/// <remarks>
/// 适用场景:
/// - 统计系统
/// - 调试工具
/// - 性能监控
/// - 辅助功能
/// </remarks>
public const int Low = 50;
/// <summary>
/// 延迟优先级 - 最低优先级,用于可延迟执行的系统
/// </summary>
/// <remarks>
/// 适用场景:
/// - 分析和遥测
/// - 后台数据同步
/// - 缓存清理
/// - 非紧急任务
/// </remarks>
public const int Deferred = 100;
}

View File

@ -1,6 +1,6 @@
using GFramework.Core.Abstractions.rule;
using GFramework.Core.Abstractions.Rule;
namespace GFramework.Core.Abstractions.command;
namespace GFramework.Core.Abstractions.Command;
/// <summary>
/// 表示一个异步命令接口,该命令不返回结果

View File

@ -1,6 +1,6 @@
using GFramework.Core.Abstractions.rule;
using GFramework.Core.Abstractions.Rule;
namespace GFramework.Core.Abstractions.command;
namespace GFramework.Core.Abstractions.Command;
/// <summary>
/// 命令接口,定义了无返回值命令的基本契约

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.command;
namespace GFramework.Core.Abstractions.Command;
/// <summary>
/// 定义命令执行器接口,提供同步和异步方式发送并执行命令的方法。

View File

@ -0,0 +1,49 @@
// Copyright (c) 2025 GeWuYou
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using GFramework.Core.Abstractions.Utility;
namespace GFramework.Core.Abstractions.Concurrency;
/// <summary>
/// 异步键锁管理器接口,提供基于键的细粒度锁机制
/// </summary>
public interface IAsyncKeyLockManager : IUtility, IDisposable
{
/// <summary>
/// 异步获取指定键的锁(推荐使用)
/// </summary>
/// <param name="key">锁键</param>
/// <param name="cancellationToken">取消令牌</param>
/// <returns>锁句柄,使用 await using 自动释放</returns>
ValueTask<IAsyncLockHandle> AcquireLockAsync(string key, CancellationToken cancellationToken = default);
/// <summary>
/// 同步获取指定键的锁(兼容性方法)
/// </summary>
/// <param name="key">锁键</param>
/// <returns>锁句柄,使用 using 自动释放</returns>
IAsyncLockHandle AcquireLock(string key);
/// <summary>
/// 获取锁管理器的统计信息
/// </summary>
/// <returns>统计信息快照</returns>
LockStatistics GetStatistics();
/// <summary>
/// 获取当前活跃的锁信息(用于调试)
/// </summary>
/// <returns>键到锁信息的只读字典</returns>
IReadOnlyDictionary<string, LockInfo> GetActiveLocks();
}

View File

@ -1,33 +1,30 @@
// Copyright (c) 2025 GeWuYou
// Copyright (c) 2025 GeWuYou
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace GFramework.Core.functional.pipe;
namespace GFramework.Core.Abstractions.Concurrency;
/// <summary>
/// 提供函数式编程中的管道和组合操作扩展方
/// 异步锁句柄接口,支持 await using 语
/// </summary>
public static class PipeExtensions
public interface IAsyncLockHandle : IAsyncDisposable, IDisposable
{
/// <summary>
/// Also
/// 对值执行副作用操作并返回原值
/// 适用于日志、调试、状态同步等场景
/// 锁的键
/// </summary>
public static T Also<T>(
this T value,
Action<T> action)
{
action(value);
return value;
}
string Key { get; }
/// <summary>
/// 锁获取时的时间戳Environment.TickCount64
/// </summary>
long AcquiredTicks { get; }
}

View File

@ -0,0 +1,43 @@
// Copyright (c) 2025 GeWuYou
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace GFramework.Core.Abstractions.Concurrency;
/// <summary>
/// 锁信息(用于调试)
/// </summary>
public readonly struct LockInfo
{
/// <summary>
/// 锁的键。
/// </summary>
public string Key { get; init; }
/// <summary>
/// 当前引用计数。
/// </summary>
public int ReferenceCount { get; init; }
/// <summary>
/// 最后访问时间戳Environment.TickCount64
/// </summary>
public long LastAccessTicks { get; init; }
/// <summary>
/// 等待队列长度(近似值)。
/// 注意:这是一个基于 SemaphoreSlim.CurrentCount 的近似指示器,
/// 当 CurrentCount == 0 时表示锁被持有且可能有等待者,返回 1
/// 否则返回 0。这不是精确的等待者数量仅用于调试参考。
/// </summary>
public int WaitingCount { get; init; }
}

View File

@ -0,0 +1,43 @@
// Copyright (c) 2025 GeWuYou
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Runtime.InteropServices;
namespace GFramework.Core.Abstractions.Concurrency;
/// <summary>
/// 锁统计信息
/// </summary>
[StructLayout(LayoutKind.Auto)]
public readonly struct LockStatistics
{
/// <summary>
/// 当前活跃的锁数量
/// </summary>
public int ActiveLockCount { get; init; }
/// <summary>
/// 累计获取锁的次数
/// </summary>
public int TotalAcquired { get; init; }
/// <summary>
/// 累计释放锁的次数
/// </summary>
public int TotalReleased { get; init; }
/// <summary>
/// 累计清理的锁数量
/// </summary>
public int TotalCleaned { get; init; }
}

View File

@ -0,0 +1,99 @@
using GFramework.Core.Abstractions.Events;
using GFramework.Core.Abstractions.Utility;
namespace GFramework.Core.Abstractions.Configuration;
/// <summary>
/// 配置管理器接口,提供类型安全的配置存储和访问
/// 线程安全:所有方法都是线程安全的
/// </summary>
public interface IConfigurationManager : IUtility
{
/// <summary>
/// 获取配置数量
/// </summary>
int Count { get; }
/// <summary>
/// 获取指定键的配置值
/// </summary>
/// <typeparam name="T">配置值类型</typeparam>
/// <param name="key">配置键</param>
/// <returns>配置值,如果不存在则返回类型默认值</returns>
T? GetConfig<T>(string key);
/// <summary>
/// 获取指定键的配置值,如果不存在则返回默认值
/// </summary>
/// <typeparam name="T">配置值类型</typeparam>
/// <param name="key">配置键</param>
/// <param name="defaultValue">默认值</param>
/// <returns>配置值或默认值</returns>
T GetConfig<T>(string key, T defaultValue);
/// <summary>
/// 设置指定键的配置值
/// </summary>
/// <typeparam name="T">配置值类型</typeparam>
/// <param name="key">配置键</param>
/// <param name="value">配置值</param>
void SetConfig<T>(string key, T value);
/// <summary>
/// 检查指定键的配置是否存在
/// </summary>
/// <param name="key">配置键</param>
/// <returns>如果存在返回 true否则返回 false</returns>
bool HasConfig(string key);
/// <summary>
/// 移除指定键的配置
/// </summary>
/// <param name="key">配置键</param>
/// <returns>如果成功移除返回 true否则返回 false</returns>
bool RemoveConfig(string key);
/// <summary>
/// 清空所有配置
/// </summary>
void Clear();
/// <summary>
/// 监听指定键的配置变化
/// </summary>
/// <typeparam name="T">配置值类型</typeparam>
/// <param name="key">配置键</param>
/// <param name="onChange">配置变化时的回调,参数为新值</param>
/// <returns>取消注册接口</returns>
IUnRegister WatchConfig<T>(string key, Action<T> onChange);
/// <summary>
/// 从 JSON 字符串加载配置
/// </summary>
/// <param name="json">JSON 字符串</param>
void LoadFromJson(string json);
/// <summary>
/// 将配置保存为 JSON 字符串
/// </summary>
/// <returns>JSON 字符串</returns>
string SaveToJson();
/// <summary>
/// 从文件加载配置
/// </summary>
/// <param name="path">文件路径</param>
void LoadFromFile(string path);
/// <summary>
/// 将配置保存到文件
/// </summary>
/// <param name="path">文件路径</param>
void SaveToFile(string path);
/// <summary>
/// 获取所有配置键
/// </summary>
/// <returns>配置键集合</returns>
IEnumerable<string> GetAllKeys();
}

View File

@ -0,0 +1,38 @@
namespace GFramework.Core.Abstractions.Controller;
/// <summary>
/// 控制器标记接口,用于标识控制器组件
/// </summary>
/// <remarks>
/// <para>
/// IController 是一个标记接口Marker Interface不包含任何方法或属性。
/// 它的作用是标识一个类是控制器,用于协调 Model、System 和 UI 之间的交互。
/// </para>
/// <para>
/// 架构访问 :控制器通常需要访问架构上下文。使用 [ContextAware] 特性
/// 自动生成上下文访问能力:
/// </para>
/// <code>
/// using GFramework.SourceGenerators.Abstractions.Rule;
///
/// [ContextAware]
/// public partial class PlayerController : IController
/// {
/// public void Initialize()
/// {
/// // [ContextAware] 实现 IContextAware 接口,可使用扩展方法
/// var playerModel = this.GetModel&lt;PlayerModel&gt;();
/// var gameSystem = this.GetSystem&lt;GameSystem&gt;();
/// }
/// }
/// </code>
/// <para>
/// 注意:
/// </para>
/// <list type="bullet">
/// <item>必须添加 partial 关键字</item>
/// <item>[ContextAware] 特性会自动实现 IContextAware 接口</item>
/// <item>可使用 this.GetModel()、this.GetSystem() 等扩展方法访问架构</item>
/// </list>
/// </remarks>
public interface IController;

View File

@ -0,0 +1,33 @@
namespace GFramework.Core.Abstractions.Coroutine;
/// <summary>
/// 协程优先级枚举
/// 定义协程的执行优先级,高优先级的协程会优先执行
/// </summary>
public enum CoroutinePriority
{
/// <summary>
/// 最低优先级
/// </summary>
Lowest = 0,
/// <summary>
/// 低优先级
/// </summary>
Low = 1,
/// <summary>
/// 普通优先级(默认)
/// </summary>
Normal = 2,
/// <summary>
/// 高优先级
/// </summary>
High = 3,
/// <summary>
/// 最高优先级
/// </summary>
Highest = 4
}

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.coroutine;
namespace GFramework.Core.Abstractions.Coroutine;
/// <summary>
/// 表示协程的执行状态枚举

View File

@ -0,0 +1,68 @@
namespace GFramework.Core.Abstractions.Coroutine;
/// <summary>
/// 协程统计信息接口
/// 提供协程执行的性能统计数据
/// </summary>
public interface ICoroutineStatistics
{
/// <summary>
/// 获取总协程启动数量
/// </summary>
long TotalStarted { get; }
/// <summary>
/// 获取总协程完成数量
/// </summary>
long TotalCompleted { get; }
/// <summary>
/// 获取总协程失败数量
/// </summary>
long TotalFailed { get; }
/// <summary>
/// 获取当前活跃协程数量
/// </summary>
int ActiveCount { get; }
/// <summary>
/// 获取当前暂停协程数量
/// </summary>
int PausedCount { get; }
/// <summary>
/// 获取协程平均执行时间(毫秒)
/// </summary>
double AverageExecutionTimeMs { get; }
/// <summary>
/// 获取协程最大执行时间(毫秒)
/// </summary>
double MaxExecutionTimeMs { get; }
/// <summary>
/// 获取按优先级分组的协程数量
/// </summary>
/// <param name="priority">协程优先级</param>
/// <returns>指定优先级的协程数量</returns>
int GetCountByPriority(CoroutinePriority priority);
/// <summary>
/// 获取按标签分组的协程数量
/// </summary>
/// <param name="tag">协程标签</param>
/// <returns>指定标签的协程数量</returns>
int GetCountByTag(string tag);
/// <summary>
/// 重置统计数据
/// </summary>
void Reset();
/// <summary>
/// 生成统计报告
/// </summary>
/// <returns>格式化的统计报告字符串</returns>
string GenerateReport();
}

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.coroutine;
namespace GFramework.Core.Abstractions.Coroutine;
/// <summary>
/// 时间源接口,提供当前时间、时间增量以及更新功能

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.coroutine;
namespace GFramework.Core.Abstractions.Coroutine;
/// <summary>
/// 定义一个可等待指令的接口,用于协程系统中的异步操作控制

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.cqrs.command;
namespace GFramework.Core.Abstractions.Cqrs.Command;
/// <summary>
/// 命令输入接口,定义命令模式中输入数据的契约

View File

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
namespace GFramework.Core.Abstractions.cqrs;
namespace GFramework.Core.Abstractions.Cqrs;
/// <summary>
/// 表示输入数据的标记接口。

View File

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
namespace GFramework.Core.Abstractions.cqrs.notification;
namespace GFramework.Core.Abstractions.Cqrs.Notification;
/// <summary>
/// 表示通知输入数据的标记接口。

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.cqrs.query;
namespace GFramework.Core.Abstractions.Cqrs.Query;
/// <summary>
/// 查询输入接口,定义了查询操作的输入规范

View File

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
namespace GFramework.Core.Abstractions.cqrs.request;
namespace GFramework.Core.Abstractions.Cqrs.Request;
/// <summary>
/// 表示请求输入数据的标记接口。

View File

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
namespace GFramework.Core.Abstractions.data;
namespace GFramework.Core.Abstractions.Data;
/// <summary>
/// 定义从指定类型数据源加载数据的接口

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.enums;
namespace GFramework.Core.Abstractions.Enums;
/// <summary>
/// 架构阶段枚举,定义了系统架构初始化和运行过程中的各个关键阶段

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.environment;
namespace GFramework.Core.Abstractions.Environment;
/// <summary>
/// 定义环境接口,提供应用程序运行环境的相关信息

View File

@ -0,0 +1,26 @@
namespace GFramework.Core.Abstractions.Events;
/// <summary>
/// 事件上下文,包装事件数据并提供控制方法
/// </summary>
/// <typeparam name="T">事件数据类型</typeparam>
public class EventContext<T>(T data)
{
/// <summary>
/// 事件数据
/// </summary>
public T Data { get; } = data;
/// <summary>
/// 事件是否已被处理
/// </summary>
public bool IsHandled { get; private set; }
/// <summary>
/// 标记事件为已处理,停止后续传播(仅对 UntilHandled 模式有效)
/// </summary>
public void MarkAsHandled()
{
IsHandled = true;
}
}

View File

@ -0,0 +1,22 @@
namespace GFramework.Core.Abstractions.Events;
/// <summary>
/// 事件传播模式
/// </summary>
public enum EventPropagation
{
/// <summary>
/// 传播到所有处理器
/// </summary>
All,
/// <summary>
/// 传播直到某个处理器标记为已处理
/// </summary>
UntilHandled,
/// <summary>
/// 仅传播到最高优先级的处理器
/// </summary>
Highest
}

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.events;
namespace GFramework.Core.Abstractions.Events;
/// <summary>
/// 事件接口,定义了事件注册的基本功能

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.events;
namespace GFramework.Core.Abstractions.Events;
/// <summary>
/// 事件总线接口,提供事件的发送、注册和注销功能
@ -18,6 +18,14 @@ public interface IEventBus
/// <param name="e">事件实例</param>
void Send<T>(T e);
/// <summary>
/// 发送指定的事件实例,并指定传播模式
/// </summary>
/// <typeparam name="T">事件类型</typeparam>
/// <param name="e">事件实例</param>
/// <param name="propagation">事件传播模式</param>
void Send<T>(T e, EventPropagation propagation);
/// <summary>
/// 注册事件监听器
/// </summary>
@ -26,6 +34,15 @@ public interface IEventBus
/// <returns>反注册接口,用于注销事件监听</returns>
IUnRegister Register<T>(Action<T> onEvent);
/// <summary>
/// 注册事件监听器,并指定优先级
/// </summary>
/// <typeparam name="T">事件类型</typeparam>
/// <param name="onEvent">事件处理回调函数</param>
/// <param name="priority">优先级,数值越大优先级越高</param>
/// <returns>反注册接口,用于注销事件监听</returns>
IUnRegister Register<T>(Action<T> onEvent, int priority);
/// <summary>
/// 注销事件监听器
/// </summary>

View File

@ -0,0 +1,16 @@
namespace GFramework.Core.Abstractions.Events;
/// <summary>
/// 事件过滤器接口
/// 用于在事件触发前进行条件判断,决定是否允许事件传递给监听器
/// </summary>
/// <typeparam name="T">事件类型</typeparam>
public interface IEventFilter<in T>
{
/// <summary>
/// 判断事件是否应该被过滤(阻止传递)
/// </summary>
/// <param name="eventData">事件数据</param>
/// <returns>如果返回 true则事件被过滤不传递给监听器如果返回 false则允许传递</returns>
bool ShouldFilter(T eventData);
}

View File

@ -0,0 +1,58 @@
namespace GFramework.Core.Abstractions.Events;
/// <summary>
/// 事件统计信息接口
/// 提供事件系统的性能统计数据
/// </summary>
public interface IEventStatistics
{
/// <summary>
/// 获取总事件发布数量
/// </summary>
long TotalPublished { get; }
/// <summary>
/// 获取总事件处理数量(监听器调用次数)
/// </summary>
long TotalHandled { get; }
/// <summary>
/// 获取总事件处理失败数量
/// </summary>
long TotalFailed { get; }
/// <summary>
/// 获取当前活跃的事件类型数量
/// </summary>
int ActiveEventTypes { get; }
/// <summary>
/// 获取当前活跃的监听器总数
/// </summary>
int ActiveListeners { get; }
/// <summary>
/// 获取指定事件类型的发布次数
/// </summary>
/// <param name="eventType">事件类型名称</param>
/// <returns>发布次数</returns>
long GetPublishCount(string eventType);
/// <summary>
/// 获取指定事件类型的监听器数量
/// </summary>
/// <param name="eventType">事件类型名称</param>
/// <returns>监听器数量</returns>
int GetListenerCount(string eventType);
/// <summary>
/// 重置统计数据
/// </summary>
void Reset();
/// <summary>
/// 生成统计报告
/// </summary>
/// <returns>格式化的统计报告字符串</returns>
string GenerateReport();
}

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.events;
namespace GFramework.Core.Abstractions.Events;
/// <summary>
/// 提供注销功能的接口

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.events;
namespace GFramework.Core.Abstractions.Events;
/// <summary>
/// 提供统一注销功能的接口,用于管理需要注销的对象列表

View File

@ -17,15 +17,14 @@
<Using Include="GFramework.Core.Abstractions"/>
</ItemGroup>
<ItemGroup>
<PackageReference Update="Meziantou.Analyzer" Version="3.0.12">
<PackageReference Update="Meziantou.Analyzer" Version="3.0.25">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Update="Meziantou.Polyfill" Version="1.0.101">
<PackageReference Update="Meziantou.Polyfill" Version="1.0.104">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Arch" Version="2.1.0"/>
<PackageReference Include="Mediator.Abstractions" Version="3.0.1"/>
</ItemGroup>
</Project>

View File

@ -1,18 +1,20 @@
// IsExternalInit.cs
// This type is required to support init-only setters and record types
// when targeting netstandard2.0 or older frameworks.
#if !NET5_0_OR_GREATER
using System.ComponentModel;
namespace System.Runtime.CompilerServices;
/// <summary>
/// 提供一个占位符类型,用于支持 C# 9.0 的 init 访问器功能。
/// 该类型在 .NET 5.0 及更高版本中已内置,因此仅在较低版本的 .NET 中定义。
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit
{
}
// IsExternalInit.cs
// This type is required to support init-only setters and record types
// when targeting netstandard2.0 or older frameworks.
#if !NET5_0_OR_GREATER
using System.ComponentModel;
// ReSharper disable CheckNamespace
namespace System.Runtime.CompilerServices;
/// <summary>
/// 提供一个占位符类型,用于支持 C# 9.0 的 init 访问器功能。
/// 该类型在 .NET 5.0 及更高版本中已内置,因此仅在较低版本的 .NET 中定义。
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit
{
}
#endif

View File

@ -1,8 +1,8 @@
using GFramework.Core.Abstractions.rule;
using GFramework.Core.Abstractions.system;
using GFramework.Core.Abstractions.Rule;
using GFramework.Core.Abstractions.Systems;
using Microsoft.Extensions.DependencyInjection;
namespace GFramework.Core.Abstractions.ioc;
namespace GFramework.Core.Abstractions.Ioc;
/// <summary>
/// 依赖注入容器接口,定义了服务注册、解析和管理的基本操作
@ -29,6 +29,24 @@ public interface IIocContainer : IContextAware
void RegisterSingleton<TService, TImpl>()
where TImpl : class, TService where TService : class;
/// <summary>
/// 注册瞬态服务,指定服务类型和实现类型
/// 每次解析时都会创建新的实例
/// </summary>
/// <typeparam name="TService">服务接口或基类类型</typeparam>
/// <typeparam name="TImpl">具体的实现类型</typeparam>
void RegisterTransient<TService, TImpl>()
where TImpl : class, TService where TService : class;
/// <summary>
/// 注册作用域服务,指定服务类型和实现类型
/// 在同一作用域内共享实例,不同作用域使用不同实例
/// </summary>
/// <typeparam name="TService">服务接口或基类类型</typeparam>
/// <typeparam name="TImpl">具体的实现类型</typeparam>
void RegisterScoped<TService, TImpl>()
where TImpl : class, TService where TService : class;
/// <summary>
/// 注册多个实例
/// 将实例注册到其实现的所有接口和具体类型上
@ -147,6 +165,24 @@ public interface IIocContainer : IContextAware
/// <returns>按指定方式排序后的实例列表</returns>
IReadOnlyList<T> GetAllSorted<T>(Comparison<T> comparison) where T : class;
/// <summary>
/// 获取指定类型的所有实例,并按优先级排序
/// 实现 IPrioritized 接口的服务将按优先级排序(数值越小优先级越高)
/// 未实现 IPrioritized 的服务将使用默认优先级 0
/// </summary>
/// <typeparam name="T">期望获取的实例类型</typeparam>
/// <returns>按优先级排序后的实例列表</returns>
IReadOnlyList<T> GetAllByPriority<T>() where T : class;
/// <summary>
/// 获取指定类型的所有实例,并按优先级排序
/// 实现 IPrioritized 接口的服务将按优先级排序(数值越小优先级越高)
/// 未实现 IPrioritized 的服务将使用默认优先级 0
/// </summary>
/// <param name="type">期望获取的实例类型</param>
/// <returns>按优先级排序后的实例列表</returns>
IReadOnlyList<object> GetAllByPriority(Type type);
#endregion
#region Utility Methods
@ -183,5 +219,12 @@ public interface IIocContainer : IContextAware
/// <returns>底层的IServiceCollection实例</returns>
IServiceCollection GetServicesUnsafe { get; }
/// <summary>
/// 创建一个新的服务作用域
/// 作用域内的 Scoped 服务将共享同一实例
/// </summary>
/// <returns>服务作用域实例</returns>
IServiceScope CreateScope();
#endregion
}

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.lifecycle;
namespace GFramework.Core.Abstractions.Lifecycle;
/// <summary>
/// 定义异步销毁接口,用于需要异步清理资源的组件

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.lifecycle;
namespace GFramework.Core.Abstractions.Lifecycle;
/// <summary>
/// 定义异步初始化接口,用于需要异步初始化的组件或服务

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.lifecycle;
namespace GFramework.Core.Abstractions.Lifecycle;
/// <summary>
/// 定义异步生命周期接口,组合了异步初始化和异步销毁

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.lifecycle;
namespace GFramework.Core.Abstractions.Lifecycle;
/// <summary>
/// 可销毁接口,为需要资源清理的组件提供标准销毁能力

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.lifecycle;
namespace GFramework.Core.Abstractions.Lifecycle;
/// <summary>
/// 可初始化接口,为需要初始化的组件提供标准初始化能力

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.lifecycle;
namespace GFramework.Core.Abstractions.Lifecycle;
/// <summary>
/// 完整生命周期接口,组合了初始化和销毁能力

View File

@ -0,0 +1,22 @@
namespace GFramework.Core.Abstractions.Localization;
/// <summary>
/// 本地化格式化器接口
/// </summary>
public interface ILocalizationFormatter
{
/// <summary>
/// 格式化器名称
/// </summary>
string Name { get; }
/// <summary>
/// 尝试格式化值
/// </summary>
/// <param name="format">格式字符串</param>
/// <param name="value">要格式化的值</param>
/// <param name="provider">格式提供者</param>
/// <param name="result">格式化结果</param>
/// <returns>是否成功格式化</returns>
bool TryFormat(string format, object value, IFormatProvider? provider, out string result);
}

View File

@ -0,0 +1,89 @@
using System.Globalization;
using GFramework.Core.Abstractions.Systems;
namespace GFramework.Core.Abstractions.Localization;
/// <summary>
/// 本地化管理器接口
/// </summary>
public interface ILocalizationManager : ISystem
{
/// <summary>
/// 当前语言代码
/// </summary>
string CurrentLanguage { get; }
/// <summary>
/// 当前文化信息
/// </summary>
CultureInfo CurrentCulture { get; }
/// <summary>
/// 可用语言列表
/// </summary>
IReadOnlyList<string> AvailableLanguages { get; }
/// <summary>
/// 设置当前语言
/// </summary>
/// <param name="languageCode">语言代码</param>
void SetLanguage(string languageCode);
/// <summary>
/// 获取本地化表
/// </summary>
/// <param name="tableName">表名</param>
/// <returns>本地化表</returns>
ILocalizationTable GetTable(string tableName);
/// <summary>
/// 获取本地化文本
/// </summary>
/// <param name="table">表名</param>
/// <param name="key">键名</param>
/// <returns>本地化文本</returns>
string GetText(string table, string key);
/// <summary>
/// 获取本地化字符串(支持变量和格式化)
/// </summary>
/// <param name="table">表名</param>
/// <param name="key">键名</param>
/// <returns>本地化字符串</returns>
ILocalizationString GetString(string table, string key);
/// <summary>
/// 尝试获取本地化文本
/// </summary>
/// <param name="table">表名</param>
/// <param name="key">键名</param>
/// <param name="text">输出文本</param>
/// <returns>是否成功获取</returns>
bool TryGetText(string table, string key, out string text);
/// <summary>
/// 注册格式化器
/// </summary>
/// <param name="name">格式化器名称</param>
/// <param name="formatter">格式化器实例</param>
void RegisterFormatter(string name, ILocalizationFormatter formatter);
/// <summary>
/// 获取格式化器
/// </summary>
/// <param name="name">格式化器名称</param>
/// <returns>格式化器实例,如果不存在则返回 null</returns>
ILocalizationFormatter? GetFormatter(string name);
/// <summary>
/// 订阅语言变化事件
/// </summary>
/// <param name="callback">回调函数</param>
void SubscribeToLanguageChange(Action<string> callback);
/// <summary>
/// 取消订阅语言变化事件
/// </summary>
/// <param name="callback">回调函数</param>
void UnsubscribeFromLanguageChange(Action<string> callback);
}

View File

@ -0,0 +1,50 @@
namespace GFramework.Core.Abstractions.Localization;
/// <summary>
/// 本地化字符串接口(支持变量和格式化)
/// </summary>
public interface ILocalizationString
{
/// <summary>
/// 表名
/// </summary>
string Table { get; }
/// <summary>
/// 键名
/// </summary>
string Key { get; }
/// <summary>
/// 添加变量
/// </summary>
/// <param name="name">变量名</param>
/// <param name="value">变量值</param>
/// <returns>当前实例(支持链式调用)</returns>
ILocalizationString WithVariable(string name, object value);
/// <summary>
/// 批量添加变量
/// </summary>
/// <param name="variables">变量数组</param>
/// <returns>当前实例(支持链式调用)</returns>
ILocalizationString WithVariables(params (string name, object value)[] variables);
/// <summary>
/// 格式化并返回最终文本
/// </summary>
/// <returns>格式化后的文本</returns>
string Format();
/// <summary>
/// 获取原始文本(不进行格式化)
/// </summary>
/// <returns>原始文本</returns>
string GetRaw();
/// <summary>
/// 检查键是否存在
/// </summary>
/// <returns>是否存在</returns>
bool Exists();
}

View File

@ -0,0 +1,48 @@
namespace GFramework.Core.Abstractions.Localization;
/// <summary>
/// 本地化表接口
/// </summary>
public interface ILocalizationTable
{
/// <summary>
/// 表名
/// </summary>
string Name { get; }
/// <summary>
/// 语言代码
/// </summary>
string Language { get; }
/// <summary>
/// 回退表(当前表中找不到键时使用)
/// </summary>
ILocalizationTable? Fallback { get; }
/// <summary>
/// 获取原始文本(不进行格式化)
/// </summary>
/// <param name="key">键名</param>
/// <returns>原始文本</returns>
string GetRawText(string key);
/// <summary>
/// 检查是否包含指定键
/// </summary>
/// <param name="key">键名</param>
/// <returns>是否包含</returns>
bool ContainsKey(string key);
/// <summary>
/// 获取所有键
/// </summary>
/// <returns>键集合</returns>
IEnumerable<string> GetKeys();
/// <summary>
/// 合并覆盖数据
/// </summary>
/// <param name="overrides">覆盖数据</param>
void Merge(IReadOnlyDictionary<string, string> overrides);
}

View File

@ -0,0 +1,37 @@
namespace GFramework.Core.Abstractions.Localization;
/// <summary>
/// 本地化配置
/// </summary>
public class LocalizationConfig
{
/// <summary>
/// 默认语言代码
/// </summary>
public string DefaultLanguage { get; set; } = "eng";
/// <summary>
/// 回退语言代码(当目标语言缺少键时使用)
/// </summary>
public string FallbackLanguage { get; set; } = "eng";
/// <summary>
/// 本地化文件路径Godot 资源路径)
/// </summary>
public string LocalizationPath { get; set; } = "res://localization";
/// <summary>
/// 用户覆盖文件路径(用于热更新和自定义翻译)
/// </summary>
public string OverridePath { get; set; } = "user://localization_override";
/// <summary>
/// 是否启用热重载(监视覆盖文件变化)
/// </summary>
public bool EnableHotReload { get; set; } = true;
/// <summary>
/// 是否在加载时验证本地化文件
/// </summary>
public bool ValidateOnLoad { get; set; } = true;
}

View File

@ -0,0 +1,31 @@
namespace GFramework.Core.Abstractions.Localization;
/// <summary>
/// 本地化异常基类
/// </summary>
public class LocalizationException : Exception
{
/// <summary>
/// 初始化本地化异常
/// </summary>
public LocalizationException()
{
}
/// <summary>
/// 初始化本地化异常
/// </summary>
/// <param name="message">异常消息</param>
public LocalizationException(string message) : base(message)
{
}
/// <summary>
/// 初始化本地化异常
/// </summary>
/// <param name="message">异常消息</param>
/// <param name="innerException">内部异常</param>
public LocalizationException(string message, Exception innerException) : base(message, innerException)
{
}
}

View File

@ -0,0 +1,29 @@
namespace GFramework.Core.Abstractions.Localization;
/// <summary>
/// 本地化键未找到异常
/// </summary>
public class LocalizationKeyNotFoundException : LocalizationException
{
/// <summary>
/// 初始化键未找到异常
/// </summary>
/// <param name="tableName">表名</param>
/// <param name="key">键名</param>
public LocalizationKeyNotFoundException(string tableName, string key)
: base($"Localization key '{key}' not found in table '{tableName}'")
{
TableName = tableName;
Key = key;
}
/// <summary>
/// 表名
/// </summary>
public string TableName { get; }
/// <summary>
/// 键名
/// </summary>
public string Key { get; }
}

View File

@ -0,0 +1,22 @@
namespace GFramework.Core.Abstractions.Localization;
/// <summary>
/// 本地化表未找到异常
/// </summary>
public class LocalizationTableNotFoundException : LocalizationException
{
/// <summary>
/// 初始化表未找到异常
/// </summary>
/// <param name="tableName">表名</param>
public LocalizationTableNotFoundException(string tableName)
: base($"Localization table '{tableName}' not found")
{
TableName = tableName;
}
/// <summary>
/// 表名
/// </summary>
public string TableName { get; }
}

View File

@ -0,0 +1,18 @@
namespace GFramework.Core.Abstractions.Logging;
/// <summary>
/// 日志输出器接口,负责将日志条目写入特定目标
/// </summary>
public interface ILogAppender : IDisposable
{
/// <summary>
/// 追加日志条目
/// </summary>
/// <param name="entry">日志条目</param>
void Append(LogEntry entry);
/// <summary>
/// 刷新缓冲区,确保所有日志已写入
/// </summary>
void Flush();
}

View File

@ -0,0 +1,14 @@
namespace GFramework.Core.Abstractions.Logging;
/// <summary>
/// 日志过滤器接口,用于决定是否应该记录某条日志
/// </summary>
public interface ILogFilter
{
/// <summary>
/// 判断是否应该记录该日志条目
/// </summary>
/// <param name="entry">日志条目</param>
/// <returns>如果应该记录返回 true否则返回 false</returns>
bool ShouldLog(LogEntry entry);
}

View File

@ -0,0 +1,14 @@
namespace GFramework.Core.Abstractions.Logging;
/// <summary>
/// 日志格式化器接口,用于将日志条目格式化为字符串
/// </summary>
public interface ILogFormatter
{
/// <summary>
/// 将日志条目格式化为字符串
/// </summary>
/// <param name="entry">日志条目</param>
/// <returns>格式化后的日志字符串</returns>
string Format(LogEntry entry);
}

View File

@ -1,4 +1,4 @@
namespace GFramework.Core.Abstractions.logging;
namespace GFramework.Core.Abstractions.Logging;
/// <summary>
/// 定义日志记录接口,提供日志记录和级别检查功能
@ -309,4 +309,48 @@ public interface ILogger
void Fatal(string msg, Exception t);
#endregion
#region Generic Log Methods
/// <summary>
/// 使用指定的日志级别记录消息
/// </summary>
/// <param name="level">日志级别</param>
/// <param name="message">要记录的消息字符串</param>
void Log(LogLevel level, string message);
/// <summary>
/// 使用指定的日志级别根据格式和参数记录消息
/// </summary>
/// <param name="level">日志级别</param>
/// <param name="format">格式字符串</param>
/// <param name="arg">参数</param>
void Log(LogLevel level, string format, object arg);
/// <summary>
/// 使用指定的日志级别根据格式和参数记录消息
/// </summary>
/// <param name="level">日志级别</param>
/// <param name="format">格式字符串</param>
/// <param name="arg1">第一个参数</param>
/// <param name="arg2">第二个参数</param>
void Log(LogLevel level, string format, object arg1, object arg2);
/// <summary>
/// 使用指定的日志级别根据格式和参数数组记录消息
/// </summary>
/// <param name="level">日志级别</param>
/// <param name="format">格式字符串</param>
/// <param name="arguments">参数数组</param>
void Log(LogLevel level, string format, params object[] arguments);
/// <summary>
/// 使用指定的日志级别记录消息和异常
/// </summary>
/// <param name="level">日志级别</param>
/// <param name="message">伴随异常的消息</param>
/// <param name="exception">要记录的异常</param>
void Log(LogLevel level, string message, Exception exception);
#endregion
}

Some files were not shown because too many files have changed in this diff Show More