using System; using System.Linq; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; using DepthsOfGreed.HandbookUI; [InitializeOnLoad] public static class SupplyBindingValidation { static SupplyBindingValidation(){if(SessionState.GetBool("SupplyBindingTest",false))EditorApplication.playModeStateChanged+=Ready;} public static void Validate(){EditorSceneManager.OpenScene("Assets/Scenes/Tim_Test_UI.unity");SessionState.SetBool("SupplyBindingTest",true);EditorApplication.playModeStateChanged+=Ready;EditorApplication.EnterPlaymode();} static void Check(bool value,string message){if(!value)throw new Exception(message);} static void Ready(PlayModeStateChange change) { if(change!=PlayModeStateChange.EnteredPlayMode)return;SessionState.SetBool("SupplyBindingTest",false);EditorApplication.playModeStateChanged-=Ready; double due=EditorApplication.timeSinceStartup+1;int stage=0;SupplyBasementController c=null;SupplyContractTestBackend fake=null; EditorApplication.CallbackFunction run=null;run=()=> { if(EditorApplication.timeSinceStartup();fake=new GameObject("TEST_ONLY_SupplyAdapter").AddComponent(); var catalog=AssetDatabase.LoadAssetAtPath("Assets/HandbookData/TestTurmkatalog.asset"); Check(catalog.towers.Count(t=>t.supply.kind!=SupplyKind.None)==12,"Twelve supplied weapons"); fake.state.towers=new[]{new TowerSupplyState{instanceId=987,type=catalog.towers.First(t=>t.id=="ammo_0"),magazine=17,magazineCapacity=40}}; fake.state.channels=new[]{new SupplyChannelState{kind=SupplyKind.Physical,storage=180,storageCapacity=300,buffer=23,bufferCapacity=50}}; fake.state.truck=new SupplyTruckState{phase=SupplyTruckPhase.Driving,from=SupplyStop.PhysicalTank,to=SupplyStop.Distributor,progress=.5f,cargoKind=SupplyKind.Physical,cargo=20,cargoCapacity=40}; c.BindSupplyBackend(fake);c.UseLift();stage=1;due=EditorApplication.timeSinceStartup+1.7; } else { Check(c.IsInBasement && c.HasSupplyBackend,"Adapter attached"); Check(c.connectionNames[0].text.Contains("987"),"Backend tower IDs, independent of prototype placement"); Check(c.storageAmounts[0].text=="180 / 300" && c.bufferAmounts[0].text=="23 / 50","Channel snapshots rendered"); Check(c.magazineAmounts[0].gameObject.activeSelf && c.magazineAmounts[0].text.Contains("17 / 40"),"Live magazine rendered"); Check(Mathf.Abs(c.truck.anchoredPosition.x-Mathf.Lerp(c.loadingPositions[0],c.unloadingPosition,.5f))<.1f,"Backend drives truck; preview suppressed"); c.ToggleConnection(0);Check(!fake.state.towers[0].connected && !c.IsConnectionEnabled(987),"Connection command accepted"); fake.reject=true;c.ToggleConnection(0);Check(!c.IsConnectionEnabled(987),"Rejected command does not change connection"); fake.reject=false;c.SetPriority(1);Check(fake.state.priority==SupplyKind.EnergyCells && c.Priority==1,"Priority command accepted"); fake.reject=true;c.SetPriority(2);Check(c.Priority==1,"Rejected priority remains authoritative"); fake.state.towers=Array.Empty();c.SendMessage("RefreshConnections");Check(!c.connectionButtons[0].interactable,"Removed tower frees slot"); Debug.Log("SUPPLY_BINDING_VALIDATION_OK: fields, live amounts, external tower IDs, commands, rejection, truck route and removal.");EditorApplication.update-=run;EditorApplication.Exit(0); } } catch(Exception e){EditorApplication.update-=run;Debug.LogException(e);EditorApplication.Exit(1);} };EditorApplication.update+=run; } }