diff --git a/GFramework.Game/setting/SettingsModel.cs b/GFramework.Game/setting/SettingsModel.cs index 7ea4d67..7f9f6b8 100644 --- a/GFramework.Game/setting/SettingsModel.cs +++ b/GFramework.Game/setting/SettingsModel.cs @@ -4,6 +4,7 @@ using GFramework.Core.logging; using GFramework.Core.model; using GFramework.Game.Abstractions.data; using GFramework.Game.Abstractions.setting; +using GFramework.Game.setting.events; namespace GFramework.Game.setting; @@ -135,6 +136,8 @@ public class SettingsModel(IDataLocationProvider? locationProvider, Log.Error($"Failed to initialize settings data: {data.GetType().Name}", ex); } } + + this.SendEvent(new SettingsInitializedEvent()); } @@ -155,6 +158,8 @@ public class SettingsModel(IDataLocationProvider? locationProvider, Log.Error($"Failed to save settings data: {data.GetType().Name}", ex); } } + + this.SendEvent(new SettingsSavedAllEvent()); } /// @@ -173,6 +178,8 @@ public class SettingsModel(IDataLocationProvider? locationProvider, Log.Error($"Failed to apply settings: {applicator.GetType().Name}", ex); } } + + this.SendEvent(new SettingsAppliedAllEvent()); } /// @@ -183,6 +190,7 @@ public class SettingsModel(IDataLocationProvider? locationProvider, { var data = GetData(); data.Reset(); + this.SendEvent(new SettingsResetEvent(data)); } /// @@ -195,6 +203,7 @@ public class SettingsModel(IDataLocationProvider? locationProvider, foreach (var applicator in _applicators) applicator.Value.Reset(); + this.SendEvent(new SettingsResetAllEvent(_data.Values)); } /// diff --git a/GFramework.Game/setting/events/SettingsAllLoadedEvent.cs b/GFramework.Game/setting/events/SettingsAllLoadedEvent.cs deleted file mode 100644 index 3b480fa..0000000 --- a/GFramework.Game/setting/events/SettingsAllLoadedEvent.cs +++ /dev/null @@ -1,30 +0,0 @@ -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/SettingsAppliedAllEvent.cs b/GFramework.Game/setting/events/SettingsAppliedAllEvent.cs new file mode 100644 index 0000000..c77db89 --- /dev/null +++ b/GFramework.Game/setting/events/SettingsAppliedAllEvent.cs @@ -0,0 +1,16 @@ +// Copyright (c) 2026 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.Game.setting.events; + +public sealed class SettingsAppliedAllEvent; \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsBatchChangedEvent.cs b/GFramework.Game/setting/events/SettingsBatchChangedEvent.cs deleted file mode 100644 index c54a737..0000000 --- a/GFramework.Game/setting/events/SettingsBatchChangedEvent.cs +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index d4fb426..0000000 --- a/GFramework.Game/setting/events/SettingsBatchSavedEvent.cs +++ /dev/null @@ -1,30 +0,0 @@ -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 deleted file mode 100644 index e83fc74..0000000 --- a/GFramework.Game/setting/events/SettingsChangedEvent.cs +++ /dev/null @@ -1,32 +0,0 @@ -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/SettingsDeletedEvent.cs b/GFramework.Game/setting/events/SettingsDeletedEvent.cs deleted file mode 100644 index 923862e..0000000 --- a/GFramework.Game/setting/events/SettingsDeletedEvent.cs +++ /dev/null @@ -1,24 +0,0 @@ -using GFramework.Game.Abstractions.setting; - -namespace GFramework.Game.setting.events; - -/// -/// 表示设置删除事件 -/// -public class SettingsDeletedEvent(Type settingsType) : ISettingsChangedEvent -{ - /// - /// 获取被删除的设置类型 - /// - public Type SettingsType { get; } = settingsType; - - /// - /// 获取设置实例,删除事件中返回 null - /// - public ISettingsSection Settings => null!; - - /// - /// 获取删除时间 - /// - public DateTime ChangedAt { get; } = DateTime.UtcNow; -} \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsInitializedEvent.cs b/GFramework.Game/setting/events/SettingsInitializedEvent.cs new file mode 100644 index 0000000..2974514 --- /dev/null +++ b/GFramework.Game/setting/events/SettingsInitializedEvent.cs @@ -0,0 +1,16 @@ +// Copyright (c) 2026 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.Game.setting.events; + +public sealed class SettingsInitializedEvent; \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsLoadedEvent.cs b/GFramework.Game/setting/events/SettingsLoadedEvent.cs deleted file mode 100644 index 094059c..0000000 --- a/GFramework.Game/setting/events/SettingsLoadedEvent.cs +++ /dev/null @@ -1,31 +0,0 @@ -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/SettingsSavedAllEvent.cs b/GFramework.Game/setting/events/SettingsSavedAllEvent.cs new file mode 100644 index 0000000..7c0b151 --- /dev/null +++ b/GFramework.Game/setting/events/SettingsSavedAllEvent.cs @@ -0,0 +1,16 @@ +// Copyright (c) 2026 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.Game.setting.events; + +public sealed class SettingsSavedAllEvent; \ No newline at end of file diff --git a/GFramework.Game/setting/events/SettingsSavedEvent.cs b/GFramework.Game/setting/events/SettingsSavedEvent.cs deleted file mode 100644 index e8a7005..0000000 --- a/GFramework.Game/setting/events/SettingsSavedEvent.cs +++ /dev/null @@ -1,31 +0,0 @@ -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