diff --git a/GFramework.Game.Abstractions/setting/ISettingsChangedEvent.cs b/GFramework.Game.Abstractions/setting/ISettingsChangedEvent.cs new file mode 100644 index 0000000..d965298 --- /dev/null +++ b/GFramework.Game.Abstractions/setting/ISettingsChangedEvent.cs @@ -0,0 +1,25 @@ +using System; + +namespace GFramework.Game.Abstractions.setting; + +/// +/// 设置变更事件基类 +/// 定义了设置变更事件的基本结构和属性 +/// +public interface ISettingsChangedEvent +{ + /// + /// 获取变更的设置类型 + /// + Type SettingsType { get; } + + /// + /// 获取变更的设置实例 + /// + ISettingsSection Settings { get; } + + /// + /// 获取变更发生的时间 + /// + DateTime ChangedAt { get; } +} \ No newline at end of file diff --git a/GFramework.Game.Abstractions/setting/ISettingsModel.cs b/GFramework.Game.Abstractions/setting/ISettingsModel.cs index 0b8256a..8637733 100644 --- a/GFramework.Game.Abstractions/setting/ISettingsModel.cs +++ b/GFramework.Game.Abstractions/setting/ISettingsModel.cs @@ -42,5 +42,6 @@ public interface ISettingsModel : IModel /// /// 可应用设置的类型,必须继承自class和IApplyAbleSettings /// 要注册的可应用设置实例 - void RegisterApplicator(T applicator) where T : class, IApplyAbleSettings; + /// 返回当前设置模型实例,支持链式调用 + ISettingsModel RegisterApplicator(T applicator) where T : class, IApplyAbleSettings; } \ No newline at end of file diff --git a/GFramework.Game.Abstractions/setting/ISettingsPersistence.cs b/GFramework.Game.Abstractions/setting/ISettingsPersistence.cs index 47f66cf..37531e7 100644 --- a/GFramework.Game.Abstractions/setting/ISettingsPersistence.cs +++ b/GFramework.Game.Abstractions/setting/ISettingsPersistence.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using GFramework.Core.Abstractions.utility; namespace GFramework.Game.Abstractions.setting; @@ -8,7 +9,7 @@ namespace GFramework.Game.Abstractions.setting; /// 设置持久化接口 /// 定义了设置数据的异步加载、保存、检查存在性和删除操作 /// -public interface ISettingsPersistence +public interface ISettingsPersistence : IContextUtility { /// /// 异步加载指定类型的设置数据 diff --git a/GFramework.Game/setting/SettingsModel.cs b/GFramework.Game/setting/SettingsModel.cs index 611ab16..b531ad8 100644 --- a/GFramework.Game/setting/SettingsModel.cs +++ b/GFramework.Game/setting/SettingsModel.cs @@ -31,14 +31,16 @@ public class SettingsModel : AbstractModel, ISettingsModel } /// - /// 注册可应用设置 + /// 注册可应用设置(必须手动注册) /// - /// 可应用设置类型,必须实现IApplyAbleSettings接口 + /// 可应用设置的类型,必须继承自class和IApplyAbleSettings /// 要注册的可应用设置实例 - public void RegisterApplicator(T applicator) where T : class, IApplyAbleSettings + /// 返回当前设置模型实例,支持链式调用 + public ISettingsModel RegisterApplicator(T applicator) where T : class, IApplyAbleSettings { var type = typeof(T); _applicators[type] = applicator; + return this; } /// diff --git a/GFramework.Game/setting/events/SettingsAllLoadedEvent.cs b/GFramework.Game/setting/events/SettingsAllLoadedEvent.cs new file mode 100644 index 0000000..6d81f35 --- /dev/null +++ b/GFramework.Game/setting/events/SettingsAllLoadedEvent.cs @@ -0,0 +1,30 @@ +using GFramework.Game.Abstractions.setting; + +namespace GFramework.Game.setting.events; + +/// +/// 表示所有设置已加载完成的事件 +/// +/// 包含所有设置节的可枚举集合 +public class SettingsAllLoadedEvent(IEnumerable all) : ISettingsChangedEvent +{ + /// + /// 获取所有设置节的只读集合 + /// + public IReadOnlyCollection AllSettings { get; } = all.ToList(); + + /// + /// 获取设置类型,始终返回 ISettingsSection 类型 + /// + public Type SettingsType => typeof(ISettingsSection); + + /// + /// 获取具体的设置节,此事件中始终为 null + /// + public ISettingsSection Settings => null!; + + /// + /// 获取事件发生的时间(UTC时间) + /// + public DateTime ChangedAt { get; } = DateTime.UtcNow; +} \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsAppliedEvent.cs b/GFramework.Game/setting/events/SettingsAppliedEvent.cs new file mode 100644 index 0000000..59b2b8d --- /dev/null +++ b/GFramework.Game/setting/events/SettingsAppliedEvent.cs @@ -0,0 +1,41 @@ +using GFramework.Game.Abstractions.setting; + +namespace GFramework.Game.setting.events; + +/// +/// 表示设置应用完成事件 +/// +/// 设置节类型,必须实现ISettingsSection接口 +public class SettingsAppliedEvent(T settings, bool success, Exception? error = null) : ISettingsChangedEvent + where T : ISettingsSection +{ + /// + /// 获取类型化的设置节实例 + /// + public T TypedSettings => (T)Settings; + + /// + /// 获取设置应用是否成功的状态 + /// + public bool Success { get; } = success; + + /// + /// 获取设置应用过程中发生的错误异常(如果有的话) + /// + public Exception? Error { get; } = error; + + /// + /// 获取设置类型的Type信息 + /// + public Type SettingsType => typeof(T); + + /// + /// 获取应用的设置节实例 + /// + public ISettingsSection Settings { get; } = settings; + + /// + /// 获取设置变更的时间戳(UTC时间) + /// + public DateTime ChangedAt { get; } = DateTime.UtcNow; +} \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsApplyingEvent.cs b/GFramework.Game/setting/events/SettingsApplyingEvent.cs new file mode 100644 index 0000000..a8745d2 --- /dev/null +++ b/GFramework.Game/setting/events/SettingsApplyingEvent.cs @@ -0,0 +1,31 @@ +using GFramework.Game.Abstractions.setting; + +namespace GFramework.Game.setting.events; + +/// +/// 表示设置应用事件的泛型类 +/// +/// 设置节类型,必须实现ISettingsSection接口 +public class SettingsApplyingEvent(T settings) : ISettingsChangedEvent + where T : ISettingsSection +{ + /// + /// 获取类型化的设置对象 + /// + public T TypedSettings { get; } = settings; + + /// + /// 获取设置类型的Type信息 + /// + public Type SettingsType => typeof(T); + + /// + /// 获取设置节基接口实例 + /// + public ISettingsSection Settings => TypedSettings; + + /// + /// 获取设置变更的时间戳 + /// + public DateTime ChangedAt { get; } = DateTime.UtcNow; +} \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsBatchChangedEvent.cs b/GFramework.Game/setting/events/SettingsBatchChangedEvent.cs new file mode 100644 index 0000000..f1dc043 --- /dev/null +++ b/GFramework.Game/setting/events/SettingsBatchChangedEvent.cs @@ -0,0 +1,31 @@ +using GFramework.Game.Abstractions.setting; + +namespace GFramework.Game.setting.events; + +/// +/// 批量设置变更事件 +/// 表示多个设置项同时发生变更的事件 +/// +/// 发生变更的设置数据集合 +public class SettingsBatchChangedEvent(IEnumerable settings) : ISettingsChangedEvent +{ + /// + /// 获取发生变更的具体设置数据列表 + /// + public IEnumerable ChangedSettings { get; } = settings.ToList(); + + /// + /// 获取设置类型,对于批量变更事件,固定返回ISettingsSection类型 + /// + public Type SettingsType => typeof(ISettingsSection); + + /// + /// 获取设置实例,批量变更事件中此属性返回null + /// + public ISettingsSection Settings => null!; + + /// + /// 获取变更发生的时间戳(UTC时间) + /// + public DateTime ChangedAt { get; } = DateTime.UtcNow; +} \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsBatchSavedEvent.cs b/GFramework.Game/setting/events/SettingsBatchSavedEvent.cs new file mode 100644 index 0000000..922782a --- /dev/null +++ b/GFramework.Game/setting/events/SettingsBatchSavedEvent.cs @@ -0,0 +1,30 @@ +using GFramework.Game.Abstractions.setting; + +namespace GFramework.Game.setting.events; + +/// +/// 表示设置批量保存事件 +/// +/// 要保存的设置数据集合 +public class SettingsBatchSavedEvent(IEnumerable settings) : ISettingsChangedEvent +{ + /// + /// 获取已保存的设置数据只读集合 + /// + public IReadOnlyCollection SavedSettings { get; } = settings.ToList(); + + /// + /// 获取设置类型(始终返回ISettingsSection类型) + /// + public Type SettingsType => typeof(ISettingsSection); + + /// + /// 获取设置节(在此事件中始终为null) + /// + public ISettingsSection Settings => null!; + + /// + /// 获取更改发生的时间(UTC时间) + /// + public DateTime ChangedAt { get; } = DateTime.UtcNow; +} \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsChangedEvent.cs b/GFramework.Game/setting/events/SettingsChangedEvent.cs new file mode 100644 index 0000000..4eeaba1 --- /dev/null +++ b/GFramework.Game/setting/events/SettingsChangedEvent.cs @@ -0,0 +1,32 @@ +using GFramework.Game.Abstractions.setting; + +namespace GFramework.Game.setting.events; + +/// +/// 泛型设置变更事件 +/// +/// 设置节类型,必须实现ISettingsSection接口 +/// 设置实例 +public class SettingsChangedEvent(T settings) : ISettingsChangedEvent + where T : ISettingsSection +{ + /// + /// 获取类型化的设置实例 + /// + public T TypedSettings => (T)Settings; + + /// + /// 获取设置类型 + /// + public Type SettingsType => typeof(T); + + /// + /// 获取设置实例 + /// + public ISettingsSection Settings { get; } = settings; + + /// + /// 获取变更时间 + /// + public DateTime ChangedAt { get; } = DateTime.UtcNow; +} \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsLoadedEvent.cs b/GFramework.Game/setting/events/SettingsLoadedEvent.cs new file mode 100644 index 0000000..349188a --- /dev/null +++ b/GFramework.Game/setting/events/SettingsLoadedEvent.cs @@ -0,0 +1,31 @@ +using GFramework.Game.Abstractions.setting; + +namespace GFramework.Game.setting.events; + +/// +/// 表示设置加载完成事件的泛型类 +/// +/// 设置节类型,必须实现ISettingsSection接口 +public class SettingsLoadedEvent(T settings) : ISettingsChangedEvent + where T : ISettingsSection +{ + /// + /// 获取类型化的设置对象 + /// + public T TypedSettings { get; } = settings; + + /// + /// 获取设置类型的Type信息 + /// + public Type SettingsType => typeof(T); + + /// + /// 获取设置节基接口对象 + /// + public ISettingsSection Settings => TypedSettings; + + /// + /// 获取事件发生的时间戳 + /// + public DateTime ChangedAt { get; } = DateTime.UtcNow; +} \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsSavedEvent.cs b/GFramework.Game/setting/events/SettingsSavedEvent.cs new file mode 100644 index 0000000..516bb02 --- /dev/null +++ b/GFramework.Game/setting/events/SettingsSavedEvent.cs @@ -0,0 +1,31 @@ +using GFramework.Game.Abstractions.setting; + +namespace GFramework.Game.setting.events; + +/// +/// 表示设置保存事件的泛型类 +/// +/// 设置节类型,必须实现ISettingsSection接口 +public class SettingsSavedEvent(T settings) : ISettingsChangedEvent + where T : ISettingsSection +{ + /// + /// 获取类型化的设置对象 + /// + public T TypedSettings { get; } = settings; + + /// + /// 获取设置类型的Type信息 + /// + public Type SettingsType => typeof(T); + + /// + /// 获取设置节对象 + /// + public ISettingsSection Settings => TypedSettings; + + /// + /// 获取设置更改的时间戳 + /// + public DateTime ChangedAt { get; } = DateTime.UtcNow; +} \ No newline at end of file