feat(battle-engine-port): M5 COMPLETE — summon_token spell resolves headless (board-count delta oracle)

Card 800134010 (clan-1 cost-1 ungated spell, summon_token=100011020): a when_play
summon places one new neutral 2/2 follower token on the caster board. New oracle
dimension = board-count + token-identity delta from a SKILL-CREATED card. 5/5 green;
engine 0 errors; check_drift clean; zero new Engine copies.

This is the first headless run of the PUBLIC prefab card-creation path
(CardCreatorBase.CreateCard, createNullView:false) — engine-internal card creation
(summon/draw/token) has no null-view path in solo mode, unlike the M2-M4 hand-card
seam. Built that path headless:
- Self-consistent no-op Unity object graph (UnityShim.cs): Component.gameObject/
  transform, GameObject.transform, Transform.parent/Find now lazily non-null +
  cached; GetComponent routed through the GameObject component model.
- Targeted NGUI material backing-field wiring (UIFont.mMat / UILabel.mMaterial) so
  the copied material getters return non-null via their simple branch (blanket/deep
  wiring would make them delegate down a re-nulling chain).
- getUIBase_CardManager() default! -> field-wired no-op via new ShimView.Create<T>().
- Test-side seeds: SBattleLoad card templates + 3D scene GameObjects (InitCardTemplates).

Load-bearing proof: swapping to the M3 non-summoning spell fails the board-count
(Expected 2, was 1) + token-not-found assertions; reverted to green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-06 03:19:12 -04:00
parent b13cfa0fad
commit 62a28fe2d4
4 changed files with 249 additions and 13 deletions

View File

@@ -299,7 +299,11 @@ public partial class UIManager
public List<UIBase_CardManager.CardObjData> getCardListObjs() => default!;
public List<UIBase_CardManager.CardObjData> getSelectCardListObjs() => default!;
public List<UIBase_CardManager.CardObjData> getCardList2DObjs() => default!;
public UIBase_CardManager getUIBase_CardManager() => default!;
// Shim fix (M5): return a non-null, field-wired no-op so the copied cosmetic helpers it
// exposes (UIBase_CardManager.SetNumberLabelStyle/SetNameLabelStyle, read by
// CardCreatorBase.CreateCard on the createNullView:false path) resolve headless instead of
// NRE-ing on a null manager. Was `default!`.
public UIBase_CardManager getUIBase_CardManager() => UnityEngine.ShimView.Create<UIBase_CardManager>();
public void setBackScene(GameObject obj, ViewScene backScene) { }
public TopBar CreateTopBar(GameObject obj, string titleMsg, ViewScene backScene = ViewScene.None, bool MoneyDraw = true, ChangeViewSceneParam Param = null, bool isWideMode = false) => default!;
public void SetBackButtonParameter(ChangeViewSceneParam in_Param) { }

View File

@@ -84,12 +84,19 @@ namespace UnityEngine
public class Component : Object
{
public Transform transform => null;
public GameObject gameObject => null;
internal GameObject _go;
// Self-consistent no-op object graph (M5): a Component belongs to a GameObject, and
// component.transform == component.gameObject.transform. Lazily materialize a backing
// GameObject so the unguarded prefab/view touches on the createNullView:false card-creation
// path (F1) resolve to non-null no-ops, and route GetComponent through that GameObject's
// cached component model so a chained transform.Find(...).GetComponent<T>() yields the same
// non-null instances rather than null.
public virtual GameObject gameObject => _go ??= new GameObject();
public virtual Transform transform => gameObject.transform;
public string tag { get; set; }
public T GetComponent<T>() => default;
public T GetComponent<T>(string type) => default;
public Component GetComponent(System.Type t) => null;
public T GetComponent<T>() => gameObject.GetComponent<T>();
public T GetComponent<T>(string type) => gameObject.GetComponent<T>();
public Component GetComponent(System.Type t) => gameObject.GetComponent(t);
public Component GetComponent(string t) => null;
public T GetComponentInChildren<T>() => default;
public T GetComponentInChildren<T>(bool includeInactive) => default;
@@ -129,6 +136,10 @@ namespace UnityEngine
public partial class Transform : Component, IEnumerable
{
public Transform() { }
internal Transform(GameObject owner) { _go = owner; }
// A Transform IS its own transform (vs Component.transform => gameObject.transform).
public override Transform transform => this;
public Vector3 position { get; set; }
public Vector3 localPosition { get; set; }
public Vector3 localScale { get; set; } = new Vector3(1, 1, 1);
@@ -136,9 +147,20 @@ namespace UnityEngine
public Vector3 eulerAngles { get; set; }
public Quaternion rotation { get; set; }
public Quaternion localRotation { get; set; }
public Transform parent { get; set; }
// Lazily non-null so `someLabel.transform.parent.gameObject` (unguarded in the NORMAL
// card-creation path) resolves; settable so real re-parenting still records.
private Transform _parent;
public Transform parent { get => _parent ??= new Transform(); set => _parent = value; }
public int childCount => 0;
public Transform Find(string n) => null;
// Return a non-null cached child per name so Find(...).Find(...).GetComponent<UILabel>()
// chains resolve to no-ops; cached so repeated Find of the same child is stable.
private System.Collections.Generic.Dictionary<string, Transform> _children;
public Transform Find(string n)
{
_children ??= new System.Collections.Generic.Dictionary<string, Transform>();
if (!_children.TryGetValue(n ?? "", out var t)) { t = new GameObject(n).transform; _children[n ?? ""] = t; }
return t;
}
public Transform GetChild(int i) => null;
public void SetParent(Transform p) { }
public void SetParent(Transform p, bool worldPositionStays) { }
@@ -169,7 +191,7 @@ namespace UnityEngine
public void LookAt(Vector3 p) { }
public void LookAt(Vector3 p, Vector3 worldUp) { }
public void DetachChildren() { }
public Transform Find(string n, bool includeInactive) => null;
public Transform Find(string n, bool includeInactive) => Find(n);
public IEnumerator GetEnumerator() { yield break; }
}
@@ -178,7 +200,8 @@ namespace UnityEngine
public GameObject() { }
public GameObject(string name) { this.name = name; }
public GameObject(string name, params Type[] components) { this.name = name; }
public Transform transform => null;
private Transform _transform;
public Transform transform => _transform ??= new Transform(this);
public GameObject gameObject => this;
public bool activeSelf => false;
public bool activeInHierarchy => false;
@@ -200,8 +223,50 @@ namespace UnityEngine
try { inst = Activator.CreateInstance(t); }
catch { return null; }
_components[t] = inst;
if (inst is Component comp) comp._go = this;
WireComponentFields(inst);
return inst;
}
// The createNullView:false card-creation path reads many view-leaf reference fields off a
// CardTemplate component (UILabel/MeshRenderer/Transform/GameObject) UNGUARDED, plus the
// copied NGUI cosmetic helpers (CardTemplate.SetNumberLabelStyle -> UIBase_CardManager ->
// UIFont.material / UILabel.material) read material backing fields. The real engine wires all
// of this from the prefab in SBattleLoad.CreateUnitCardTemplate, which we skip headless. Fill
// any null GameObject/Component-derived view field with a no-op instance. Pure no-ops:
// nothing here computes game state (the token's authoritative stats come from CardCSVData).
internal const System.Reflection.BindingFlags WireFlags =
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance;
private static readonly Material _noopViewMaterial = new Material { name = "ShimNoOpMaterial" };
// Create a no-op view-leaf instance and pre-set the NGUI material backing fields the copied
// UIFont.material / UILabel.material getters read so they return non-null. Only mMat/mMaterial
// are filled: blanket-filling mReplacement/mAtlas/mDynamicFont would make those getters
// DELEGATE down a chain that re-nulls. One level deep — no recursion into the created leaf.
private static object Materialize(Type t)
{
var o = Activator.CreateInstance(t);
SetBackingMaterial(o, "mMat"); // UIFont
SetBackingMaterial(o, "mMaterial"); // UILabel / UIWidget
return o;
}
private static void SetBackingMaterial(object o, string field)
{
var f = o.GetType().GetField(field, WireFlags);
if (f != null && f.FieldType == typeof(Material) && f.GetValue(o) == null)
f.SetValue(o, _noopViewMaterial);
}
internal static void WireComponentFields(object inst)
{
foreach (var f in inst.GetType().GetFields(WireFlags))
{
if (f.GetValue(inst) != null) continue;
var ft = f.FieldType;
if (ft == typeof(GameObject) || (typeof(Component).IsAssignableFrom(ft) && !ft.IsAbstract))
{ try { f.SetValue(inst, Materialize(ft)); } catch { } }
else if (ft == typeof(Material))
{ f.SetValue(inst, _noopViewMaterial); }
}
}
public T GetComponent<T>() => (T)(GetOrAddComponent(typeof(T)) ?? default(T));
public Component GetComponent(Type t) => (Component)GetOrAddComponent(t);
public Component GetComponent(string t) => null;
@@ -230,6 +295,19 @@ namespace UnityEngine
public class ScriptableObject : Object { }
// Factory for no-op view/manager objects that are NOT acquired via GameObject.GetComponent (e.g.
// UIManager.getUIBase_CardManager()). Creates the instance and runs the same field-wiring the
// component model applies, so the copied cosmetic helpers it exposes resolve headless.
public static class ShimView
{
public static T Create<T>() where T : class
{
var o = System.Activator.CreateInstance(typeof(T));
GameObject.WireComponentFields(o);
return (T)o;
}
}
// ---- rendering / physics / audio (pure no-op presentation) ----
public class Renderer : Component
{