Fixed UI extend button to actually move the stats box
Fixed DevDebugTools not accounting for map tile size (f Zeekers) Added more debugging text
This commit is contained in:
		
							parent
							
								
									a166b3d4a7
								
							
						
					
					
						commit
						ef4ce26491
					
				
					 10 changed files with 158 additions and 55 deletions
				
			
		|  | @ -25,7 +25,7 @@ namespace DunGenPlus.DevTools { | |||
|     public RuntimeDungeon dungeon; | ||||
|     public GameObject devCamera; | ||||
|     public BasePanel[] panels; | ||||
|     public RectTransform canvasRectTransform; | ||||
|     public LayoutElement canvasLayoutElement; | ||||
| 
 | ||||
|     public TMP_Dropdown dungeonFlowSelectionDropDown; | ||||
|     private ExtendedDungeonFlow[] dungeonFlows; | ||||
|  | @ -52,6 +52,7 @@ namespace DunGenPlus.DevTools { | |||
| 
 | ||||
|     // canvas | ||||
|     public bool canvasExtended; | ||||
|     private bool canvasExtendedInAnimation; | ||||
|     private float canvasWidthTarget; | ||||
| 
 | ||||
|     void Awake(){ | ||||
|  | @ -94,9 +95,16 @@ namespace DunGenPlus.DevTools { | |||
|     } | ||||
| 
 | ||||
|     void Update(){ | ||||
|       var sizeDelta = canvasRectTransform.sizeDelta; | ||||
|       sizeDelta.x = Mathf.Lerp(sizeDelta.x, canvasWidthTarget, Time.deltaTime * 10f); | ||||
|       canvasRectTransform.sizeDelta = sizeDelta; | ||||
|       if (canvasExtendedInAnimation){ | ||||
|         var currentWidth = canvasLayoutElement.preferredWidth; | ||||
|         if (Mathf.Abs(currentWidth - canvasWidthTarget) < 4f) { | ||||
|           canvasLayoutElement.preferredWidth = canvasWidthTarget; | ||||
|           canvasExtendedInAnimation = false; | ||||
|         } else { | ||||
|           canvasLayoutElement.preferredWidth = Mathf.Lerp(currentWidth, canvasWidthTarget, Time.deltaTime * 10f); | ||||
|         } | ||||
|       } | ||||
|        | ||||
| 
 | ||||
|       statusTextMesh.text = dungeon.Generator.Status.ToString(); | ||||
| 
 | ||||
|  | @ -125,6 +133,7 @@ namespace DunGenPlus.DevTools { | |||
|     } | ||||
| 
 | ||||
|     public void ToggleCanvasExtended(){ | ||||
|       canvasExtendedInAnimation = true; | ||||
|       canvasExtended = !canvasExtended; | ||||
|       canvasWidthTarget = canvasExtended ? 800f : 440f; | ||||
|     } | ||||
|  | @ -220,6 +229,17 @@ namespace DunGenPlus.DevTools { | |||
|       textList.AppendLine($"DoorwayPair Time: {DunGenPlusGenerator.DoorwayPairTime:F2} ms"); | ||||
|       textList.AppendLine($"CalculateWeight Time: {DunGenPlusGenerator.CalculateWeightTime:F2} ms"); | ||||
| 
 | ||||
|       /* | ||||
|       var errors = generator.tilePlacementResultCounters; | ||||
|       if (errors.Count > 0) { | ||||
|         textList.AppendLine(""); | ||||
|         textList.AppendLine("Reasons for faliure:"); | ||||
|         foreach(var pair in errors){ | ||||
|           textList.AppendLine($"{pair.Key} (x{pair.Value})"); | ||||
|         } | ||||
|       } | ||||
|       */ | ||||
| 
 | ||||
|       statsTextMesh.text = textList.ToString(); | ||||
|     } | ||||
| 
 | ||||
|  | @ -228,6 +248,7 @@ namespace DunGenPlus.DevTools { | |||
|     } | ||||
| 
 | ||||
|     private void UpdatePanels() { | ||||
|       MainPanel.Instance?.UpdatePanel(); | ||||
|       DunFlowPanel.Instance?.UpdatePanel(true); | ||||
|       DunGenPlusPanel.Instance?.UpdatePanel(true); | ||||
|       AssetsPanel.Instance?.UpdatePanel(true); | ||||
|  |  | |||
|  | @ -18,9 +18,13 @@ namespace DunGenPlus.DevTools.Panels { | |||
| 
 | ||||
|     internal IntInputField seedInputField; | ||||
|     internal TextUIElement lengthMultiplierField; | ||||
|     internal TextUIElement mapSizeMultiplierField; | ||||
|     internal TextUIElement factorySizeMultiplierField; | ||||
|     internal TextUIElement mapTileSizeField; | ||||
| 
 | ||||
|     internal ExtendedLevel[] levels; | ||||
|     internal IEnumerable<string> levelOptions; | ||||
|     private ExtendedLevel selectedLevel; | ||||
| 
 | ||||
|     private GameObject asyncParentGameobject; | ||||
| 
 | ||||
|  | @ -50,12 +54,20 @@ namespace DunGenPlus.DevTools.Panels { | |||
| 
 | ||||
|       manager.CreateHeaderUIField(parentTransform, "Levels"); | ||||
|       manager.CreateLevelOptionsUIField(parentTransform, "Level", 0, SetLevel); | ||||
|       lengthMultiplierField = manager.CreateTextUIField(parentTransform, ("Length Multiplier", "Dungeon size multiplier based on the level.")); | ||||
|       lengthMultiplierField = manager.CreateTextUIField(parentTransform, ("Length Multiplier", "Dungeon generation length multiplier based on the numerous factors.")); | ||||
|       mapSizeMultiplierField = manager.CreateTextUIField(parentTransform, ("Map Size Multiplier", "Map size multiplier based on the round manager (fixed).")); | ||||
|       factorySizeMultiplierField = manager.CreateTextUIField(parentTransform, ("Factory Size Multiplier", "Factory size multiplier based on the level.")); | ||||
|       mapTileSizeField = manager.CreateTextUIField(parentTransform, ("Map Tile Size", "Map tile size based on the dungeon.")); | ||||
| 
 | ||||
|       SetLevel(levels[0]); | ||||
| 
 | ||||
|       asyncParentGameobject.SetActive(gen.GenerateAsynchronously); | ||||
|     } | ||||
| 
 | ||||
|     public void UpdatePanel(){ | ||||
|       SetLevel(selectedLevel); | ||||
|     } | ||||
| 
 | ||||
|     public void SetSeed(int value) { | ||||
|       dungeon.Generator.Seed = value; | ||||
|     } | ||||
|  | @ -87,20 +99,38 @@ namespace DunGenPlus.DevTools.Panels { | |||
|     } | ||||
| 
 | ||||
|     public void SetLevel(ExtendedLevel level){ | ||||
|       var currentLevelLengthMultlpier = GetLevelMultiplier(level); | ||||
|       dungeon.Generator.LengthMultiplier = currentLevelLengthMultlpier; | ||||
|       var currentValues = GetLevelMultiplier(level); | ||||
|       dungeon.Generator.LengthMultiplier = currentValues.lengthMultiplier; | ||||
|       manager.UpdateDungeonBounds(); | ||||
|       lengthMultiplierField.SetText($"Length multiplier: {currentLevelLengthMultlpier.ToString("F2")}"); | ||||
| 
 | ||||
|       var lengthString = currentValues.lengthMultiplier.ToString("F2"); | ||||
|       var mapSizeString = currentValues.mapSizeMultiplier.ToString("F2"); | ||||
|       var factoryString = currentValues.factorySizeMultiplier.ToString("F2"); | ||||
|       var tileString = currentValues.mapTileSize.ToString("F2"); | ||||
| 
 | ||||
|       lengthMultiplierField.SetText($"Length multiplier: {lengthString} [{mapSizeString} / {tileString} * {factoryString}]"); | ||||
|       mapSizeMultiplierField.SetText($"Map size multiplier: {mapSizeString}"); | ||||
|       factorySizeMultiplierField.SetText($"Factory size multiplier: {factoryString}"); | ||||
|       mapTileSizeField.SetText($"Map tile size: {tileString}"); | ||||
| 
 | ||||
|       selectedLevel = level; | ||||
|     } | ||||
| 
 | ||||
|     private float GetLevelMultiplier(ExtendedLevel level){ | ||||
|     private (float lengthMultiplier, float mapSizeMultiplier, float factorySizeMultiplier, float mapTileSize) GetLevelMultiplier(ExtendedLevel level){ | ||||
|       var roundManager = RoundManager.Instance; | ||||
|       if (roundManager == null) { | ||||
|         Plugin.logger.LogError("RoundManager somehow null. Can't set level length multiplier"); | ||||
|         return 1f; | ||||
|       var mapSizeMultiplier = 1f; | ||||
|       if (roundManager != null) { | ||||
|         mapSizeMultiplier = roundManager.mapSizeMultiplier; | ||||
|       } else { | ||||
|         Plugin.logger.LogError("RoundManager somehow null."); | ||||
|       } | ||||
| 
 | ||||
|       return roundManager.mapSizeMultiplier * level.SelectableLevel.factorySizeMultiplier;  | ||||
|       var factorySizeMultiplier = level.SelectableLevel.factorySizeMultiplier; | ||||
|       var mapTileSize = selectedExtendedDungeonFlow.MapTileSize; | ||||
| 
 | ||||
|       var num2 = mapSizeMultiplier / mapTileSize * factorySizeMultiplier;  | ||||
|       num2 = (float)((double)Mathf.Round(num2 * 100f) / 100f); | ||||
|       return (num2, mapSizeMultiplier, factorySizeMultiplier, mapTileSize); | ||||
|     } | ||||
| 
 | ||||
|   } | ||||
|  |  | |||
|  | @ -150,6 +150,7 @@ | |||
|     <Compile Include="Components\Scrap\RandomGuaranteedScrapSpawn.cs" /> | ||||
|     <Compile Include="DevTools\Panels\AssetsPanel.cs" /> | ||||
|     <Compile Include="Generation\DunGenPlusGenerationPaths.cs" /> | ||||
|     <Compile Include="Generation\DunGenPlusGeneratorDebug.cs" /> | ||||
|     <Compile Include="Generation\DunGenPlusGeneratorGlobalProps.cs" /> | ||||
|     <Compile Include="MainPathExtender.cs" /> | ||||
|     <Compile Include="Managers\EnemyManager.cs" /> | ||||
|  |  | |||
										
											Binary file not shown.
										
									
								
							|  | @ -327,42 +327,6 @@ namespace DunGenPlus.Generation { | |||
|       AddForcedTiles(gen); | ||||
| 		} | ||||
| 
 | ||||
|     public static void PrintAddTileError(DungeonGenerator gen, TileProxy previousTile, DungeonArchetype archetype, IEnumerable<TileSet> useableTileSets, int branchId, int lineLength, float lineRatio){ | ||||
| 
 | ||||
|       var prevName = previousTile != null ? previousTile.Prefab.name : "NULL"; | ||||
|       var archetypeName = archetype ? archetype.name : "NULL"; | ||||
|       var tileSetNames = string.Join(", ", useableTileSets); | ||||
| 
 | ||||
|       var stringList = new List<string>();   | ||||
|       stringList.Add($"Main branch gen failed at Branch {branchId} (Length: {lineLength}, Ratio: {lineRatio})"); | ||||
|       stringList.Add($"Prev tile: {prevName}"); | ||||
|       stringList.Add($"Archetype: {archetypeName}"); | ||||
|       stringList.Add($"Tilesets: {tileSetNames}"); | ||||
|       stringList.Add($"Reason: {DungeonGeneratorPatch.lastTilePlacementResult}"); | ||||
| 
 | ||||
|       if (previousTile != null) { | ||||
|         var availableDoorways = string.Join(", ", previousTile.UnusedDoorways.Select(d => d.DoorwayComponent.gameObject.name)); | ||||
|         var usedDoorways = string.Join(", ", previousTile.UsedDoorways.Select(d => d.DoorwayComponent.gameObject.name)); | ||||
| 
 | ||||
|         stringList.Add($"Available Doorways: {availableDoorways}"); | ||||
|         stringList.Add($"Used Doorways: {usedDoorways}"); | ||||
| 
 | ||||
|         if (API.IsDevDebugModeActive()){ | ||||
|           var allTiles = GetDoorwayPairs(gen, previousTile, useableTileSets, archetype, lineRatio); | ||||
|           var uniqueTiles = string.Join(", ", allTiles.Select(t => t.NextTemplate.Prefab).Distinct().Select(d => d.name)); | ||||
| 
 | ||||
|           stringList.Add($"Next Possible Tiles: {uniqueTiles}"); | ||||
|         } | ||||
|       } | ||||
| 
 | ||||
|       stringList.Add(string.Empty); | ||||
|       Plugin.logger.LogDebug(string.Join("\n", stringList)); | ||||
|     } | ||||
| 
 | ||||
|     public static void PrintAddTileErrorQuick(DungeonGenerator gen, int lineLength){ | ||||
|       PrintAddTileError(gen, DungeonGeneratorPatch.lastAttachTo, DungeonGeneratorPatch.lastArchetype, DungeonGeneratorPatch.lastUseableTileSets, 0, lineLength, DungeonGeneratorPatch.lastNormalizedDepth); | ||||
|     } | ||||
| 
 | ||||
|     private static IEnumerator GenerateBranchPaths(DungeonGenerator gen, TileProxy mainRoom, string message, LogLevel logLevel){ | ||||
|       Plugin.logger.Log(logLevel, $"Switching to default dungeon branch generation: {message}"); | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										63
									
								
								DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorDebug.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorDebug.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,63 @@ | |||
| using DunGen.Graph; | ||||
| using DunGen; | ||||
| using HarmonyLib; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| using System.Collections; | ||||
| using UnityEngine; | ||||
| using DunGenPlus.Collections; | ||||
| using DunGenPlus.Components; | ||||
| using BepInEx.Logging; | ||||
| using DunGenPlus.DevTools; | ||||
| using DunGenPlus.Patches; | ||||
| 
 | ||||
| namespace DunGenPlus.Generation { | ||||
|   internal partial class DunGenPlusGenerator { | ||||
| 
 | ||||
|     public static void PrintAddTileError(DungeonGenerator gen, TileProxy previousTile, DungeonArchetype archetype, IEnumerable<TileSet> useableTileSets, int branchId, int lineLength, float lineRatio){ | ||||
| 
 | ||||
|       var prevName = previousTile != null ? previousTile.Prefab.name : "NULL"; | ||||
|       var archetypeName = archetype ? archetype.name : "NULL"; | ||||
|       var tileSetNames = string.Join(", ", useableTileSets); | ||||
| 
 | ||||
|       var stringList = new List<string>();   | ||||
|       stringList.Add($"Main branch gen failed at Branch {branchId} (Length: {lineLength}, Ratio: {lineRatio})"); | ||||
|       stringList.Add($"Prev tile: {prevName}"); | ||||
|       stringList.Add($"Archetype: {archetypeName}"); | ||||
|       stringList.Add($"Tilesets: {tileSetNames}"); | ||||
|       stringList.Add($"Reason: {lastTilePlacementResult}"); | ||||
| 
 | ||||
|       if (previousTile != null) { | ||||
|         var availableDoorways = string.Join(", ", previousTile.UnusedDoorways.Select(d => d.DoorwayComponent.gameObject.name)); | ||||
|         var usedDoorways = string.Join(", ", previousTile.UsedDoorways.Select(d => d.DoorwayComponent.gameObject.name)); | ||||
| 
 | ||||
|         stringList.Add($"Available Doorways: {availableDoorways}"); | ||||
|         stringList.Add($"Used Doorways: {usedDoorways}"); | ||||
| 
 | ||||
|         if (API.IsDevDebugModeActive()){ | ||||
|           var allTiles = GetDoorwayPairs(gen, previousTile, useableTileSets, archetype, lineRatio); | ||||
|           var uniqueTiles = string.Join(", ", allTiles.Select(t => t.NextTemplate.Prefab).Distinct().Select(d => d.name)); | ||||
| 
 | ||||
|           stringList.Add($"Next Possible Tiles: {uniqueTiles}"); | ||||
|         } | ||||
|       } | ||||
| 
 | ||||
|       stringList.Add(string.Empty); | ||||
|       Plugin.logger.LogDebug(string.Join("\n", stringList)); | ||||
|     } | ||||
| 
 | ||||
|     public static void PrintAddTileErrorQuick(DungeonGenerator gen, int lineLength){ | ||||
|       PrintAddTileError(gen, DungeonGeneratorPatch.lastAttachTo, DungeonGeneratorPatch.lastArchetype, DungeonGeneratorPatch.lastUseableTileSets, 0, lineLength, DungeonGeneratorPatch.lastNormalizedDepth); | ||||
|     } | ||||
| 
 | ||||
|     public static TilePlacementResult lastTilePlacementResult;  | ||||
| 
 | ||||
|     public static void RecordLastTilePlacementResult(DungeonGenerator gen, TilePlacementResult result){ | ||||
|       lastTilePlacementResult = result; | ||||
|     } | ||||
| 
 | ||||
|   } | ||||
| } | ||||
|  | @ -29,6 +29,9 @@ namespace DunGenPlus.Managers { | |||
|           d.Cleanup(); | ||||
|         } | ||||
| 
 | ||||
|         // we can leave early if doorway cleanup is not used (most likely for most dungeons anyway) | ||||
|         if (doorwayCleanupList.Count == 0) return; | ||||
| 
 | ||||
|         try{ | ||||
|           var dungeonGen = RoundManager.Instance.dungeonGenerator; | ||||
|           var navmesh = dungeonGen.transform.parent.GetComponentInChildren<UnityNavMeshAdapter>(); | ||||
|  |  | |||
|  | @ -336,11 +336,32 @@ namespace DunGenPlus.Patches { | |||
|       } | ||||
|     } | ||||
| 
 | ||||
|     public static TilePlacementResult lastTilePlacementResult; | ||||
|     [HarmonyPrefix] | ||||
|     [HarmonyPatch(typeof(DungeonGenerator), "AddTilePlacementResult")] | ||||
|     public static void AddTilePlacementResultPatch(TilePlacementResult result){ | ||||
|       lastTilePlacementResult = result; | ||||
|     [HarmonyTranspiler] | ||||
|     [HarmonyPatch(typeof(DungeonGenerator), "AddTile")] | ||||
|     public static IEnumerable<CodeInstruction> AddTileDebugPatch(IEnumerable<CodeInstruction> instructions){ | ||||
| 
 | ||||
|       var addTileSequence = new InstructionSequenceStandard("Add Tile Placement"); | ||||
|       addTileSequence.AddBasic(OpCodes.Callvirt); | ||||
|       addTileSequence.AddBasic(OpCodes.Ldc_I4_0); | ||||
|       addTileSequence.AddBasic(OpCodes.Bgt); | ||||
|       addTileSequence.AddBasicLocal(OpCodes.Ldloc_S, 9); | ||||
| 
 | ||||
|       foreach(var instruction in instructions){ | ||||
|         if (addTileSequence.VerifyStage(instruction)) { | ||||
|           var specialFunction = typeof(DunGenPlusGenerator).GetMethod("RecordLastTilePlacementResult", BindingFlags.Static | BindingFlags.Public); | ||||
| 
 | ||||
|           yield return new CodeInstruction(OpCodes.Ldarg_0); | ||||
|           yield return new CodeInstruction(OpCodes.Ldloc_S, 9); | ||||
|           yield return new CodeInstruction(OpCodes.Call, specialFunction); | ||||
| 
 | ||||
|           yield return instruction; | ||||
| 
 | ||||
|           continue; | ||||
|         } | ||||
|         yield return instruction; | ||||
|       } | ||||
| 
 | ||||
|       addTileSequence.ReportComplete(); | ||||
|     } | ||||
| 
 | ||||
|     [HarmonyTranspiler] | ||||
|  |  | |||
|  | @ -25,7 +25,7 @@ namespace DunGenPlus { | |||
| 
 | ||||
|     internal const string modGUID = "dev.ladyalice.dungenplus"; | ||||
|     private const string modName = "Dungeon Generation Plus"; | ||||
|     private const string modVersion = "1.3.0"; | ||||
|     private const string modVersion = "1.3.1"; | ||||
| 
 | ||||
|     internal readonly Harmony Harmony = new Harmony(modGUID); | ||||
| 
 | ||||
|  |  | |||
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue