feat(battle-engine-port): M2 step 1 — SingleBattleMgr constructs headless
First green of the M2 go/no-go probe: `new SingleBattleMgr(StandardBattleMgr- ContentsCreator)` now builds the two-player pair fully headless against the shim, no Unity runtime. Verdict: headless construction is feasible; every blocker was a mechanical no-op shim fill or data seam, not a Unity/logic wall. Shim fills (authored): - GameMgr: lazy non-null DataMgr/PrefabMgr/InputMgr/SoundMgr/BattleControl. - GameObject: lazy cached component model so GetComponent<T>/AddComponent<T> return non-null no-op instances for Component-derived T (F1: unguarded view touches). - Resources.Load(string): cached non-null GameObject so the prefab->Instantiate-> GetComponent chain (UnityEventAgent) yields a real object. - ClassBattleCardViewBase: re-attach dropped IClassBattleCardView (no-op members); ClassBattleCardBase.Setup casts the created view to it. Engine copy (DP1/DP3 mis-cut fix): - CardIconControl.cs copied verbatim (manifested) + generated null-stub deleted. SplitAndCompleteIconStr is pure string logic on the resolution path that M1 had wrongly stubbed as "View" -> null deref in SkillCreator.CreateBuildInfo. Test harness (SVSim.BattleEngine.Tests, authored fixture): - HeadlessContentsCreator/HeadlessPhaseCreator: deterministic replica of the solo practice init (StandardBattleMgrContentsCreator + SingleBattlePhaseCreator) with no-op recovery/replay managers. - HeadlessCardMaster: reflects the loader cards.json dump into CardMaster. - HeadlessMasterData: minimal Data.Master (class-character list, empty collections) + Data.Load + player/enemy chara ids. - ConstructionProbeTests.SingleBattleMgr_constructs_headless — GREEN. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
77
SVSim.BattleEngine.Tests/HeadlessFixture.cs
Normal file
77
SVSim.BattleEngine.Tests/HeadlessFixture.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Wizard.Battle.Phase;
|
||||
using Wizard.Battle.Recovery;
|
||||
using Wizard.Battle.Replay;
|
||||
using Wizard.Battle.Resource;
|
||||
using Wizard.Battle.View.Vfx;
|
||||
using Wizard.BattleMgr;
|
||||
|
||||
namespace SVSim.BattleEngine.Tests
|
||||
{
|
||||
// Initializes the global engine state a headless battle assumes exists. In the real client this
|
||||
// is populated from /load/index at login; here we author the minimum the resolution path reads.
|
||||
public static class HeadlessEngineEnv
|
||||
{
|
||||
private static bool _done;
|
||||
|
||||
public static void EnsureInitialized()
|
||||
{
|
||||
if (_done) return;
|
||||
// Wizard.Data.Load: static /load/index snapshot. The ctor's CreateBackgroundId reads
|
||||
// Data.Load.data._userTutorial (LoadDetail self-inits _userTutorial). Suppress VFX too.
|
||||
Wizard.Data.Load = new Load { data = new LoadDetail() };
|
||||
BattleManagerBase.IsForecast = true;
|
||||
// CardMaster must be non-null before construction (the leader/class card looks up id 0).
|
||||
// Empty load suffices for construction; the oracle reloads with the follower's real id.
|
||||
HeadlessCardMaster.Load();
|
||||
// Master reference data (class-character list) for leader/class card resolution.
|
||||
HeadlessMasterData.Install();
|
||||
// Player/enemy leaders (chara ids must map to a ClassCharacterMasterData in Master).
|
||||
// Set the backing fields directly: the public SetPlayerCharaId() also pulls MyRotation/
|
||||
// AvatarBattle info (more null statics) which the resolution path doesn't need (the
|
||||
// TryGet* accessors are null-tolerant).
|
||||
var dm = GameMgr.GetIns().GetDataMgr();
|
||||
SetField(dm, "_playerCharaId", HeadlessMasterData.PlayerCharaId);
|
||||
SetField(dm, "_enemyCharaId", HeadlessMasterData.EnemyCharaId);
|
||||
_done = true;
|
||||
}
|
||||
|
||||
private static void SetField(object obj, string name, object value)
|
||||
{
|
||||
var f = obj.GetType().GetField(name,
|
||||
System.Reflection.BindingFlags.Instance |
|
||||
System.Reflection.BindingFlags.NonPublic |
|
||||
System.Reflection.BindingFlags.Public);
|
||||
if (f == null) throw new System.InvalidOperationException(
|
||||
$"{obj.GetType().Name} has no field '{name}'");
|
||||
f.SetValue(obj, value);
|
||||
}
|
||||
}
|
||||
|
||||
// Test-side replica of the engine's own StandardBattleMgrContentsCreator (the practice/solo
|
||||
// init path: GameMgr.cs:244 `new SingleBattleMgr(new StandardBattleMgrContentsCreator(null, null))`).
|
||||
// Authored here (not copied) so we control the seed deterministically; uses the real engine
|
||||
// managers verbatim. The real StandardBattleMgrContentsCreator + SingleBattlePhaseCreator were
|
||||
// cut from the M1 copy set (entry-point constructors), so we reproduce them minimally.
|
||||
public sealed class HeadlessContentsCreator : IBattleMgrContentsCreator
|
||||
{
|
||||
public int RandomSeed => 12345; // fixed; vanilla follower has no RNG so value is irrelevant
|
||||
|
||||
// No-op managers (vs the practice path's file-backed SingleBattleRecoveryRecordManager):
|
||||
// the ctor's FirstRecoverySetting/FirstReplaySetting dereference these, and recovery/replay
|
||||
// recording is irrelevant to the M2 oracle, so use the engine's own null implementations.
|
||||
public IRecoveryManager RecoveryManager { get; } = new NullRecoveryManager();
|
||||
public IRecoveryRecordManager RecoveryRecordManager { get; } = new NullRecoveryRecordManager();
|
||||
public IReplayRecordManager ReplayRecordManager { get; } = new NullReplayRecordManager();
|
||||
|
||||
public IBattleResourceMgr CreateResourceMgr() => new BattleResourceMgr();
|
||||
public VfxMgr CreateVfxMgr() => new VfxMgr();
|
||||
public IPhaseCreator CreatePhaseCreator(BattleManagerBase battleMgr) =>
|
||||
new HeadlessPhaseCreator(battleMgr);
|
||||
}
|
||||
|
||||
// Equivalent of the engine's SingleBattlePhaseCreator: inherits PhaseCreatorBase wholesale.
|
||||
public sealed class HeadlessPhaseCreator : PhaseCreatorBase
|
||||
{
|
||||
public HeadlessPhaseCreator(BattleManagerBase battleMgr) : base(battleMgr) { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user