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:
gamer147
2026-06-07 21:37:58 -04:00
parent 4e756a6c46
commit fe146fde50
9 changed files with 230 additions and 16 deletions

View File

@@ -16,7 +16,7 @@ public class Certification : MonoBehaviour
private static string udid;
private static int viewer_id;
private static int _viewerIdFallback;
private static int short_udid;
@@ -42,17 +42,25 @@ public class Certification : MonoBehaviour
{
get
{
if (viewer_id == 0)
var c = SVSim.BattleEngine.Ambient.BattleAmbient.Current;
if (c != null) return c.ViewerId;
if (_viewerIdFallback == 0)
{
viewer_id = Toolbox.SavedataManager.GetInt("VIEWER_ID");
_viewerIdFallback = Toolbox.SavedataManager.GetInt("VIEWER_ID");
}
return viewer_id;
return _viewerIdFallback;
}
set
{
var c = SVSim.BattleEngine.Ambient.BattleAmbient.Current;
if (c != null)
{
// Inside a scope, ViewerId is fixed at scope entry — swallow the write.
return;
}
Toolbox.SavedataManager.SetInt("VIEWER_ID", value);
Toolbox.SavedataManager.Save();
viewer_id = value;
_viewerIdFallback = value;
}
}
@@ -144,7 +152,7 @@ public class Certification : MonoBehaviour
{
sessionId = null;
udid = null;
viewer_id = 0;
_viewerIdFallback = 0;
short_udid = 0;
Toolbox.SavedataManager.SetInt("VIEWER_ID", 0);
Toolbox.SavedataManager.SetInt("SHORT_UDID", 0);

View File

@@ -176,7 +176,17 @@ public static class Data
public static ReplayDetailInfo ReplayBattleInfo { get; set; }
public static BattleRecoveryInfo BattleRecoveryInfo { get; set; }
private static BattleRecoveryInfo _battleRecoveryInfoFallback;
public static BattleRecoveryInfo BattleRecoveryInfo
{
get => SVSim.BattleEngine.Ambient.BattleAmbient.Current?.RecoveryInfo ?? _battleRecoveryInfoFallback;
set
{
var c = SVSim.BattleEngine.Ambient.BattleAmbient.Current;
if (c != null) c.RecoveryInfo = value;
else _battleRecoveryInfoFallback = value;
}
}
public static VoteData VoteInfo { get; set; }

View File

@@ -25,7 +25,11 @@ public static class ToolboxGame
private static Transform _gameTransform = null;
public static RealTimeNetworkAgent RealTimeNetworkAgent { get; private set; }
private static RealTimeNetworkAgent _realTimeNetworkAgentFallback;
public static RealTimeNetworkAgent RealTimeNetworkAgent
{
get => SVSim.BattleEngine.Ambient.BattleAmbient.Current?.NetworkAgent ?? _realTimeNetworkAgentFallback;
}
public static Transform GameTransform
{
@@ -56,15 +60,20 @@ public static class ToolboxGame
public static void SetRealTimeNetworkBattle(RealTimeNetworkAgent agent)
{
RealTimeNetworkAgent = agent;
var c = SVSim.BattleEngine.Ambient.BattleAmbient.Current;
if (c != null) c.NetworkAgent = agent;
else _realTimeNetworkAgentFallback = agent;
}
public static void DestroyNetworkAgent()
{
if (RealTimeNetworkAgent != null)
var c = SVSim.BattleEngine.Ambient.BattleAmbient.Current;
var current = c?.NetworkAgent ?? _realTimeNetworkAgentFallback;
if (current != null)
{
Object.DestroyImmediate(RealTimeNetworkAgent.gameObject);
RealTimeNetworkAgent = null;
Object.DestroyImmediate(current.gameObject);
if (c != null) c.NetworkAgent = null;
else _realTimeNetworkAgentFallback = null;
}
}