Skip to content

Commit

Permalink
Improve debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
drojf committed Oct 12, 2024
1 parent 11be9d4 commit a26d862
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
23 changes: 12 additions & 11 deletions Assets.Scripts.Core.AssetManagement/AssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down
54 changes: 33 additions & 21 deletions MOD.Debugging/MODDebugSpriteMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> JSONLoadStatuses = new List<string>();

private static string SpriteMappingLookupArguments = "No sprite looked up yet";
private static string SpriteMappingLookupStatus = "No sprite looked up yet";
private static Queue<string> SpriteMappingLookupDebug = new Queue<string>();

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");
}
}

/// <summary>
/// baseSpritePath is the path the sprite would be loaded from, if mapping was not performed
/// </summary>
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)
/// <summary>
/// baseSpritePath is the path the sprite would be loaded from, if mapping was not performed
/// </summary>
public static void RecordLookup(string baseSpritePath, string scriptNameNoExt, string maybeLastPlayedVoice, string sourcePath, string maybeMappedPath, string resultDescription)
{
SpriteMappingLookupStatus = $"{sourcePath}-><Failed>: {resultDescription}";
QueueSpriteLookupDebug($"{id++}: {baseSpritePath} - {scriptNameNoExt} - {maybeLastPlayedVoice ?? "[null]"} | [{sourcePath}] > [{maybeMappedPath ?? ("Failed")}]: {resultDescription}");
}

public static void RecordLastVoiceLoadedFromSaveFile(string lastVoiceFromSaveFile)
Expand Down

0 comments on commit a26d862

Please sign in to comment.