mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
docs(core): 修复文档中的泛型符号显示问题
- 修复了配置模块文档中 GetConfig、SetConfig、WatchConfig 方法的泛型符号 - 修复了 ECS 模块文档中 ArchSystemAdapter 的泛型符号显示 - 修复了函数式编程文档中 Option 和 Result 类型的泛型符号 - 修复了序列化和存储模块中各类方法的泛型符号显示 - 修正了存储模块文档中的序列化系统链接路径 - 修复了函数式编程教程中 Option 和 Result 的泛型符号显示
This commit is contained in:
parent
84d7408bef
commit
c969a9a022
@ -78,8 +78,10 @@ export default defineConfig({
|
||||
{ text: '事件系统', link: '/zh-CN/core/events' },
|
||||
{ text: '属性系统', link: '/zh-CN/core/property' },
|
||||
{ text: 'IoC容器', link: '/zh-CN/core/ioc' },
|
||||
{ text: 'ECS 系统集成', link: '/zh-CN/core/ecs' },
|
||||
{ text: '对象池', link: '/zh-CN/core/pool' },
|
||||
{ text: '日志系统', link: '/zh-CN/core/logging' },
|
||||
{ text: '函数式编程', link: '/zh-CN/core/functional' },
|
||||
{ text: '扩展方法', link: '/zh-CN/core/extensions' },
|
||||
{ text: '工具类', link: '/zh-CN/core/utility' },
|
||||
{ text: '模型层', link: '/zh-CN/core/model' },
|
||||
@ -105,6 +107,10 @@ export default defineConfig({
|
||||
text: 'Godot 集成',
|
||||
items: [
|
||||
{ text: '概览', link: '/zh-CN/godot/' },
|
||||
{ text: '架构集成', link: '/zh-CN/godot/architecture' },
|
||||
{ text: '场景系统', link: '/zh-CN/godot/scene' },
|
||||
{ text: 'UI 系统', link: '/zh-CN/godot/ui' },
|
||||
{ text: '资源仓储', link: '/zh-CN/godot/resource' },
|
||||
{ text: '协程系统', link: '/zh-CN/godot/coroutine' },
|
||||
{ text: '节点扩展', link: '/zh-CN/godot/extensions' },
|
||||
{ text: '信号系统', link: '/zh-CN/godot/signal' },
|
||||
@ -156,7 +162,13 @@ export default defineConfig({
|
||||
{ text: '7. 总结与最佳实践', link: '/zh-CN/tutorials/basic/07-summary' }
|
||||
]
|
||||
},
|
||||
{ text: 'Godot集成', link: '/zh-CN/tutorials/godot-integration' },
|
||||
{ text: '使用协程系统', link: '/zh-CN/tutorials/coroutine-tutorial' },
|
||||
{ text: '实现状态机', link: '/zh-CN/tutorials/state-machine-tutorial' },
|
||||
{ text: '函数式编程实践', link: '/zh-CN/tutorials/functional-programming' },
|
||||
{ text: '资源管理最佳实践', link: '/zh-CN/tutorials/resource-management' },
|
||||
{ text: '实现存档系统', link: '/zh-CN/tutorials/save-system' },
|
||||
{ text: 'Godot 集成', link: '/zh-CN/tutorials/godot-integration' },
|
||||
{ text: 'Godot 完整项目', link: '/zh-CN/tutorials/godot-complete-project' },
|
||||
{ text: '高级模式', link: '/zh-CN/tutorials/advanced-patterns' }
|
||||
]
|
||||
}
|
||||
|
||||
@ -16,15 +16,15 @@ Configuration 包提供了线程安全的配置管理系统,支持类型安全
|
||||
|
||||
```csharp
|
||||
// 配置访问
|
||||
T? GetConfig<T>(string key); // 获取配置值
|
||||
T GetConfig<T>(string key, T defaultValue); // 获取配置值(带默认值)
|
||||
void SetConfig<T>(string key, T value); // 设置配置值
|
||||
T? GetConfig<T>(string key); // 获取配置值
|
||||
T GetConfig<T>(string key, T defaultValue); // 获取配置值(带默认值)
|
||||
void SetConfig<T>(string key, T value); // 设置配置值
|
||||
bool HasConfig(string key); // 检查配置是否存在
|
||||
bool RemoveConfig(string key); // 移除配置
|
||||
void Clear(); // 清空所有配置
|
||||
|
||||
// 配置监听
|
||||
IUnRegister WatchConfig<T>(string key, Action<T> onChange); // 监听配置变化
|
||||
IUnRegister WatchConfig<T>(string key, Action<T> onChange); // 监听配置变化
|
||||
|
||||
// 持久化
|
||||
void LoadFromJson(string json); // 从 JSON 加载
|
||||
|
||||
@ -79,7 +79,7 @@ public struct Velocity(float x, float y)
|
||||
|
||||
### System(系统)
|
||||
|
||||
系统包含游戏逻辑,负责处理具有特定组件组合的实体。在 GFramework 中,系统通过继承 `ArchSystemAdapter<T>` 来实现。
|
||||
系统包含游戏逻辑,负责处理具有特定组件组合的实体。在 GFramework 中,系统通过继承 `ArchSystemAdapter<T>` 来实现。
|
||||
|
||||
```csharp
|
||||
using Arch.Core;
|
||||
@ -133,7 +133,7 @@ public class MySystem : ArchSystemAdapter<float>
|
||||
GFramework 通过以下组件桥接 Arch.Core 到框架生命周期:
|
||||
|
||||
- **ArchEcsModule**:ECS 模块,管理 World 和系统生命周期
|
||||
- **ArchSystemAdapter<T>**:系统适配器,桥接 Arch 系统到 GFramework
|
||||
- **ArchSystemAdapter<T>**:系统适配器,桥接 Arch 系统到 GFramework
|
||||
|
||||
## 基本用法
|
||||
|
||||
@ -338,7 +338,7 @@ public class QueryExampleSystem : ArchSystemAdapter<float>
|
||||
|
||||
### 系统生命周期钩子
|
||||
|
||||
`ArchSystemAdapter<T>` 提供了多个生命周期钩子:
|
||||
`ArchSystemAdapter<T>` 提供了多个生命周期钩子:
|
||||
|
||||
```csharp
|
||||
public class LifecycleExampleSystem : ArchSystemAdapter<float>
|
||||
@ -856,7 +856,7 @@ public class LifecycleManagementSystem : ArchSystemAdapter<float>
|
||||
|
||||
### Q: 如何在 ECS 系统中访问其他服务?
|
||||
|
||||
A: `ArchSystemAdapter<T>` 继承自 `AbstractSystem`,可以使用所有 GFramework 的扩展方法:
|
||||
A: `ArchSystemAdapter<T>` 继承自 `AbstractSystem`,可以使用所有 GFramework 的扩展方法:
|
||||
|
||||
```csharp
|
||||
public class ServiceAccessSystem : ArchSystemAdapter<float>
|
||||
|
||||
@ -17,7 +17,7 @@ GFramework.Core 提供了一套完整的函数式编程工具,帮助开发者
|
||||
|
||||
### Option 类型
|
||||
|
||||
`Option<T>` 表示可能存在或不存在的值,用于替代 null 引用。它有两种状态:
|
||||
`Option<T>` 表示可能存在或不存在的值,用于替代 null 引用。它有两种状态:
|
||||
|
||||
- **Some**:包含一个值
|
||||
- **None**:不包含值
|
||||
@ -26,7 +26,7 @@ GFramework.Core 提供了一套完整的函数式编程工具,帮助开发者
|
||||
|
||||
### Result 类型
|
||||
|
||||
`Result<T>` 表示操作的结果,可能是成功值或失败异常。它有三种状态:
|
||||
`Result<T>` 表示操作的结果,可能是成功值或失败异常。它有三种状态:
|
||||
|
||||
- **Success**:操作成功,包含返回值
|
||||
- **Faulted**:操作失败,包含异常信息
|
||||
@ -586,14 +586,14 @@ public async Task<Result<Response>> ProcessRequestAsync(Request request)
|
||||
|
||||
### Option vs Nullable
|
||||
|
||||
**Q: Option 和 Nullable<T> 有什么区别?**
|
||||
**Q: Option 和 Nullable<T> 有什么区别?**
|
||||
|
||||
A:
|
||||
|
||||
- `Nullable<T>` 只能用于值类型,`Option<T>` 可用于任何类型
|
||||
- `Option<T>` 提供丰富的函数式操作(Map、Bind、Filter 等)
|
||||
- `Option<T>` 强制显式处理"无值"情况,更安全
|
||||
- `Option<T>` 可以与 Result 等其他函数式类型组合
|
||||
- `Nullable<T>` 只能用于值类型,`Option<T>` 可用于任何类型
|
||||
- `Option<T>` 提供丰富的函数式操作(Map、Bind、Filter 等)
|
||||
- `Option<T>` 强制显式处理"无值"情况,更安全
|
||||
- `Option<T>` 可以与 Result 等其他函数式类型组合
|
||||
|
||||
### Result vs Exception
|
||||
|
||||
|
||||
@ -31,10 +31,10 @@ JSON)进行存储或传输,并能够将字符串数据还原为对象。
|
||||
public interface ISerializer : IUtility
|
||||
{
|
||||
// 将对象序列化为字符串
|
||||
string Serialize<T>(T value);
|
||||
string Serialize<T>(T value);
|
||||
|
||||
// 将字符串反序列化为对象
|
||||
T Deserialize<T>(string data);
|
||||
T Deserialize<T>(string data);
|
||||
}
|
||||
```
|
||||
|
||||
@ -60,8 +60,8 @@ public interface IRuntimeTypeSerializer : ISerializer
|
||||
```csharp
|
||||
public sealed class JsonSerializer : IRuntimeTypeSerializer
|
||||
{
|
||||
string Serialize<T>(T value);
|
||||
T Deserialize<T>(string data);
|
||||
string Serialize<T>(T value);
|
||||
T Deserialize<T>(string data);
|
||||
string Serialize(object obj, Type type);
|
||||
object Deserialize(string data, Type type);
|
||||
}
|
||||
|
||||
@ -37,13 +37,13 @@ public interface IStorage : IUtility
|
||||
Task<bool> ExistsAsync(string key);
|
||||
|
||||
// 读取数据
|
||||
T Read<T>(string key);
|
||||
T Read<T>(string key, T defaultValue);
|
||||
Task<T> ReadAsync<T>(string key);
|
||||
T Read<T>(string key);
|
||||
T Read<T>(string key, T defaultValue);
|
||||
Task<T> ReadAsync<T>(string key);
|
||||
|
||||
// 写入数据
|
||||
void Write<T>(string key, T value);
|
||||
Task WriteAsync<T>(string key, T value);
|
||||
void Write<T>(string key, T value);
|
||||
Task WriteAsync<T>(string key, T value);
|
||||
|
||||
// 删除数据
|
||||
void Delete(string key);
|
||||
@ -410,7 +410,7 @@ public class CachedStorage : IStorage
|
||||
_innerStorage = innerStorage;
|
||||
}
|
||||
|
||||
public T Read<T>(string key)
|
||||
public T Read<T>(string key)
|
||||
{
|
||||
// 先从缓存读取
|
||||
if (_cache.TryGetValue(key, out var cached))
|
||||
@ -419,12 +419,12 @@ public class CachedStorage : IStorage
|
||||
}
|
||||
|
||||
// 从存储读取并缓存
|
||||
var value = _innerStorage.Read<T>(key);
|
||||
var value = _innerStorage.Read<T>(key);
|
||||
_cache[key] = value;
|
||||
return value;
|
||||
}
|
||||
|
||||
public void Write<T>(string key, T value)
|
||||
public void Write<T>(string key, T value)
|
||||
{
|
||||
// 写入存储
|
||||
_innerStorage.Write(key, value);
|
||||
@ -592,18 +592,18 @@ public class EncryptedStorage : IStorage
|
||||
private readonly IStorage _innerStorage;
|
||||
private readonly IEncryption _encryption;
|
||||
|
||||
public void Write<T>(string key, T value)
|
||||
public void Write<T>(string key, T value)
|
||||
{
|
||||
var json = JsonSerializer.Serialize(value);
|
||||
var encrypted = _encryption.Encrypt(json);
|
||||
_innerStorage.Write(key, encrypted);
|
||||
}
|
||||
|
||||
public T Read<T>(string key)
|
||||
public T Read<T>(string key)
|
||||
{
|
||||
var encrypted = _innerStorage.Read<byte[]>(key);
|
||||
var json = _encryption.Decrypt(encrypted);
|
||||
return JsonSerializer.Deserialize<T>(json);
|
||||
return JsonSerializer.Deserialize<T>(json);
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -620,7 +620,7 @@ public class QuotaStorage : IStorage
|
||||
private readonly long _maxSize;
|
||||
private long _currentSize;
|
||||
|
||||
public void Write<T>(string key, T value)
|
||||
public void Write<T>(string key, T value)
|
||||
{
|
||||
var data = Serialize(value);
|
||||
var size = data.Length;
|
||||
@ -646,7 +646,7 @@ public class CompressedSerializer : ISerializer
|
||||
{
|
||||
private readonly ISerializer _innerSerializer;
|
||||
|
||||
public string Serialize<T>(T value)
|
||||
public string Serialize<T>(T value)
|
||||
{
|
||||
var json = _innerSerializer.Serialize(value);
|
||||
var bytes = Encoding.UTF8.GetBytes(json);
|
||||
@ -654,12 +654,12 @@ public class CompressedSerializer : ISerializer
|
||||
return Convert.ToBase64String(compressed);
|
||||
}
|
||||
|
||||
public T Deserialize<T>(string data)
|
||||
public T Deserialize<T>(string data)
|
||||
{
|
||||
var compressed = Convert.FromBase64String(data);
|
||||
var bytes = Decompress(compressed);
|
||||
var json = Encoding.UTF8.GetString(bytes);
|
||||
return _innerSerializer.Deserialize<T>(json);
|
||||
return _innerSerializer.Deserialize<T>(json);
|
||||
}
|
||||
|
||||
private byte[] Compress(byte[] data)
|
||||
@ -694,7 +694,7 @@ public class LoggingStorage : IStorage
|
||||
private readonly IStorage _innerStorage;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public void Write<T>(string key, T value)
|
||||
public void Write<T>(string key, T value)
|
||||
{
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
try
|
||||
@ -709,12 +709,12 @@ public class LoggingStorage : IStorage
|
||||
}
|
||||
}
|
||||
|
||||
public T Read<T>(string key)
|
||||
public T Read<T>(string key)
|
||||
{
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
try
|
||||
{
|
||||
var value = _innerStorage.Read<T>(key);
|
||||
var value = _innerStorage.Read<T>(key);
|
||||
_logger.Info($"读取成功: {key}, 耗时: {stopwatch.ElapsedMilliseconds}ms");
|
||||
return value;
|
||||
}
|
||||
@ -730,6 +730,6 @@ public class LoggingStorage : IStorage
|
||||
## 相关文档
|
||||
|
||||
- [数据与存档系统](/zh-CN/game/data) - 数据持久化
|
||||
- [序列化系统](/zh-CN/core/serializer) - 数据序列化
|
||||
- [序列化系统](/zh-CN/game/serialization) - 数据序列化
|
||||
- [Godot 集成](/zh-CN/godot/index) - Godot 中的存储
|
||||
- [存档系统教程](/zh-CN/tutorials/save-system) - 完整示例
|
||||
|
||||
@ -681,4 +681,4 @@ GD.Print($"使用池: {stopwatch.ElapsedMilliseconds}ms");
|
||||
- [对象池系统](/zh-CN/core/pool) - 核心对象池实现
|
||||
- [Godot 架构集成](/zh-CN/godot/architecture) - Godot 架构基础
|
||||
- [Godot 场景系统](/zh-CN/godot/scene) - Godot 场景管理
|
||||
- [性能优化](/zh-CN/best-practices/performance) - 性能优化最佳实践
|
||||
- [性能优化](/zh-CN/core/pool) - 性能优化最佳实践
|
||||
|
||||
@ -121,7 +121,7 @@ namespace MyGame.Services
|
||||
|
||||
**代码说明**:
|
||||
|
||||
- `Option<T>` 明确表示值可能不存在,避免 NullReferenceException
|
||||
- `Option<T>` 明确表示值可能不存在,避免 NullReferenceException
|
||||
- `Match` 强制处理两种情况,不会遗漏 null 检查
|
||||
- `Map` 和 `Bind` 实现链式转换,代码更简洁
|
||||
- `Filter` 可以安全地过滤值
|
||||
@ -250,7 +250,7 @@ namespace MyGame.Services
|
||||
|
||||
**代码说明**:
|
||||
|
||||
- `Result<T>` 将错误作为值返回,而不是抛出异常
|
||||
- `Result<T>` 将错误作为值返回,而不是抛出异常
|
||||
- `Result.Try` 自动捕获异常并转换为 Result
|
||||
- `Bind` 可以链接多个可能失败的操作
|
||||
- `Match` 强制处理成功和失败两种情况
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user