refactor(engine-ambient): ViewerId/RealTimeNetworkAgent/BattleRecoveryInfo read ambient first
Step 4 of multi-instancing migration. Three additional per-battle statics front-fronted by BattleAmbient.Current, each with a static fallback for unwrapped callers. ViewerId's SavedataManager-persisting setter is preserved on the fallback path; inside a scope, the setter is a no-op (the per-battle perspective is fixed at scope entry). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -148,4 +148,45 @@ public class BattleAmbientTests
|
||||
var v = BattleManagerBase.GetIns();
|
||||
Assert.Pass($"GetIns()={(v is null ? "null" : v.GetType().Name)}");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ViewerId_ReadsAmbient_WhenScopeActive()
|
||||
{
|
||||
var ctx = new BattleAmbientContext { ViewerId = 12345 };
|
||||
using var _ = BattleAmbient.Enter(ctx);
|
||||
Assert.That(Cute.Certification.ViewerId, Is.EqualTo(12345));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RealTimeNetworkAgent_ReadsAmbient_WhenScopeActive()
|
||||
{
|
||||
var ctx = new BattleAmbientContext();
|
||||
using var _ = BattleAmbient.Enter(ctx);
|
||||
Assert.That(Wizard.ToolboxGame.RealTimeNetworkAgent, Is.Null);
|
||||
var agent = (RealTimeNetworkAgent)System.Runtime.Serialization
|
||||
.FormatterServices.GetUninitializedObject(typeof(RealTimeNetworkAgent));
|
||||
ctx.NetworkAgent = agent;
|
||||
Assert.That(Wizard.ToolboxGame.RealTimeNetworkAgent, Is.SameAs(agent));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetRealTimeNetworkBattle_InsideScope_WritesAmbient()
|
||||
{
|
||||
var ctx = new BattleAmbientContext();
|
||||
using var _ = BattleAmbient.Enter(ctx);
|
||||
var agent = (RealTimeNetworkAgent)System.Runtime.Serialization
|
||||
.FormatterServices.GetUninitializedObject(typeof(RealTimeNetworkAgent));
|
||||
Wizard.ToolboxGame.SetRealTimeNetworkBattle(agent);
|
||||
Assert.That(ctx.NetworkAgent, Is.SameAs(agent));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BattleRecoveryInfo_ReadsAmbient_WhenScopeActive()
|
||||
{
|
||||
var info = (Wizard.BattleRecoveryInfo)System.Runtime.Serialization
|
||||
.FormatterServices.GetUninitializedObject(typeof(Wizard.BattleRecoveryInfo));
|
||||
var ctx = new BattleAmbientContext { RecoveryInfo = info };
|
||||
using var _ = BattleAmbient.Enter(ctx);
|
||||
Assert.That(Wizard.Data.BattleRecoveryInfo, Is.SameAs(info));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user