迁移测试文件,建立主程序集

This commit is contained in:
SepComet
2026-03-08 18:08:13 +08:00
parent 548bc77ba6
commit 1023239880
16 changed files with 351 additions and 307 deletions
+18
View File
@@ -0,0 +1,18 @@
{
"name": "GeometryTD.Runtime",
"rootNamespace": "GeometryTD",
"references": [
"UnityGameFramework.Runtime",
"Unity.InputSystem",
"Unity.TextMeshPro"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e67bd2d1b65d48ce8120141996e55b2b
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,19 @@
{
"name": "GeometryTD.Editor",
"rootNamespace": "GeometryTD.Editor",
"references": [
"GeometryTD.Runtime",
"UnityGameFramework.Editor"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 739d2e9771244fc8af6c8d8636eade79
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -8,6 +8,44 @@ using UnityGameFramework.Runtime;
namespace GeometryTD.Procedure
{
public enum ProcedureMainFlowPhase
{
Hub = 0,
NodeActive = 1,
RunCompletedPendingFinish = 2
}
public enum ProcedureMainRunAdvanceResult
{
NoChange = 0,
NodeFailed = 1,
AdvancedToNextNode = 2,
RunCompleted = 3
}
public static class ProcedureMainRunFlowService
{
public static ProcedureMainRunAdvanceResult TryAdvanceRun(
RunState runState,
bool succeeded,
BackpackInventoryData snapshot)
{
if (!RunStateAdvanceService.TryCompleteCurrentNode(runState, succeeded, snapshot))
{
return ProcedureMainRunAdvanceResult.NoChange;
}
if (runState != null && runState.IsCompleted)
{
return ProcedureMainRunAdvanceResult.RunCompleted;
}
return succeeded
? ProcedureMainRunAdvanceResult.AdvancedToNextNode
: ProcedureMainRunAdvanceResult.NodeFailed;
}
}
public class ProcedureMain : ProcedureBase
{
public override bool UseNativeDialog => false;
@@ -15,6 +53,7 @@ namespace GeometryTD.Procedure
private RepoFormUseCase _repoFormUseCase;
private NodeMapFormUseCase _nodeMapFormUseCase;
private RunState _currentRunState;
private ProcedureMainFlowPhase _flowPhase = ProcedureMainFlowPhase.Hub;
#region FSM
@@ -45,7 +84,7 @@ namespace GeometryTD.Procedure
_nodeMapFormUseCase.SetRunState(_currentRunState);
GameEntry.UIRouter.BindUIUseCase(UIFormType.NodeMapForm, _nodeMapFormUseCase);
OpenHubUI();
EnterHubFlow();
}
protected override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
@@ -69,6 +108,7 @@ namespace GeometryTD.Procedure
_repoFormUseCase = null;
_nodeMapFormUseCase = null;
_currentRunState = null;
_flowPhase = ProcedureMainFlowPhase.Hub;
base.OnLeave(procedureOwner, isShutdown);
}
@@ -117,8 +157,7 @@ namespace GeometryTD.Procedure
args.NodeType,
args.SequenceIndex);
GameEntry.UIRouter.CloseUI(UIFormType.NodeMapForm);
GameEntry.UIRouter.CloseUI(UIFormType.MainForm);
EnterNodeFlow();
}
private void OnNodeComplete(object sender, GameEventArgs e)
@@ -145,8 +184,7 @@ namespace GeometryTD.Procedure
snapshot = GameEntry.PlayerInventory.GetInventorySnapshot();
}
AdvanceRunState(args.Succeeded, snapshot);
OpenHubUI();
HandleRunAdvanceResult(ProcedureMainRunFlowService.TryAdvanceRun(_currentRunState, args.Succeeded, snapshot));
}
private void OnCombatFailureReturn(object sender, GameEventArgs e)
@@ -159,8 +197,7 @@ namespace GeometryTD.Procedure
BackpackInventoryData snapshot = GameEntry.PlayerInventory != null
? GameEntry.PlayerInventory.GetInventorySnapshot()
: null;
AdvanceRunState(false, snapshot);
OpenHubUI();
HandleRunAdvanceResult(ProcedureMainRunFlowService.TryAdvanceRun(_currentRunState, false, snapshot));
}
private void OnNodeMapNodeEnterRequested(object sender, GameEventArgs e)
@@ -171,9 +208,15 @@ namespace GeometryTD.Procedure
}
RunNodeState currentNode = _currentRunState?.CurrentNode;
if (_currentRunState == null || !_currentRunState.CanEnterCurrentNode || currentNode == null)
if (_currentRunState == null ||
_flowPhase != ProcedureMainFlowPhase.Hub ||
!_currentRunState.CanEnterCurrentNode ||
currentNode == null)
{
Log.Warning("ProcedureMain.OnNodeMapNodeEnterRequested() ignored. Current run has no enterable node.");
Log.Warning(
"ProcedureMain.OnNodeMapNodeEnterRequested() ignored. FlowPhase={0}, HasEnterableNode={1}.",
_flowPhase,
_currentRunState != null && _currentRunState.CanEnterCurrentNode);
return;
}
@@ -226,33 +269,30 @@ namespace GeometryTD.Procedure
}
}
private void AdvanceRunState(bool succeeded, BackpackInventoryData snapshot)
private void HandleRunAdvanceResult(ProcedureMainRunAdvanceResult result)
{
if (_currentRunState == null)
switch (result)
{
return;
}
if (!RunStateAdvanceService.TryCompleteCurrentNode(_currentRunState, succeeded, snapshot))
{
return;
}
if (_currentRunState.IsCompleted)
{
Log.Info("ProcedureMain run completed. RunId={0}", _currentRunState.RunId);
return;
}
RunNodeState nextNode = _currentRunState.CurrentNode;
if (nextNode != null)
{
Log.Info(
"ProcedureMain advanced run. RunId={0}, NextNodeType={1}, SequenceIndex={2}, LevelId={3}.",
_currentRunState.RunId,
nextNode.NodeType,
nextNode.SequenceIndex,
nextNode.LinkedLevelId);
case ProcedureMainRunAdvanceResult.NoChange:
return;
case ProcedureMainRunAdvanceResult.NodeFailed:
Log.Info(
"ProcedureMain current node failed. RunId={0}, NodeId={1}, NodeType={2}, SequenceIndex={3}.",
_currentRunState?.RunId,
_currentRunState?.CurrentNode?.NodeId ?? 0,
_currentRunState?.CurrentNode?.NodeType ?? RunNodeType.None,
_currentRunState?.CurrentNode?.SequenceIndex ?? -1);
EnterHubFlow();
return;
case ProcedureMainRunAdvanceResult.AdvancedToNextNode:
LogNextNode();
EnterHubFlow();
return;
case ProcedureMainRunAdvanceResult.RunCompleted:
EnterRunCompletedPendingFinish();
return;
default:
return;
}
}
@@ -262,11 +302,48 @@ namespace GeometryTD.Procedure
GameEntry.PlayerInventory.GetParticipantTowerSnapshot().Count > 0;
}
private void OpenHubUI()
private void EnterHubFlow()
{
_flowPhase = ProcedureMainFlowPhase.Hub;
_nodeMapFormUseCase?.SetRunState(_currentRunState);
GameEntry.UIRouter.OpenUI(UIFormType.NodeMapForm);
GameEntry.UIRouter.OpenUI(UIFormType.MainForm);
}
private void EnterNodeFlow()
{
_flowPhase = ProcedureMainFlowPhase.NodeActive;
CloseHubUI();
}
private void EnterRunCompletedPendingFinish()
{
_flowPhase = ProcedureMainFlowPhase.RunCompletedPendingFinish;
_nodeMapFormUseCase?.SetRunState(_currentRunState);
CloseHubUI();
Log.Info("ProcedureMain run completed. RunId={0}", _currentRunState?.RunId);
}
private void CloseHubUI()
{
GameEntry.UIRouter.CloseUI(UIFormType.NodeMapForm);
GameEntry.UIRouter.CloseUI(UIFormType.MainForm);
}
private void LogNextNode()
{
RunNodeState nextNode = _currentRunState?.CurrentNode;
if (nextNode == null)
{
return;
}
Log.Info(
"ProcedureMain advanced run. RunId={0}, NextNodeType={1}, SequenceIndex={2}, LevelId={3}.",
_currentRunState.RunId,
nextNode.NodeType,
nextNode.SequenceIndex,
nextNode.LinkedLevelId);
}
}
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d9f1bdc0fe72470fbe5ee26565921a4b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 377f170c02c1478bafc8f641391a7887
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,24 @@
{
"name": "GeometryTD.Tests.EditMode",
"rootNamespace": "GeometryTD.Tests.EditMode",
"references": [
"GeometryTD.Runtime",
"UnityGameFramework.Runtime"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"GameFramework.dll"
],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false,
"optionalUnityReferences": [
"TestAssemblies"
]
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9d9745e0e8394cfa84739c027b399124
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -4,7 +4,7 @@ using GeometryTD.Definition;
using GeometryTD.Procedure;
using NUnit.Framework;
namespace GeometryTD.Tests.Editor
namespace GeometryTD.Tests.EditMode
{
public sealed class RunStateTests
{
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 3d3e6fd8ec274118b59f66c6efc41405
guid: e010ded52b54f984589333da57b3f393
MonoImporter:
externalObjects: {}
serializedVersion: 2
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0c4132be2aca4c2cae2e3d8dc89d020a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,22 @@
{
"name": "GeometryTD.Tests.PlayMode",
"rootNamespace": "GeometryTD.Tests.PlayMode",
"references": [
"GeometryTD.Runtime",
"UnityGameFramework.Runtime"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"GameFramework.dll"
],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false,
"optionalUnityReferences": [
"TestAssemblies"
]
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 10188d8fe2854dd4ace136e83d968aa7
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: