Skip to content

Commit

Permalink
Move sprite mapping debugging to separate class and display on Mod UI…
Browse files Browse the repository at this point in the history
… rather than in logs
  • Loading branch information
drojf committed Oct 12, 2024
1 parent 02860f7 commit b8fa76d
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 10 deletions.
1 change: 1 addition & 0 deletions Assembly-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Reference Include="Antlr3.Runtime">
<HintPath>DLLs\Antlr3.Runtime.dll</HintPath>
</Reference>
<Compile Include="MOD.Debugging\MODDebugSpriteMapping.cs" />
<Compile Include="MOD.Scripts.Core\MODUnityLoggerShim.cs" />
<Compile Include="MOD.Scripts.Core\MODXMLWrapper.cs" />
<Compile Include="MOD.Scripts.AssetManager\MODAssetManager.cs" />
Expand Down
29 changes: 19 additions & 10 deletions Assets.Scripts.Core.AssetManagement/AssetManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Assets.Scripts.Core.Audio;
using Assets.Scripts.Core.Buriko;
using BGICompiler.Compiler;
using MOD.Debugging;
using MOD.ImageMapping;
using MOD.Scripts.Core.Audio;
using System;
Expand Down Expand Up @@ -82,14 +83,17 @@ private static bool LoadMappingFromJSON(string mappingFolderPath, out MODImageMa
if (AssetManager.Instance.CheckStreamingAssetsPathExistsInner(mappingFolderPath, "mapping.json", out mappingPath))
{
mapping = MODImageMapping.GetVoiceBasedMapping(mappingPath);
// TODO: remove this once checked its working
Debug.Log($"Successfully loaded mapping from {mappingPath} JSON file");
MODDebugSpriteMapping.RecordJSONLoadStatus(mappingPath, "Load OK");
return true;
}
else
{
MODDebugSpriteMapping.RecordJSONLoadStatus(mappingPath, "Not Found");
}
}
catch (Exception e)
{
Debug.Log($"Failed to load mapping from {mappingPath} JSON file:\n{e}");
MODDebugSpriteMapping.RecordJSONLoadStatus(mappingPath, $"Exception: {e.Message}");
}

mapping = null;
Expand Down Expand Up @@ -313,26 +317,31 @@ private string PathToAssetWithName(string pathNoExt, string extension, PathCasca
continue;
}

// TODO: need to make sure "lastVoice" is correctly set, even after loading a save
// e.g. need to save the last played voice to the save file!

// Check if the artset has an ImageMapping, if so, map the input asset
// before looking for the file on disk
string subFolder = cascadePath.folderPath;
string scriptNameNoExt = Path.GetFileNameWithoutExtension(BurikoScriptSystem.Instance.GetCurrentScript().Filename);
string lastPlayedVoice = lastVoiceFromMODPlayVoiceLSNoExt;

// TODO: remove debug print
Debug.Log($"Looking up {cascadePath.folderPath} - {scriptNameNoExt} - {lastPlayedVoice ?? "[null]"} - {pathNoExt}");
MODDebugSpriteMapping.RecordSpriteMappingLookupArguments(cascadePath.folderPath, scriptNameNoExt, lastPlayedVoice, pathNoExt);
if (cascadePath.GetImageMapping(out MODImageMapping mapping))
{
if(mapping.GetOGImage(scriptNameNoExt, lastPlayedVoice, pathNoExt, out string mappedPath, out string debugInfo))
{
// TODO: remove debug print
Debug.Log($"Successfully got mapping {pathNoExt}->{mappedPath} from mapping - Source: {debugInfo}");
// Mapped file OK, so use the mapped folder and mapped path for this asset
subFolder = cascadePath.mappingFolderPath;
pathWithExt = mappedPath + extension;

MODDebugSpriteMapping.RecordSuccessfulLookupResult(pathNoExt, mappedPath, debugInfo);
}
else
{
MODDebugSpriteMapping.RecordFailedLookupResult(pathNoExt, $"GetOGImage failed: {debugInfo}");
}
}
else
{
MODDebugSpriteMapping.RecordFailedLookupResult(pathNoExt, $"No Mapping for {cascadePath.folderPath}");
}

if (CheckStreamingAssetsPathExists(subFolder, pathWithExt, out string filePath))
Expand Down
67 changes: 67 additions & 0 deletions MOD.Debugging/MODDebugSpriteMapping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Assets.Scripts.Core;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using static MOD.Scripts.UI.MODMenuCommon;
using Assets.Scripts.Core.AssetManagement;

namespace MOD.Debugging
{
internal class MODDebugSpriteMapping
{
private static string LastVoiceLoadedFromSaveFile = "Load Not Performed Yet";

private static string JSONLoadStatus = "";

private static string SpriteMappingLookupArguments = "No sprite looked up yet";
private static string SpriteMappingLookupStatus = "No sprite looked up yet";

public static void OnGUISpriteMapping()
{
// TODO: add button to enable debugging?

Label("---- Sprite Mapping ----");
Label($"JSON: {JSONLoadStatus}");

Label("-- Last Voice --");
Label($"Last Voice (Runtime): {AssetManager.Instance.lastVoiceFromMODPlayVoiceLSNoExt}");
Label($"Last Voice Loaded From Save File: {LastVoiceLoadedFromSaveFile}");

Label("-- Mapped Sprite Status --");
Label($"Args: {SpriteMappingLookupArguments}");
Label($"Status: {SpriteMappingLookupStatus}");
}

public static void RecordJSONLoadStatus(string mappingPath, string mappingStatus)
{
if(JSONLoadStatus.Length < 100)
{
JSONLoadStatus += $"{mappingPath}:{mappingStatus}";
}
}

/// <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)
{
SpriteMappingLookupArguments = $"{baseSpritePath} - {scriptNameNoExt} - {maybeLastPlayedVoice ?? "[null]"} - {spritePathNoExt}";
}

public static void RecordSuccessfulLookupResult(string sourcePath, string mappedPath, string resultDescription)
{
SpriteMappingLookupStatus = $"{sourcePath}->{mappedPath}: {resultDescription}";
}

public static void RecordFailedLookupResult(string sourcePath, string resultDescription)
{
SpriteMappingLookupStatus = $"{sourcePath}-><Failed>: {resultDescription}";
}

public static void RecordLastVoiceLoadedFromSaveFile(string lastVoiceFromSaveFile)
{
LastVoiceLoadedFromSaveFile = lastVoiceFromSaveFile;
}
}
}
2 changes: 2 additions & 0 deletions MOD.ImageMapping/MODImageMappingSaveData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Assets.Scripts.Core.AssetManagement;
using MOD.Debugging;
using System;
using System.Collections.Generic;
using System.Text;
Expand All @@ -25,6 +26,7 @@ public static MODImageMappingSaveData GetDataToSave(AssetManager assetManager)
public static void LoadSavedData(MODImageMappingSaveData modImageMappingSaveData, AssetManager assetManager)
{
assetManager.lastVoiceFromMODPlayVoiceLSNoExt = modImageMappingSaveData.LastVoiceFromMODPlayVoiceLSNoExt;
MODDebugSpriteMapping.RecordLastVoiceLoadedFromSaveFile(modImageMappingSaveData.LastVoiceFromMODPlayVoiceLSNoExt);
}
}
}
4 changes: 4 additions & 0 deletions MOD.Scripts.UI/MODMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Assets.Scripts.Core.Audio;
using Assets.Scripts.Core.Buriko;
using Assets.Scripts.Core.State;
using MOD.Debugging;
using MOD.Scripts.Core;
using MOD.Scripts.Core.Audio;
using MOD.Scripts.Core.Localization;
Expand Down Expand Up @@ -144,6 +145,9 @@ private void OnGUIDebugWindow(int windowID)
// Font Adjustment Debug Menu
fontMenuFragment.OnGUIFontDebug();

// Sprite Mapping Debug Menu
MODDebugSpriteMapping.OnGUISpriteMapping();

// Button to close the debug menu
if (Button(new GUIContent(Loc.MODMenu_4, Loc.MODMenu_5))) //Close | Close the debug menu
{
Expand Down

0 comments on commit b8fa76d

Please sign in to comment.