From bbb8d417f6025b5fee05a60fcb3f79c14bf72c91 Mon Sep 17 00:00:00 2001
From: GeWuYou <95328647+GeWuYou@users.noreply.github.com>
Date: Sat, 17 Jan 2026 21:13:38 +0800
Subject: [PATCH] =?UTF-8?q?refactor(state):=20=E5=B0=86=E7=8A=B6=E6=80=81?=
=?UTF-8?q?=E6=9C=BA=E7=9B=B8=E5=85=B3=E7=B1=BB=E9=87=8D=E5=91=BD=E5=90=8D?=
=?UTF-8?q?=E4=BB=A5=E7=BB=9F=E4=B8=80=E5=91=BD=E5=90=8D=E8=A7=84=E8=8C=83?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 将 ContextAwareStateMachine 重命名为 StateMachineSystem
- 将 ContextAwareStateMachineTests 重命名为 StateMachineSystemTests
- 将 GameStateMachine 重命名为 GameStateMachineSystem
- 创建新的 IStateMachineSystem 接口继承 ISystem 和 IStateMachine
- 移除 ContextAwareStateMachine 中对 system 的引用
- 将 Context 字段改为私有 _context 字段
- 更新所有测试类中的类型引用以匹配新名称
---
.../state/IStateMachineSystem.cs | 9 +++++++++
...tateMachineTests.cs => StateMachineSystemTests.cs} | 8 ++++----
...textAwareStateMachine.cs => StateMachineSystem.cs} | 11 +++++------
...{GameStateMachine.cs => GameStateMachineSystem.cs} | 2 +-
4 files changed, 19 insertions(+), 11 deletions(-)
create mode 100644 GFramework.Core.Abstractions/state/IStateMachineSystem.cs
rename GFramework.Core.Tests/state/{ContextAwareStateMachineTests.cs => StateMachineSystemTests.cs} (97%)
rename GFramework.Core/state/{ContextAwareStateMachine.cs => StateMachineSystem.cs} (91%)
rename GFramework.Game/state/{GameStateMachine.cs => GameStateMachineSystem.cs} (94%)
diff --git a/GFramework.Core.Abstractions/state/IStateMachineSystem.cs b/GFramework.Core.Abstractions/state/IStateMachineSystem.cs
new file mode 100644
index 0000000..c31021b
--- /dev/null
+++ b/GFramework.Core.Abstractions/state/IStateMachineSystem.cs
@@ -0,0 +1,9 @@
+using GFramework.Core.Abstractions.system;
+
+namespace GFramework.Core.Abstractions.state;
+
+///
+/// 状态机系统接口,继承自ISystem和IStateMachine接口
+/// 提供状态机系统的功能定义,结合了系统管理和状态机管理的能力
+///
+public interface IStateMachineSystem : ISystem, IStateMachine;
\ No newline at end of file
diff --git a/GFramework.Core.Tests/state/ContextAwareStateMachineTests.cs b/GFramework.Core.Tests/state/StateMachineSystemTests.cs
similarity index 97%
rename from GFramework.Core.Tests/state/ContextAwareStateMachineTests.cs
rename to GFramework.Core.Tests/state/StateMachineSystemTests.cs
index d52d71a..bc28b49 100644
--- a/GFramework.Core.Tests/state/ContextAwareStateMachineTests.cs
+++ b/GFramework.Core.Tests/state/StateMachineSystemTests.cs
@@ -30,7 +30,7 @@ namespace GFramework.Core.Tests.state;
/// - 状态机生命周期完整性
///
[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
///
/// 测试用的ContextAwareStateMachine派生类,用于访问内部状态字典
///
-public class TestContextAwareStateMachineV5 : ContextAwareStateMachine
+public class TestStateMachineSystemV5 : StateMachineSystem
{
///
/// 获取状态机内部的状态字典
diff --git a/GFramework.Core/state/ContextAwareStateMachine.cs b/GFramework.Core/state/StateMachineSystem.cs
similarity index 91%
rename from GFramework.Core/state/ContextAwareStateMachine.cs
rename to GFramework.Core/state/StateMachineSystem.cs
index d47fef4..477a356 100644
--- a/GFramework.Core/state/ContextAwareStateMachine.cs
+++ b/GFramework.Core/state/StateMachineSystem.cs
@@ -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接口
/// 该状态机能够感知架构上下文,并在状态切换时发送状态变更事件
///
-public class ContextAwareStateMachine : StateMachine, ISystem
+public class StateMachineSystem : StateMachine, IStateMachineSystem
{
///
/// 架构上下文对象,用于提供系统运行所需的上下文信息
///
- protected IArchitectureContext Context = null!;
+ private IArchitectureContext _context = null!;
///
/// 设置架构上下文的方法
@@ -25,7 +24,7 @@ public class ContextAwareStateMachine : StateMachine, ISystem
/// 要设置的架构上下文对象
public void SetContext(IArchitectureContext context)
{
- Context = context;
+ _context = context;
}
///
@@ -34,7 +33,7 @@ public class ContextAwareStateMachine : StateMachine, ISystem
/// 当前的架构上下文对象
public IArchitectureContext GetContext()
{
- return Context;
+ return _context;
}
///
@@ -53,7 +52,7 @@ public class ContextAwareStateMachine : StateMachine, ISystem
{
foreach (var state in States.Values.OfType())
{
- state.SetContext(Context);
+ state.SetContext(_context);
}
}
diff --git a/GFramework.Game/state/GameStateMachine.cs b/GFramework.Game/state/GameStateMachineSystem.cs
similarity index 94%
rename from GFramework.Game/state/GameStateMachine.cs
rename to GFramework.Game/state/GameStateMachineSystem.cs
index 64298e7..42270fa 100644
--- a/GFramework.Game/state/GameStateMachine.cs
+++ b/GFramework.Game/state/GameStateMachineSystem.cs
@@ -6,7 +6,7 @@ namespace GFramework.Game.state;
///
/// 游戏状态机类,继承自ContextAwareStateMachine,用于管理游戏中的各种状态
///
-public sealed class GameStateMachine : ContextAwareStateMachine
+public sealed class GameStateMachineSystem : StateMachineSystem
{
///
/// 检查当前状态是否为指定类型的状态