Skip to content

Commit 5b66514

Browse files
committed
[修改]1. 修改存档接口所属
1 parent 49fc3b7 commit 5b66514

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

GameFrameX.Core/Actors/Actor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ internal async Task SaveAllState()
262262
{
263263
foreach (var item in _componentsMap)
264264
{
265-
await item.Value.SaveState();
265+
await item.Value.WriteStateAsync();
266266
}
267267
}
268268

GameFrameX.Core/Components/BaseComponent.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace GameFrameX.Core.Components;
77
/// <summary>
88
/// 基础组件基类
99
/// </summary>
10-
public abstract class BaseComponent : IComponent
10+
public abstract class BaseComponent : IComponent, IState
1111
{
1212
private readonly object _cacheAgentLock = new();
1313
private IComponentAgent _cacheAgent;
@@ -93,11 +93,21 @@ public virtual async Task Inactive()
9393
}
9494

9595
/// <summary>
96-
/// 保存数据
96+
/// 读取状态
9797
/// </summary>
98-
/// <returns>保存任务</returns>
99-
internal virtual Task SaveState()
100-
{
101-
return Task.CompletedTask;
102-
}
98+
/// <returns>一个表示异步操作的任务,该任务在状态读取完成时完成</returns>
99+
/// <remarks>
100+
/// 此方法用于异步读取对象的当前状态信息
101+
/// </remarks>
102+
public abstract Task ReadStateAsync();
103+
104+
/// <summary>
105+
/// 更新状态
106+
/// </summary>
107+
/// <returns>一个表示异步操作的任务,该任务在状态更新完成时完成</returns>
108+
/// <remarks>
109+
/// 此方法用于异步更新对象的状态信息
110+
/// 在状态发生变化时应调用此方法以保持状态的同步
111+
/// </remarks>
112+
public abstract Task WriteStateAsync();
103113
}

GameFrameX.Core/Components/StateComponent.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static async Task TimerSave()
8888
/// 数据状态组件
8989
/// </summary>
9090
/// <typeparam name="TState"></typeparam>
91-
public abstract class StateComponent<TState> : BaseComponent, IState where TState : BaseCacheState, new()
91+
public abstract class StateComponent<TState> : BaseComponent where TState : BaseCacheState, new()
9292
{
9393
private static readonly ConcurrentDictionary<long, TState> StateDic = new ConcurrentDictionary<long, TState>();
9494

@@ -127,9 +127,10 @@ protected virtual Task<TState> ActiveReadStateAsync()
127127

128128
/// <summary>
129129
/// 准备并读取状态数据
130+
/// 子类不要重写该函数,而是重写ActiveReadStateAsync函数
130131
/// </summary>
131132
/// <returns>异步任务</returns>
132-
public async Task ReadStateAsync()
133+
public override async Task ReadStateAsync()
133134
{
134135
try
135136
{
@@ -181,7 +182,7 @@ public override Task Inactive()
181182
/// 保存状态到数据库
182183
/// </summary>
183184
/// <returns>异步任务</returns>
184-
internal override async Task SaveState()
185+
protected async Task SaveState()
185186
{
186187
try
187188
{
@@ -200,20 +201,11 @@ internal override async Task SaveState()
200201
/// 异步写入状态到数据库
201202
/// </summary>
202203
/// <returns>异步任务</returns>
203-
public async Task WriteStateAsync()
204+
public override async Task WriteStateAsync()
204205
{
205206
await SaveState();
206207
}
207208

208-
/// <summary>
209-
/// 保存数据的虚方法,可被子类重写
210-
/// </summary>
211-
/// <returns>异步任务</returns>
212-
public virtual Task SaveAsync()
213-
{
214-
return WriteStateAsync();
215-
}
216-
217209
#region 仅DBModel.Mongodb调用
218210

219211
/// <summary>

0 commit comments

Comments
 (0)