style(formatter): 统一代码格式化和文档缩进

- 调整文档文件中的缩进格式一致性
- 修正所有C#接口和类定义中的注释缩进
- 移除测试代码中不必要的构造函数参数
- 重构条件语句减少嵌套层级
- 规范方法体的大括号使用风格
- 整理全局命名空间声明格式
- 优化方法实现的代码结构和可读性
- [release ci]
This commit is contained in:
GeWuYou 2026-01-29 22:35:45 +08:00
parent ad6c621c59
commit cc8f40ee44
26 changed files with 148 additions and 142 deletions

View File

@ -14,13 +14,13 @@
namespace GFramework.Core.Abstractions.serializer;
/// <summary>
/// 运行时类型序列化器接口继承自ISerializer接口
/// 提供基于运行时类型的对象序列化和反序列化功能
/// 运行时类型序列化器接口继承自ISerializer接口
/// 提供基于运行时类型的对象序列化和反序列化功能
/// </summary>
public interface IRuntimeTypeSerializer : ISerializer
{
/// <summary>
/// 将指定对象序列化为字符串
/// 将指定对象序列化为字符串
/// </summary>
/// <param name="obj">要序列化的对象</param>
/// <param name="type">对象的运行时类型</param>
@ -28,7 +28,7 @@ public interface IRuntimeTypeSerializer : ISerializer
string Serialize(object obj, Type type);
/// <summary>
/// 将字符串数据反序列化为指定类型的对象
/// 将字符串数据反序列化为指定类型的对象
/// </summary>
/// <param name="data">要反序列化的字符串数据</param>
/// <param name="type">目标对象的运行时类型</param>

View File

@ -14,12 +14,12 @@
namespace GFramework.Core.Abstractions.versioning;
/// <summary>
/// 定义具有版本信息的接口
/// 定义具有版本信息的接口
/// </summary>
public interface IVersioned
{
/// <summary>
/// 获取对象的版本号
/// 获取对象的版本号
/// </summary>
int Version { get; }
}

View File

@ -256,7 +256,7 @@ public class CoroutineExtensionsTests
public void ParallelCoroutines_Should_Return_Valid_Coroutine()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var coroutine1 = CreateSimpleCoroutine();
var coroutine2 = CreateSimpleCoroutine();
@ -272,7 +272,7 @@ public class CoroutineExtensionsTests
public void ParallelCoroutines_Should_Execute_Coroutines_In_Parallel()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var executionCounts = new Dictionary<int, int> { { 1, 0 }, { 2, 0 }, { 3, 0 } };
var coroutine1 = CreateDelayedCoroutine(() => executionCounts[1]++, 0.5);
@ -299,7 +299,7 @@ public class CoroutineExtensionsTests
public void ParallelCoroutines_Should_Handle_Empty_Array()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var parallel = scheduler.ParallelCoroutines();
@ -313,7 +313,7 @@ public class CoroutineExtensionsTests
public void ParallelCoroutines_Should_Handle_Null_Array()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var parallel = scheduler.ParallelCoroutines(null);

View File

@ -26,7 +26,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Not_Be_Done_Initially_With_Running_Coroutines()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var coroutine1 = CreateDelayedCoroutine(() => { }, 1.0);
var coroutine2 = CreateDelayedCoroutine(() => { }, 1.0);
@ -48,7 +48,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Be_Done_When_All_Coroutines_Complete()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var coroutine1 = CreateSimpleCoroutine();
var coroutine2 = CreateSimpleCoroutine();
@ -73,7 +73,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Wait_For_All_Delayed_Coroutines()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var executionCount = 0;
var coroutine1 = CreateDelayedCoroutine(() => executionCount++, 1.0);
@ -105,7 +105,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Handle_Empty_Handles_List()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var handles = Array.Empty<CoroutineHandle>();
var wait = new WaitForAllCoroutines(scheduler, handles);
@ -120,7 +120,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Throw_ArgumentNullException_When_Handles_Is_Null()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
Assert.Throws<ArgumentNullException>(() => new WaitForAllCoroutines(scheduler, null!));
}
@ -143,7 +143,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Handle_Single_Coroutine()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var coroutine = CreateSimpleCoroutine();
var handles = new List<CoroutineHandle> { scheduler.Run(coroutine) };
@ -162,7 +162,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Not_Be_Done_When_Some_Coroutines_Complete()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var executionCount = 0;
var coroutine1 = CreateSimpleCoroutine();
@ -191,7 +191,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Handle_Killed_Coroutines()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var coroutine1 = CreateDelayedCoroutine(() => { }, 1.0);
var coroutine2 = CreateDelayedCoroutine(() => { }, 1.0);
@ -222,7 +222,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Handle_Paused_And_Resumed_Coroutines()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var executionCount = 0;
var coroutine1 = CreateDelayedCoroutine(() => executionCount++, 1.0);
@ -258,7 +258,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Update_Should_Not_Affect_State()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var coroutine = CreateDelayedCoroutine(() => { }, 1.0);
var handles = new List<CoroutineHandle> { scheduler.Run(coroutine) };
@ -278,7 +278,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Handle_Invalid_Handles()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var handles = new List<CoroutineHandle> { default };
@ -294,7 +294,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Handle_Mixed_Valid_And_Invalid_Handles()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var coroutine = CreateSimpleCoroutine();
var handles = new List<CoroutineHandle>
@ -317,7 +317,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Handle_Many_Coroutines()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var executionCount = 0;
var handles = new List<CoroutineHandle>();
@ -340,7 +340,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Handle_Coroutines_With_Exceptions()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var coroutine1 = CreateSimpleCoroutine();
var coroutine2 = CreateExceptionCoroutine();
@ -367,7 +367,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Work_With_ParallelCoroutines()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var executionOrder = new List<int>();
var coroutine1 = CreateDelayedCoroutine(() => executionOrder.Add(1), 0.5);
@ -397,7 +397,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Implement_IYieldInstruction()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var handles = Array.Empty<CoroutineHandle>();
var wait = new WaitForAllCoroutines(scheduler, handles);
@ -412,7 +412,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Be_Done_Immediately_When_All_Coroutines_Complete_Immediately()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var coroutine1 = CreateSimpleCoroutine();
var coroutine2 = CreateSimpleCoroutine();
@ -438,7 +438,7 @@ public class WaitForAllCoroutinesTests
public void WaitForAllCoroutines_Should_Handle_Duplicate_Handles()
{
var timeSource = new TestTimeSource();
var scheduler = new CoroutineScheduler(timeSource, 1);
var scheduler = new CoroutineScheduler(timeSource);
var coroutine = CreateDelayedCoroutine(() => { }, 1.0);
var handle = scheduler.Run(coroutine);

View File

@ -19,14 +19,13 @@ global using System.Threading.Tasks;
#if NETSTANDARD2_0 || NETFRAMEWORK || NETCOREAPP2_0
using System.ComponentModel;
namespace System.Runtime.CompilerServices
namespace System.Runtime.CompilerServices;
/// <summary>
/// 用于标记仅初始化 setter 的特殊类型
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class IsExternalInit
{
/// <summary>
/// 用于标记仅初始化 setter 的特殊类型
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class IsExternalInit
{
}
}
#endif

View File

@ -14,27 +14,27 @@
namespace GFramework.Game.Abstractions.data;
/// <summary>
/// 数据仓库配置选项
/// 数据仓库配置选项
/// </summary>
public class DataRepositoryOptions
{
/// <summary>
/// 存储基础路径(如 "user://data/"
/// 存储基础路径(如 "user://data/"
/// </summary>
public string BasePath { get; set; } = "";
/// <summary>
/// 键名前缀(如 "Game",生成的键为 "Game_SettingsData"
/// 键名前缀(如 "Game",生成的键为 "Game_SettingsData"
/// </summary>
public string KeyPrefix { get; set; } = "";
/// <summary>
/// 是否在保存时自动备份
/// 是否在保存时自动备份
/// </summary>
public bool AutoBackup { get; set; } = false;
/// <summary>
/// 是否启用加载/保存事件
/// 是否启用加载/保存事件
/// </summary>
public bool EnableEvents { get; set; } = true;
}

View File

@ -14,6 +14,6 @@
namespace GFramework.Game.Abstractions.data;
/// <summary>
/// 通用数据标记接口
/// 通用数据标记接口
/// </summary>
public interface IData;

View File

@ -16,26 +16,26 @@ using GFramework.Core.Abstractions.utility;
namespace GFramework.Game.Abstractions.data;
/// <summary>
/// 定义数据仓库接口,提供异步的数据加载、保存、检查存在性和删除操作
/// 定义数据仓库接口,提供异步的数据加载、保存、检查存在性和删除操作
/// </summary>
public interface IDataRepository : IUtility
{
/// <summary>
/// 异步加载指定类型的数据对象
/// 异步加载指定类型的数据对象
/// </summary>
/// <typeparam name="T">要加载的数据类型必须实现IData接口并具有无参构造函数</typeparam>
/// <returns>返回加载的数据对象的Task</returns>
Task<T> LoadAsync<T>() where T : class, IData, new();
/// <summary>
/// 根据类型异步加载数据
/// 根据类型异步加载数据
/// </summary>
/// <param name="type">要加载的数据类型</param>
/// <returns>异步操作任务返回实现IData接口的数据对象</returns>
Task<IData> LoadAsync(Type type);
/// <summary>
/// 异步保存指定的数据对象
/// 异步保存指定的数据对象
/// </summary>
/// <typeparam name="T">要保存的数据类型必须实现IData接口</typeparam>
/// <param name="data">要保存的数据对象</param>
@ -43,21 +43,21 @@ public interface IDataRepository : IUtility
Task SaveAsync<T>(T data) where T : class, IData;
/// <summary>
/// 异步检查指定类型的数据是否存在
/// 异步检查指定类型的数据是否存在
/// </summary>
/// <typeparam name="T">要检查的数据类型必须实现IData接口</typeparam>
/// <returns>返回表示数据是否存在布尔值的Task</returns>
Task<bool> ExistsAsync<T>() where T : class, IData;
/// <summary>
/// 异步删除指定类型的数据
/// 异步删除指定类型的数据
/// </summary>
/// <typeparam name="T">要删除的数据类型必须实现IData接口</typeparam>
/// <returns>表示异步删除操作的Task</returns>
Task DeleteAsync<T>() where T : class, IData;
/// <summary>
/// 批量保存多个数据
/// 批量保存多个数据
/// </summary>
/// <param name="dataList">要保存的数据列表实现IData接口的对象集合</param>
/// <returns>异步操作任务</returns>

View File

@ -14,7 +14,7 @@
namespace GFramework.Game.Abstractions.data.events;
/// <summary>
/// 表示数据批次保存事件的记录类型
/// 表示数据批次保存事件的记录类型
/// </summary>
/// <param name="List">包含已保存数据项的集合实现了IData接口</param>
public sealed record DataBatchSavedEvent(ICollection<IData> List);

View File

@ -14,7 +14,7 @@
namespace GFramework.Game.Abstractions.data.events;
/// <summary>
/// 表示数据删除事件的记录类型
/// 表示数据删除事件的记录类型
/// </summary>
/// <param name="Type">被删除数据的类型</param>
public sealed record DataDeletedEvent(Type Type);

View File

@ -14,7 +14,7 @@
namespace GFramework.Game.Abstractions.data.events;
/// <summary>
/// 表示数据加载完成事件的泛型类
/// 表示数据加载完成事件的泛型类
/// </summary>
/// <typeparam name="T">数据类型参数</typeparam>
/// <param name="Data">加载完成的数据对象</param>

View File

@ -14,7 +14,7 @@
namespace GFramework.Game.Abstractions.data.events;
/// <summary>
/// 表示数据保存事件的记录类型
/// 表示数据保存事件的记录类型
/// </summary>
/// <typeparam name="T">保存的数据类型</typeparam>
/// <param name="Data">保存的数据实例</param>

View File

@ -1,8 +1,8 @@
namespace GFramework.Game.Abstractions.setting;
/// <summary>
/// 可重置设置接口继承自ISettingsSection接口
/// 提供将设置重置为默认值的功能
/// 可重置设置接口继承自ISettingsSection接口
/// 提供将设置重置为默认值的功能
/// </summary>
public interface IResettable : ISettingsSection
{

View File

@ -14,27 +14,27 @@
namespace GFramework.Game.Abstractions.setting;
/// <summary>
/// 定义设置数据迁移接口,用于处理不同版本设置数据之间的转换
/// 定义设置数据迁移接口,用于处理不同版本设置数据之间的转换
/// </summary>
public interface ISettingsMigration
{
/// <summary>
/// 获取要迁移的设置类型
/// 获取要迁移的设置类型
/// </summary>
Type SettingsType { get; }
/// <summary>
/// 获取源版本号(迁移前的版本)
/// 获取源版本号(迁移前的版本)
/// </summary>
int FromVersion { get; }
/// <summary>
/// 获取目标版本号(迁移后的版本)
/// 获取目标版本号(迁移后的版本)
/// </summary>
int ToVersion { get; }
/// <summary>
/// 执行设置数据迁移操作
/// 执行设置数据迁移操作
/// </summary>
/// <param name="oldData">需要迁移的旧版设置数据</param>
/// <returns>迁移后的新版设置数据</returns>

View File

@ -30,13 +30,13 @@ public interface ISettingsModel : IModel
T? GetApplicator<T>() where T : class, IApplyAbleSettings;
/// <summary>
/// 获取所有设置数据的集合
/// 获取所有设置数据的集合
/// </summary>
/// <returns>包含所有设置数据的可枚举集合</returns>
IEnumerable<IResettable> AllData();
/// <summary>
/// 获取所有可应用设置的集合
/// 获取所有可应用设置的集合
/// </summary>
/// <returns>包含所有可应用设置的可枚举集合</returns>
IEnumerable<IApplyAbleSettings> AllApplicators();

View File

@ -16,20 +16,20 @@ using GFramework.Core.Abstractions.versioning;
namespace GFramework.Game.Abstractions.setting.data;
/// <summary>
/// 本地化设置类,用于管理游戏的语言本地化配置
/// 实现了ISettingsData接口提供设置数据功能实现IVersioned接口提供版本控制功能
/// 本地化设置类,用于管理游戏的语言本地化配置
/// 实现了ISettingsData接口提供设置数据功能实现IVersioned接口提供版本控制功能
/// </summary>
public class LocalizationSettings : IResettable, IVersioned
{
/// <summary>
/// 获取或设置当前使用的语言
/// 获取或设置当前使用的语言
/// </summary>
/// <value>默认值为"简体中文"</value>
public string Language { get; set; } = "简体中文";
/// <summary>
/// 重置本地化设置到默认状态
/// 将Language属性恢复为默认的"简体中文"值
/// 重置本地化设置到默认状态
/// 将Language属性恢复为默认的"简体中文"值
/// </summary>
public void Reset()
{
@ -37,7 +37,7 @@ public class LocalizationSettings : IResettable, IVersioned
}
/// <summary>
/// 获取或设置设置数据的版本号
/// 获取或设置设置数据的版本号
/// </summary>
/// <value>默认版本号为1</value>
public int Version { get; set; } = 1;

View File

@ -20,7 +20,7 @@ using GFramework.Game.Abstractions.data.events;
namespace GFramework.Game.data;
/// <summary>
/// 数据仓库类,用于管理游戏数据的存储和读取
/// 数据仓库类,用于管理游戏数据的存储和读取
/// </summary>
/// <param name="storage">存储接口实例</param>
/// <param name="options">数据仓库配置选项</param>
@ -35,7 +35,7 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
"Failed to initialize storage. No IStorage utility found in context.");
/// <summary>
/// 异步加载指定类型的数据
/// 异步加载指定类型的数据
/// </summary>
/// <typeparam name="T">要加载的数据类型必须实现IData接口</typeparam>
/// <returns>加载的数据对象</returns>
@ -46,13 +46,9 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
T result;
// 检查存储中是否存在指定键的数据
if (await Storage.ExistsAsync(key))
{
result = await Storage.ReadAsync<T>(key);
}
else
{
result = new T();
}
// 如果启用事件功能,则发送数据加载完成事件
if (_options.EnableEvents)
@ -62,7 +58,7 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
}
/// <summary>
/// 异步加载指定类型的数据通过Type参数
/// 异步加载指定类型的数据通过Type参数
/// </summary>
/// <param name="type">要加载的数据类型</param>
/// <returns>加载的数据对象</returns>
@ -79,13 +75,9 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
IData result;
// 检查存储中是否存在指定键的数据
if (await Storage.ExistsAsync(key))
{
result = await Storage.ReadAsync<IData>(key);
}
else
{
result = (IData)Activator.CreateInstance(type)!;
}
// 如果启用事件功能,则发送数据加载完成事件
if (_options.EnableEvents)
@ -96,7 +88,7 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
/// <summary>
/// 异步保存指定类型的数据
/// 异步保存指定类型的数据
/// </summary>
/// <typeparam name="T">要保存的数据类型</typeparam>
/// <param name="data">要保存的数据对象</param>
@ -119,7 +111,7 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
}
/// <summary>
/// 检查指定类型的数据是否存在
/// 检查指定类型的数据是否存在
/// </summary>
/// <typeparam name="T">要检查的数据类型</typeparam>
/// <returns>如果数据存在返回true否则返回false</returns>
@ -130,7 +122,7 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
}
/// <summary>
/// 异步删除指定类型的数据
/// 异步删除指定类型的数据
/// </summary>
/// <typeparam name="T">要删除的数据类型</typeparam>
public async Task DeleteAsync<T>() where T : class, IData
@ -143,7 +135,7 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
}
/// <summary>
/// 批量异步保存多个数据对象
/// 批量异步保存多个数据对象
/// </summary>
/// <param name="dataList">要保存的数据对象集合</param>
public async Task SaveAllAsync(IEnumerable<IData> dataList)
@ -166,14 +158,17 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
}
/// <summary>
/// 根据类型生成存储键
/// 根据类型生成存储键
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
/// <returns>生成的存储键</returns>
private string GetKey<T>() where T : IData => GetKey(typeof(T));
private string GetKey<T>() where T : IData
{
return GetKey(typeof(T));
}
/// <summary>
/// 根据类型生成存储键
/// 根据类型生成存储键
/// </summary>
/// <param name="type">数据类型</param>
/// <returns>生成的存储键</returns>

View File

@ -21,7 +21,7 @@ using GFramework.Game.Abstractions.data.events;
namespace GFramework.Game.data;
/// <summary>
/// 使用单一文件存储所有设置数据的仓库实现
/// 使用单一文件存储所有设置数据的仓库实现
/// </summary>
public class UnifiedSettingsRepository(
IStorage? storage,
@ -48,7 +48,7 @@ public class UnifiedSettingsRepository(
// =========================
/// <summary>
/// 异步加载指定类型的数据
/// 异步加载指定类型的数据
/// </summary>
/// <typeparam name="T">要加载的数据类型必须继承自IData接口并具有无参构造函数</typeparam>
/// <returns>加载的数据实例</returns>
@ -67,7 +67,7 @@ public class UnifiedSettingsRepository(
}
/// <summary>
/// 异步加载指定类型的数据通过Type参数
/// 异步加载指定类型的数据通过Type参数
/// </summary>
/// <param name="type">要加载的数据类型</param>
/// <returns>加载的数据实例</returns>
@ -86,13 +86,9 @@ public class UnifiedSettingsRepository(
IData result;
if (_cache.TryGetValue(key, out var json))
{
result = (IData)Serializer.Deserialize(json, type);
}
else
{
result = (IData)Activator.CreateInstance(type)!;
}
if (_options.EnableEvents)
this.SendEvent(new DataLoadedEvent<IData>(result));
@ -101,7 +97,7 @@ public class UnifiedSettingsRepository(
}
/// <summary>
/// 异步保存数据到存储
/// 异步保存数据到存储
/// </summary>
/// <typeparam name="T">要保存的数据类型</typeparam>
/// <param name="data">要保存的数据实例</param>
@ -119,7 +115,7 @@ public class UnifiedSettingsRepository(
}
/// <summary>
/// 异步批量保存多个数据实例
/// 异步批量保存多个数据实例
/// </summary>
/// <param name="dataList">要保存的数据实例集合</param>
public async Task SaveAllAsync(IEnumerable<IData> dataList)
@ -140,7 +136,7 @@ public class UnifiedSettingsRepository(
}
/// <summary>
/// 检查指定类型的数据是否存在
/// 检查指定类型的数据是否存在
/// </summary>
/// <typeparam name="T">要检查的数据类型</typeparam>
/// <returns>如果存在返回true否则返回false</returns>
@ -151,7 +147,7 @@ public class UnifiedSettingsRepository(
}
/// <summary>
/// 删除指定类型的数据
/// 删除指定类型的数据
/// </summary>
/// <typeparam name="T">要删除的数据类型</typeparam>
public async Task DeleteAsync<T>() where T : class, IData
@ -176,7 +172,7 @@ public class UnifiedSettingsRepository(
// =========================
/// <summary>
/// 确保数据已从存储中加载到缓存
/// 确保数据已从存储中加载到缓存
/// </summary>
private async Task EnsureLoadedAsync()
{
@ -204,7 +200,7 @@ public class UnifiedSettingsRepository(
}
/// <summary>
/// 将缓存中的所有数据保存到统一文件
/// 将缓存中的所有数据保存到统一文件
/// </summary>
private async Task SaveUnifiedFileAsync()
{
@ -220,7 +216,7 @@ public class UnifiedSettingsRepository(
}
/// <summary>
/// 获取统一文件的存储键名
/// 获取统一文件的存储键名
/// </summary>
/// <returns>完整的存储键名</returns>
private string GetUnifiedKey()
@ -230,10 +226,13 @@ public class UnifiedSettingsRepository(
}
/// <summary>
/// 获取类型的唯一标识键
/// 获取类型的唯一标识键
/// </summary>
/// <param name="type">要获取键的类型</param>
/// <returns>类型的全名作为键</returns>
private static string GetTypeKey(Type type)
=> type.FullName!; // ⚠️ 刻意不用 AssemblyQualifiedName
{
return type.FullName!;
// ⚠️ 刻意不用 AssemblyQualifiedName
}
}

View File

@ -16,7 +16,9 @@ public sealed class JsonSerializer
/// <param name="value">要序列化的对象实例</param>
/// <returns>序列化后的JSON字符串</returns>
public string Serialize<T>(T value)
=> JsonConvert.SerializeObject(value);
{
return JsonConvert.SerializeObject(value);
}
/// <summary>
/// 将JSON字符串反序列化为指定类型的对象
@ -26,8 +28,10 @@ public sealed class JsonSerializer
/// <returns>反序列化后的对象实例</returns>
/// <exception cref="ArgumentException">当无法反序列化数据时抛出</exception>
public T Deserialize<T>(string data)
=> JsonConvert.DeserializeObject<T>(data)
?? throw new ArgumentException("Cannot deserialize data");
{
return JsonConvert.DeserializeObject<T>(data)
?? throw new ArgumentException("Cannot deserialize data");
}
/// <summary>
/// 将对象序列化为JSON字符串使用运行时类型
@ -36,7 +40,9 @@ public sealed class JsonSerializer
/// <param name="type">对象的运行时类型</param>
/// <returns>序列化后的JSON字符串</returns>
public string Serialize(object obj, Type type)
=> JsonConvert.SerializeObject(obj, type, null);
{
return JsonConvert.SerializeObject(obj, type, null);
}
/// <summary>
/// 将JSON字符串反序列化为指定类型的对象使用运行时类型
@ -46,6 +52,8 @@ public sealed class JsonSerializer
/// <returns>反序列化后的对象实例</returns>
/// <exception cref="ArgumentException">当无法反序列化到指定类型时抛出</exception>
public object Deserialize(string data, Type type)
=> JsonConvert.DeserializeObject(data, type)
?? throw new ArgumentException($"Cannot deserialize to {type.Name}");
{
return JsonConvert.DeserializeObject(data, type)
?? throw new ArgumentException($"Cannot deserialize to {type.Name}");
}
}

View File

@ -30,7 +30,7 @@ public class SettingsModel<TRepository>(IDataRepository? repository)
// -----------------------------
/// <summary>
/// 获取指定类型的设置数据实例,如果不存在则创建新的实例
/// 获取指定类型的设置数据实例,如果不存在则创建新的实例
/// </summary>
/// <typeparam name="T">设置数据类型必须实现ISettingsData接口并提供无参构造函数</typeparam>
/// <returns>指定类型的设置数据实例</returns>
@ -40,25 +40,29 @@ public class SettingsModel<TRepository>(IDataRepository? repository)
}
/// <summary>
/// 获取所有设置数据的枚举集合
/// 获取所有设置数据的枚举集合
/// </summary>
/// <returns>所有设置数据的枚举集合</returns>
public IEnumerable<IResettable> AllData()
=> _dataSettings.Values;
{
return _dataSettings.Values;
}
// -----------------------------
// Applicator
// -----------------------------
/// <summary>
/// 获取所有设置应用器的枚举集合
/// 获取所有设置应用器的枚举集合
/// </summary>
/// <returns>所有设置应用器的枚举集合</returns>
public IEnumerable<IApplyAbleSettings> AllApplicators()
=> _applicators.Values;
{
return _applicators.Values;
}
/// <summary>
/// 注册设置应用器到模型中
/// 注册设置应用器到模型中
/// </summary>
/// <typeparam name="T">设置应用器类型必须实现IApplyAbleSettings接口</typeparam>
/// <param name="applicator">要注册的设置应用器实例</param>
@ -71,7 +75,7 @@ public class SettingsModel<TRepository>(IDataRepository? repository)
}
/// <summary>
/// 获取指定类型的设置应用器实例
/// 获取指定类型的设置应用器实例
/// </summary>
/// <typeparam name="T">设置应用器类型必须实现IApplyAbleSettings接口</typeparam>
/// <returns>指定类型的设置应用器实例如果不存在则返回null</returns>
@ -87,7 +91,7 @@ public class SettingsModel<TRepository>(IDataRepository? repository)
// -----------------------------
/// <summary>
/// 尝试获取指定类型的设置节
/// 尝试获取指定类型的设置节
/// </summary>
/// <param name="type">要查找的设置类型</param>
/// <param name="section">输出参数,找到的设置节实例</param>
@ -115,7 +119,7 @@ public class SettingsModel<TRepository>(IDataRepository? repository)
// -----------------------------
/// <summary>
/// 注册设置迁移器到模型中
/// 注册设置迁移器到模型中
/// </summary>
/// <param name="migration">要注册的设置迁移器实例</param>
/// <returns>当前设置模型实例,支持链式调用</returns>
@ -131,7 +135,7 @@ public class SettingsModel<TRepository>(IDataRepository? repository)
// -----------------------------
/// <summary>
/// 异步初始化设置模型,加载指定类型的设置数据
/// 异步初始化设置模型,加载指定类型的设置数据
/// </summary>
/// <param name="settingTypes">要初始化的设置类型数组</param>
public async Task InitializeAsync(params Type[] settingTypes)
@ -157,7 +161,7 @@ public class SettingsModel<TRepository>(IDataRepository? repository)
}
/// <summary>
/// 重置指定类型的可重置对象
/// 重置指定类型的可重置对象
/// </summary>
/// <typeparam name="T">要重置的对象类型必须是class类型实现IResettable接口并具有无参构造函数</typeparam>
public void Reset<T>() where T : class, IResettable, new()
@ -167,18 +171,15 @@ public class SettingsModel<TRepository>(IDataRepository? repository)
}
/// <summary>
/// 重置所有存储的数据设置对象
/// 重置所有存储的数据设置对象
/// </summary>
public void ResetAll()
{
foreach (var data in _dataSettings.Values)
{
data.Reset();
}
foreach (var data in _dataSettings.Values) data.Reset();
}
/// <summary>
/// 如果需要的话,对设置节进行版本迁移
/// 如果需要的话,对设置节进行版本迁移
/// </summary>
/// <param name="section">待检查和迁移的设置节</param>
/// <returns>迁移后的设置节</returns>
@ -210,7 +211,7 @@ public class SettingsModel<TRepository>(IDataRepository? repository)
/// <summary>
/// 初始化方法,用于获取设置持久化服务
/// 初始化方法,用于获取设置持久化服务
/// </summary>
protected override void OnInit()
{

View File

@ -23,10 +23,7 @@ public class SettingsSystem<TRepository>(IDataRepository? repository)
public async Task ApplyAll()
{
// 遍历所有设置应用器并尝试应用
foreach (var applicator in _model.AllApplicators())
{
await TryApplyAsync(applicator);
}
foreach (var applicator in _model.AllApplicators()) await TryApplyAsync(applicator);
}
/// <summary>
@ -52,7 +49,7 @@ public class SettingsSystem<TRepository>(IDataRepository? repository)
}
/// <summary>
/// 重置所有设置并应用更改
/// 重置所有设置并应用更改
/// </summary>
/// <returns>异步任务</returns>
public async Task ResetAll()
@ -62,7 +59,7 @@ public class SettingsSystem<TRepository>(IDataRepository? repository)
}
/// <summary>
/// 重置指定类型的设置并应用更改
/// 重置指定类型的设置并应用更改
/// </summary>
/// <typeparam name="T">设置类型必须实现IPersistentApplyAbleSettings接口且具有无参构造函数</typeparam>
/// <returns>异步任务</returns>

View File

@ -181,8 +181,7 @@ public partial class Timing : Node
_processScheduler = new CoroutineScheduler(
_processTimeSource,
_instanceId,
256
_instanceId
);
_physicsScheduler = new CoroutineScheduler(

View File

@ -29,8 +29,10 @@ public class GodotAudioSettings(ISettingsModel model, AudioBusMap audioBusMap)
/// <summary>
/// 重置音频设置为默认值
/// </summary>
public void Reset() =>
public void Reset()
{
model.GetData<AudioSettings>().Reset();
}
/// <summary>
/// 设置指定音频总线的音量

View File

@ -46,5 +46,8 @@ public class GodotGraphicsSettings(ISettingsModel model) : IPersistentApplyAbleS
/// <summary>
/// 重置图形设置
/// </summary>
public void Reset() => model.GetData<GraphicsSettings>().Reset();
public void Reset()
{
model.GetData<GraphicsSettings>().Reset();
}
}

View File

@ -19,7 +19,7 @@ using Godot;
namespace GFramework.Godot.setting;
/// <summary>
/// Godot本地化设置类负责应用本地化配置到Godot引擎
/// Godot本地化设置类负责应用本地化配置到Godot引擎
/// </summary>
/// <param name="model">设置模型</param>
/// <param name="localizationMap">本地化映射表</param>
@ -27,7 +27,7 @@ public class GodotLocalizationSettings(ISettingsModel model, LocalizationMap loc
: IPersistentApplyAbleSettings
{
/// <summary>
/// 应用本地化设置到Godot引擎
/// 应用本地化设置到Godot引擎
/// </summary>
/// <returns>完成的任务</returns>
public Task Apply()
@ -41,7 +41,10 @@ public class GodotLocalizationSettings(ISettingsModel model, LocalizationMap loc
}
/// <summary>
/// 重置本地化设置
/// 重置本地化设置
/// </summary>
public void Reset() => model.GetData<LocalizationSettings>().Reset();
public void Reset()
{
model.GetData<LocalizationSettings>().Reset();
}
}

View File

@ -14,12 +14,12 @@
namespace GFramework.Godot.setting.data;
/// <summary>
/// 本地化映射设置
/// 本地化映射设置
/// </summary>
public class LocalizationMap
{
/// <summary>
/// 用户语言 -> Godot locale 映射表
/// 用户语言 -> Godot locale 映射表
/// </summary>
public Dictionary<string, string> LanguageMap { get; set; } = new()
{