refactor(state): 将状态机相关类重命名以统一命名规范

- 将 ContextAwareStateMachine 重命名为 StateMachineSystem
- 将 ContextAwareStateMachineTests 重命名为 StateMachineSystemTests
- 将 GameStateMachine 重命名为 GameStateMachineSystem
- 创建新的 IStateMachineSystem 接口继承 ISystem 和 IStateMachine
- 移除 ContextAwareStateMachine 中对 system 的引用
- 将 Context 字段改为私有 _context 字段
- 更新所有测试类中的类型引用以匹配新名称
This commit is contained in:
GeWuYou 2026-01-17 21:13:38 +08:00
parent 193e3f2cfa
commit bbb8d417f6
4 changed files with 19 additions and 11 deletions

View File

@ -0,0 +1,9 @@
using GFramework.Core.Abstractions.system;
namespace GFramework.Core.Abstractions.state;
/// <summary>
/// 状态机系统接口继承自ISystem和IStateMachine接口
/// 提供状态机系统的功能定义,结合了系统管理和状态机管理的能力
/// </summary>
public interface IStateMachineSystem : ISystem, IStateMachine;

View File

@ -30,7 +30,7 @@ namespace GFramework.Core.Tests.state;
/// - 状态机生命周期完整性
/// </summary>
[TestFixture]
public class ContextAwareStateMachineTests
public class StateMachineSystemTests
{
[SetUp]
public void SetUp()
@ -43,11 +43,11 @@ public class ContextAwareStateMachineTests
new QueryBus(),
new DefaultEnvironment());
_stateMachine = new TestContextAwareStateMachineV5();
_stateMachine = new TestStateMachineSystemV5();
_stateMachine.SetContext(_context);
}
private TestContextAwareStateMachineV5? _stateMachine;
private TestStateMachineSystemV5? _stateMachine;
private ArchitectureContext? _context;
private EventBus? _eventBus;
@ -263,7 +263,7 @@ public class ContextAwareStateMachineTests
/// <summary>
/// 测试用的ContextAwareStateMachine派生类用于访问内部状态字典
/// </summary>
public class TestContextAwareStateMachineV5 : ContextAwareStateMachine
public class TestStateMachineSystemV5 : StateMachineSystem
{
/// <summary>
/// 获取状态机内部的状态字典

View File

@ -2,7 +2,6 @@
using GFramework.Core.Abstractions.enums;
using GFramework.Core.Abstractions.rule;
using GFramework.Core.Abstractions.state;
using GFramework.Core.Abstractions.system;
using GFramework.Core.extensions;
using IDisposable = GFramework.Core.Abstractions.lifecycle.IDisposable;
@ -12,12 +11,12 @@ namespace GFramework.Core.state;
/// 上下文感知状态机继承自StateMachine并实现ISystem接口
/// 该状态机能够感知架构上下文,并在状态切换时发送状态变更事件
/// </summary>
public class ContextAwareStateMachine : StateMachine, ISystem
public class StateMachineSystem : StateMachine, IStateMachineSystem
{
/// <summary>
/// 架构上下文对象,用于提供系统运行所需的上下文信息
/// </summary>
protected IArchitectureContext Context = null!;
private IArchitectureContext _context = null!;
/// <summary>
/// 设置架构上下文的方法
@ -25,7 +24,7 @@ public class ContextAwareStateMachine : StateMachine, ISystem
/// <param name="context">要设置的架构上下文对象</param>
public void SetContext(IArchitectureContext context)
{
Context = context;
_context = context;
}
/// <summary>
@ -34,7 +33,7 @@ public class ContextAwareStateMachine : StateMachine, ISystem
/// <returns>当前的架构上下文对象</returns>
public IArchitectureContext GetContext()
{
return Context;
return _context;
}
/// <summary>
@ -53,7 +52,7 @@ public class ContextAwareStateMachine : StateMachine, ISystem
{
foreach (var state in States.Values.OfType<IContextAware>())
{
state.SetContext(Context);
state.SetContext(_context);
}
}

View File

@ -6,7 +6,7 @@ namespace GFramework.Game.state;
/// <summary>
/// 游戏状态机类继承自ContextAwareStateMachine用于管理游戏中的各种状态
/// </summary>
public sealed class GameStateMachine : ContextAwareStateMachine
public sealed class GameStateMachineSystem : StateMachineSystem
{
/// <summary>
/// 检查当前状态是否为指定类型的状态