From a26d862a3ba35b25ebbd301def9e5e125cc7f272 Mon Sep 17 00:00:00 2001 From: drojf <1249449+drojf@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:08:33 +1100 Subject: [PATCH] Improve debug output --- .../AssetManager.cs | 23 ++++---- MOD.Debugging/MODDebugSpriteMapping.cs | 54 +++++++++++-------- 2 files changed, 45 insertions(+), 32 deletions(-) diff --git a/Assets.Scripts.Core.AssetManagement/AssetManager.cs b/Assets.Scripts.Core.AssetManagement/AssetManager.cs index 6c2ef07..d45493c 100644 --- a/Assets.Scripts.Core.AssetManagement/AssetManager.cs +++ b/Assets.Scripts.Core.AssetManagement/AssetManager.cs @@ -75,25 +75,22 @@ public bool GetImageMapping(out MODImageMapping retMapping) private static bool LoadMappingFromJSON(string mappingFolderPath, out MODImageMapping mapping) { + const string mappingFile = "mapping.json"; string mappingPath = ""; try { Debug.Log($"Checking for mapping.json inside {mappingFolderPath} folder..."); - if (AssetManager.Instance.CheckStreamingAssetsPathExistsInner(mappingFolderPath, "mapping.json", out mappingPath)) + if (AssetManager.Instance.CheckStreamingAssetsPathExistsInner(mappingFolderPath, mappingFile, out mappingPath)) { mapping = MODImageMapping.GetVoiceBasedMapping(mappingPath); - MODDebugSpriteMapping.RecordJSONLoadStatus(mappingPath, "Load OK"); + MODDebugSpriteMapping.RecordJSONLoadStatus(mappingFolderPath, mappingFile, "Load OK"); return true; } - else - { - MODDebugSpriteMapping.RecordJSONLoadStatus(mappingPath, "Not Found"); - } } catch (Exception e) { - MODDebugSpriteMapping.RecordJSONLoadStatus(mappingPath, $"Exception: {e.Message}"); + MODDebugSpriteMapping.RecordJSONLoadStatus(mappingFolderPath, mappingFile, $"Exception: {e.Message}"); } mapping = null; @@ -323,7 +320,8 @@ private string PathToAssetWithName(string pathNoExt, string extension, PathCasca string scriptNameNoExt = Path.GetFileNameWithoutExtension(BurikoScriptSystem.Instance.GetCurrentScript().Filename); string lastPlayedVoice = lastVoiceFromMODPlayVoiceLSNoExt; - MODDebugSpriteMapping.RecordSpriteMappingLookupArguments(cascadePath.folderPath, scriptNameNoExt, lastPlayedVoice, pathNoExt); + string debugMaybeMappedPath = null; + string debugMappedDescription; if (cascadePath.GetImageMapping(out MODImageMapping mapping)) { if(mapping.GetOGImage(scriptNameNoExt, lastPlayedVoice, pathNoExt, out string mappedPath, out string debugInfo)) @@ -332,18 +330,21 @@ private string PathToAssetWithName(string pathNoExt, string extension, PathCasca subFolder = cascadePath.mappingFolderPath; pathWithExt = mappedPath + extension; - MODDebugSpriteMapping.RecordSuccessfulLookupResult(pathNoExt, mappedPath, debugInfo); + debugMappedDescription = debugInfo; + debugMaybeMappedPath = pathWithExt; } else { - MODDebugSpriteMapping.RecordFailedLookupResult(pathNoExt, $"GetOGImage failed: {debugInfo}"); + debugMappedDescription = $"GetOGImage: {debugInfo}"; } } else { - MODDebugSpriteMapping.RecordFailedLookupResult(pathNoExt, $"No Mapping for {cascadePath.folderPath}"); + debugMappedDescription = $"No Mapping for folder [{cascadePath.folderPath}]"; } + MODDebugSpriteMapping.RecordLookup(cascadePath.folderPath, scriptNameNoExt, lastPlayedVoice, pathNoExt, debugMaybeMappedPath, debugMappedDescription); + if (CheckStreamingAssetsPathExists(subFolder, pathWithExt, out string filePath)) { // Asset was successfully - now report the subfolder where the asset was found diff --git a/MOD.Debugging/MODDebugSpriteMapping.cs b/MOD.Debugging/MODDebugSpriteMapping.cs index 67372ad..c80e45e 100644 --- a/MOD.Debugging/MODDebugSpriteMapping.cs +++ b/MOD.Debugging/MODDebugSpriteMapping.cs @@ -5,58 +5,70 @@ using UnityEngine; using static MOD.Scripts.UI.MODMenuCommon; using Assets.Scripts.Core.AssetManagement; +using MOD.Scripts.UI; +using System.Linq; namespace MOD.Debugging { internal class MODDebugSpriteMapping { + private static int id = 0; + private static string LastVoiceLoadedFromSaveFile = "Load Not Performed Yet"; - private static string JSONLoadStatus = ""; + private static List JSONLoadStatuses = new List(); - private static string SpriteMappingLookupArguments = "No sprite looked up yet"; - private static string SpriteMappingLookupStatus = "No sprite looked up yet"; + private static Queue SpriteMappingLookupDebug = new Queue(); public static void OnGUISpriteMapping() { // TODO: add button to enable debugging? Label("---- Sprite Mapping ----"); - Label($"JSON: {JSONLoadStatus}"); + foreach(string s in JSONLoadStatuses) + { + Label(s); + } Label("-- Last Voice --"); - Label($"Last Voice (Runtime): {AssetManager.Instance.lastVoiceFromMODPlayVoiceLSNoExt}"); + Label($"Last Voice (Runtime): {AssetManager.Instance.lastVoiceFromMODPlayVoiceLSNoExt ?? "[null]"}"); Label($"Last Voice Loaded From Save File: {LastVoiceLoadedFromSaveFile}"); Label("-- Mapped Sprite Status --"); - Label($"Args: {SpriteMappingLookupArguments}"); - Label($"Status: {SpriteMappingLookupStatus}"); + foreach(string s in SpriteMappingLookupDebug.Reverse().ToList()) + { + Label(s); + } } - public static void RecordJSONLoadStatus(string mappingPath, string mappingStatus) + public static void RecordJSONLoadStatus(string mappingPath, string mappingFile, string mappingStatus) { - if(JSONLoadStatus.Length < 100) + if(JSONLoadStatuses.Count < 10) { - JSONLoadStatus += $"{mappingPath}:{mappingStatus}"; + JSONLoadStatuses.Add($"StreamingAssets/{mappingPath}/{mappingFile}: {mappingStatus}"); + } + else + { + MODToaster.Show("MODDebugSpriteMapping: Too many Sprite Mapping JSON Statuses - not showing any more"); } } - /// - /// baseSpritePath is the path the sprite would be loaded from, if mapping was not performed - /// - public static void RecordSpriteMappingLookupArguments(string baseSpritePath, string scriptNameNoExt, string maybeLastPlayedVoice, string spritePathNoExt) + private static void QueueSpriteLookupDebug(string s) { - SpriteMappingLookupArguments = $"{baseSpritePath} - {scriptNameNoExt} - {maybeLastPlayedVoice ?? "[null]"} - {spritePathNoExt}"; - } + if(SpriteMappingLookupDebug.Count > 10) + { + SpriteMappingLookupDebug.Dequeue(); + } - public static void RecordSuccessfulLookupResult(string sourcePath, string mappedPath, string resultDescription) - { - SpriteMappingLookupStatus = $"{sourcePath}->{mappedPath}: {resultDescription}"; + SpriteMappingLookupDebug.Enqueue(s); } - public static void RecordFailedLookupResult(string sourcePath, string resultDescription) + /// + /// baseSpritePath is the path the sprite would be loaded from, if mapping was not performed + /// + public static void RecordLookup(string baseSpritePath, string scriptNameNoExt, string maybeLastPlayedVoice, string sourcePath, string maybeMappedPath, string resultDescription) { - SpriteMappingLookupStatus = $"{sourcePath}->: {resultDescription}"; + QueueSpriteLookupDebug($"{id++}: {baseSpritePath} - {scriptNameNoExt} - {maybeLastPlayedVoice ?? "[null]"} | [{sourcePath}] > [{maybeMappedPath ?? ("Failed")}]: {resultDescription}"); } public static void RecordLastVoiceLoadedFromSaveFile(string lastVoiceFromSaveFile)