diff --git a/DunGenPlus/DunGenPlus/DevTools/DevDebugManager.cs b/DunGenPlus/DunGenPlus/DevTools/DevDebugManager.cs index 8e5ddc3..0c2e466 100644 --- a/DunGenPlus/DunGenPlus/DevTools/DevDebugManager.cs +++ b/DunGenPlus/DunGenPlus/DevTools/DevDebugManager.cs @@ -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); diff --git a/DunGenPlus/DunGenPlus/DevTools/Panels/MainPanel.cs b/DunGenPlus/DunGenPlus/DevTools/Panels/MainPanel.cs index 0457327..465fad5 100644 --- a/DunGenPlus/DunGenPlus/DevTools/Panels/MainPanel.cs +++ b/DunGenPlus/DunGenPlus/DevTools/Panels/MainPanel.cs @@ -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 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); } } diff --git a/DunGenPlus/DunGenPlus/DunGenPlus.csproj b/DunGenPlus/DunGenPlus/DunGenPlus.csproj index 0c5c6e0..e7a3602 100644 --- a/DunGenPlus/DunGenPlus/DunGenPlus.csproj +++ b/DunGenPlus/DunGenPlus/DunGenPlus.csproj @@ -150,6 +150,7 @@ + diff --git a/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll b/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll index 2de848f..ff63d48 100644 Binary files a/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll and b/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll differ diff --git a/DunGenPlus/DunGenPlus/Generation/DunGenPlusGenerator.cs b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGenerator.cs index 7808781..42cf5d7 100644 --- a/DunGenPlus/DunGenPlus/Generation/DunGenPlusGenerator.cs +++ b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGenerator.cs @@ -327,42 +327,6 @@ namespace DunGenPlus.Generation { AddForcedTiles(gen); } - public static void PrintAddTileError(DungeonGenerator gen, TileProxy previousTile, DungeonArchetype archetype, IEnumerable 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(); - 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}"); diff --git a/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorDebug.cs b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorDebug.cs new file mode 100644 index 0000000..17a6498 --- /dev/null +++ b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorDebug.cs @@ -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 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(); + 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; + } + + } +} diff --git a/DunGenPlus/DunGenPlus/Managers/DoorwayManager.cs b/DunGenPlus/DunGenPlus/Managers/DoorwayManager.cs index 6670389..dd1c3e9 100644 --- a/DunGenPlus/DunGenPlus/Managers/DoorwayManager.cs +++ b/DunGenPlus/DunGenPlus/Managers/DoorwayManager.cs @@ -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(); diff --git a/DunGenPlus/DunGenPlus/Patches/DungeonGeneratorPatch.cs b/DunGenPlus/DunGenPlus/Patches/DungeonGeneratorPatch.cs index e4828f3..cbaa900 100644 --- a/DunGenPlus/DunGenPlus/Patches/DungeonGeneratorPatch.cs +++ b/DunGenPlus/DunGenPlus/Patches/DungeonGeneratorPatch.cs @@ -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 AddTileDebugPatch(IEnumerable 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] diff --git a/DunGenPlus/DunGenPlus/Plugin.cs b/DunGenPlus/DunGenPlus/Plugin.cs index 741183e..afa36bd 100644 --- a/DunGenPlus/DunGenPlus/Plugin.cs +++ b/DunGenPlus/DunGenPlus/Plugin.cs @@ -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); diff --git a/DunGenPlus/DunGenPlus/dungen b/DunGenPlus/DunGenPlus/dungen index d5e1c2b..cb73817 100644 Binary files a/DunGenPlus/DunGenPlus/dungen and b/DunGenPlus/DunGenPlus/dungen differ