refactor 6:
- CombatInfoFormUseCase.cs 改成回调驱动:
- 不再直接读 GameEntry.CombatNode
- 由 CombatLoadSession.cs 在打开 CombatInfoForm 前注入 modelProvider 和 TryEndCombat 回调
- CombatSelectFormUseCase.cs 的默认 coin provider 改成返回 0,不再偷偷 fallback 到 GameEntry.CombatNode
- CombatFinishFormUseCase.cs 去掉了未准备 summary 时对 GameEntry.CombatNode 的兜底读取
- MapData.cs 进一步补充了战斗初始快照:
- InventorySnapshot
- ParticipantTowerSnapshot
- CombatLoadingState.cs 现在会把这些背包/参战塔快照也一起打进 MapData
- MapEntity.cs 配置建塔面板时不再直接读 PlayerInventory,改为用 MapData 里的快照
This commit is contained in:
+29
-3
@@ -45,7 +45,7 @@ namespace GeometryTD.CustomComponent
|
||||
_currentMap = null;
|
||||
}
|
||||
|
||||
public bool StartLoading(DRLevel level, MapData mapData, out string errorMessage)
|
||||
public bool StartLoading(DRLevel level, MapData mapData, CombatScheduler scheduler, out string errorMessage)
|
||||
{
|
||||
errorMessage = null;
|
||||
if (_entity == null)
|
||||
@@ -59,7 +59,7 @@ namespace GeometryTD.CustomComponent
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryOpenCombatInfoForm(out errorMessage))
|
||||
if (!TryOpenCombatInfoForm(scheduler, out errorMessage))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -249,7 +249,7 @@ namespace GeometryTD.CustomComponent
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool TryOpenCombatInfoForm(out string errorMessage)
|
||||
private bool TryOpenCombatInfoForm(CombatScheduler scheduler, out string errorMessage)
|
||||
{
|
||||
errorMessage = null;
|
||||
if (_combatInfoFormUseCase == null)
|
||||
@@ -258,6 +258,10 @@ namespace GeometryTD.CustomComponent
|
||||
GameEntry.UIRouter.BindUIUseCase(UIFormType.CombatInfoForm, _combatInfoFormUseCase);
|
||||
}
|
||||
|
||||
_combatInfoFormUseCase.Configure(
|
||||
() => BuildCombatInfoFormRawData(scheduler),
|
||||
() => scheduler != null && scheduler.CanEndCombat && scheduler.TryEndCombatByPlayer());
|
||||
|
||||
int? serialId = GameEntry.UIRouter.OpenUI(UIFormType.CombatInfoForm);
|
||||
if (!serialId.HasValue)
|
||||
{
|
||||
@@ -270,6 +274,28 @@ namespace GeometryTD.CustomComponent
|
||||
return true;
|
||||
}
|
||||
|
||||
private static CombatInfoFormRawData BuildCombatInfoFormRawData(CombatScheduler scheduler)
|
||||
{
|
||||
if (scheduler == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
DRLevel level = scheduler.CurrentLevel;
|
||||
LevelThemeType themeType = level != null ? level.LevelThemeType : LevelThemeType.None;
|
||||
int levelId = level != null ? level.Id : 0;
|
||||
int baseHpMax = level != null ? Mathf.Max(0, level.BaseHp) : 0;
|
||||
return CombatInfoFormUseCase.BuildRawData(
|
||||
themeType,
|
||||
levelId,
|
||||
scheduler.DisplayPhaseIndex,
|
||||
scheduler.PhaseCount,
|
||||
scheduler.CurrentCoin,
|
||||
scheduler.CurrentBaseHp,
|
||||
baseHpMax,
|
||||
scheduler.CanEndCombat);
|
||||
}
|
||||
|
||||
private void CloseCombatInfoForm()
|
||||
{
|
||||
GameEntry.UIRouter.CloseUI(UIFormType.CombatInfoForm);
|
||||
|
||||
+8
-1
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using GeometryTD.Definition;
|
||||
using GeometryTD.Entity.EntityData;
|
||||
using GeometryTD.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.CustomComponent
|
||||
@@ -22,7 +23,7 @@ namespace GeometryTD.CustomComponent
|
||||
}
|
||||
|
||||
MapData mapData = BuildMapData();
|
||||
if (!Scheduler._loadSession.StartLoading(Scheduler._currentLevel, mapData, out string errorMessage))
|
||||
if (!Scheduler._loadSession.StartLoading(Scheduler._currentLevel, mapData, Scheduler, out string errorMessage))
|
||||
{
|
||||
Scheduler.EnterFailureFallback($"Combat loading failed. {errorMessage}");
|
||||
}
|
||||
@@ -60,6 +61,12 @@ namespace GeometryTD.CustomComponent
|
||||
position: Vector3.zero,
|
||||
initialCoin: Scheduler._combatInRunResourceManager.CurrentCoin,
|
||||
buildTowerStatsSnapshot: buildTowerStatsSnapshot,
|
||||
inventorySnapshot: GameEntry.PlayerInventory != null
|
||||
? GameEntry.PlayerInventory.GetInventorySnapshot()
|
||||
: null,
|
||||
participantTowerSnapshot: GameEntry.PlayerInventory != null
|
||||
? GameEntry.PlayerInventory.GetParticipantTowerSnapshot()
|
||||
: null,
|
||||
tryConsumeCoin: Scheduler.TryConsumeCoin,
|
||||
addCoin: Scheduler.AddCoin);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user