mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-25 21:34:28 +08:00
style(formatter): 统一代码格式化和文档缩进
- 调整文档文件中的缩进格式一致性 - 修正所有C#接口和类定义中的注释缩进 - 移除测试代码中不必要的构造函数参数 - 重构条件语句减少嵌套层级 - 规范方法体的大括号使用风格 - 整理全局命名空间声明格式 - 优化方法实现的代码结构和可读性 - [release ci]
This commit is contained in:
parent
ad6c621c59
commit
cc8f40ee44
@ -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);
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
@ -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)
|
||||
@ -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)
|
||||
@ -170,7 +162,10 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
|
||||
/// </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>
|
||||
/// 根据类型生成存储键
|
||||
|
||||
@ -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));
|
||||
@ -235,5 +231,8 @@ public class UnifiedSettingsRepository(
|
||||
/// <param name="type">要获取键的类型</param>
|
||||
/// <returns>类型的全名作为键</returns>
|
||||
private static string GetTypeKey(Type type)
|
||||
=> type.FullName!; // ⚠️ 刻意不用 AssemblyQualifiedName
|
||||
{
|
||||
return type.FullName!;
|
||||
// ⚠️ 刻意不用 AssemblyQualifiedName
|
||||
}
|
||||
}
|
||||
@ -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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return JsonConvert.DeserializeObject(data, type)
|
||||
?? throw new ArgumentException($"Cannot deserialize to {type.Name}");
|
||||
}
|
||||
}
|
||||
@ -44,7 +44,9 @@ public class SettingsModel<TRepository>(IDataRepository? repository)
|
||||
/// </summary>
|
||||
/// <returns>所有设置数据的枚举集合</returns>
|
||||
public IEnumerable<IResettable> AllData()
|
||||
=> _dataSettings.Values;
|
||||
{
|
||||
return _dataSettings.Values;
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// Applicator
|
||||
@ -55,7 +57,9 @@ public class SettingsModel<TRepository>(IDataRepository? repository)
|
||||
/// </summary>
|
||||
/// <returns>所有设置应用器的枚举集合</returns>
|
||||
public IEnumerable<IApplyAbleSettings> AllApplicators()
|
||||
=> _applicators.Values;
|
||||
{
|
||||
return _applicators.Values;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册设置应用器到模型中
|
||||
@ -171,10 +175,7 @@ public class SettingsModel<TRepository>(IDataRepository? repository)
|
||||
/// </summary>
|
||||
public void ResetAll()
|
||||
{
|
||||
foreach (var data in _dataSettings.Values)
|
||||
{
|
||||
data.Reset();
|
||||
}
|
||||
foreach (var data in _dataSettings.Values) data.Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -181,8 +181,7 @@ public partial class Timing : Node
|
||||
|
||||
_processScheduler = new CoroutineScheduler(
|
||||
_processTimeSource,
|
||||
_instanceId,
|
||||
256
|
||||
_instanceId
|
||||
);
|
||||
|
||||
_physicsScheduler = new CoroutineScheduler(
|
||||
|
||||
@ -29,8 +29,10 @@ public class GodotAudioSettings(ISettingsModel model, AudioBusMap audioBusMap)
|
||||
/// <summary>
|
||||
/// 重置音频设置为默认值
|
||||
/// </summary>
|
||||
public void Reset() =>
|
||||
public void Reset()
|
||||
{
|
||||
model.GetData<AudioSettings>().Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定音频总线的音量
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
@ -43,5 +43,8 @@ public class GodotLocalizationSettings(ISettingsModel model, LocalizationMap loc
|
||||
/// <summary>
|
||||
/// 重置本地化设置
|
||||
/// </summary>
|
||||
public void Reset() => model.GetData<LocalizationSettings>().Reset();
|
||||
public void Reset()
|
||||
{
|
||||
model.GetData<LocalizationSettings>().Reset();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user