Skip to content

Commit

Permalink
Improve character-related log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Nov 10, 2022
1 parent c80c112 commit dcb18bf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Shared.AIalike/Chara/CharacterApi.Hooks.AI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void InitHooks()

public static void ChaControl_InitializePostHook(ChaControl __instance)
{
KoikatuAPI.Logger.LogDebug($"Character card load: {GetLogName(__instance)} {(MakerAPI.CharaListIsLoading ? "inside CharaList" : string.Empty)}");
KoikatuAPI.Logger.LogDebug($"Character card load: {GetLogName(__instance?.chaFile)} {(MakerAPI.CharaListIsLoading ? "inside CharaList" : string.Empty)}");

ChaControls.Add(__instance);

Expand Down
2 changes: 1 addition & 1 deletion src/Shared.Core/Chara/CharaCustomFunctionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ internal void OnCardBeingSavedInternal(GameMode gamemode)
{
if (!_wasLoaded)
{
KoikatuAPI.Logger.LogWarning("Tried to save card before it was loaded - " + ChaFileControl.charaFileName);
KoikatuAPI.Logger.LogWarning("Tried to save card before it was loaded - " + ChaFileControl.GetFancyCharacterName());
return;
}

Expand Down
17 changes: 9 additions & 8 deletions src/Shared.Core/Chara/CharacterApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private static void CreateOrAddBehaviours(ChaControl target)
changed = currentCoordinate != controllerSubject.Value;
if (changed && KoikatuAPI.EnableDebugLogging)
KoikatuAPI.Logger.LogMessage(
$"Changed coord of character {target.fileParam.fullname} to {currentCoordinate}");
$"Changed coord of character {target.chaFile.GetFancyCharacterName()} to {currentCoordinate}");
}
if (changed) controllerSubject.OnNext(currentCoordinate);
Expand All @@ -271,7 +271,7 @@ private static void CreateOrAddBehaviours(ChaControl target)

private static void OnCardBeingSaved(ChaFile chaFile)
{
KoikatuAPI.Logger.LogDebug("Character save: " + chaFile.parameter.fullname);
KoikatuAPI.Logger.LogDebug("Character save: " + GetLogName(chaFile));

var gamemode = KoikatuAPI.GetCurrentGameMode();

Expand All @@ -285,8 +285,10 @@ private static void OnCardBeingSaved(ChaFile chaFile)
#endif

var chaControl = gamemode == GameMode.Maker ? MakerAPI.GetCharacterControl() : chaFile.GetChaControl();
MakerAPI.GetCharacterControl() :
ChaControls.FirstOrDefault(control => control.chaFile == chaFile);
if (chaControl == null)
{
KoikatuAPI.Logger.LogWarning("Could not find chaControl responsible for this chaFile! Triggering the save event on all chaControls!");
}

foreach (var behaviour in GetBehaviours(chaControl))
behaviour.OnCardBeingSavedInternal(gamemode);
Expand All @@ -304,7 +306,7 @@ private static void ReloadChara(ChaControl chaControl = null)
else
_currentlyReloading.Add(chaControl);

KoikatuAPI.Logger.LogDebug("Character load/reload: " + GetLogName(chaControl));
KoikatuAPI.Logger.LogDebug("Character load/reload: " + GetLogName(chaControl?.chaFile));

// Always send events to controllers before subscribers of CharacterReloaded
var gamemode = KoikatuAPI.GetCurrentGameMode();
Expand Down Expand Up @@ -394,10 +396,9 @@ private static void OnCoordinateBeingLoaded(ChaControl character, ChaFileCoordin
MakerAPI.OnReloadInterface(args);
}

private static string GetLogName(ChaInfo chaInfo)
private static string GetLogName(ChaFile chaFile)
{
if (chaInfo == null) return "NULL";
return chaInfo.chaFile?.charaFileName ?? chaInfo.fileParam?.fullname ?? "Unknown";
return chaFile == null ? "NULL / ALL CHARACTERS" : $"{chaFile.GetFancyCharacterName()} from {(string.IsNullOrEmpty(chaFile.charaFileName) ? "Unknown" : chaFile.charaFileName)}";
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Shared.Core/Chara/TestCharaCustomFunctionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override void OnReload(GameMode currentGameMode, bool maintainState)
if (id == null)
{
id = $"{No++} - {SceneApi.GetLoadSceneName()} - {SceneApi.GetAddSceneName()}";
Console.WriteLine($"New ID assigned - {id} | Chara - {ChaControl.name} | {ChaFileControl.parameter.fullname}");
Console.WriteLine($"New ID assigned - {id} | Chara - {ChaControl.name} | {ChaFileControl.GetFancyCharacterName()}");
SetParameterExtData(new PluginData() { data = new Dictionary<string, object> { { "id", id } } });
SetBodyExtData(new PluginData() { data = new Dictionary<string, object> { { "id", id } } });
SetFaceExtData(new PluginData() { data = new Dictionary<string, object> { { "id", id } } });
Expand Down
3 changes: 2 additions & 1 deletion src/Shared.KKalike/Chara/CharacterApi.Hooks.KK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using KKAPI.Utilities;

namespace KKAPI.Chara
{
Expand Down Expand Up @@ -50,7 +51,7 @@ public static void InitHooks()

public static void ChaControl_InitializePostHook(ChaControl __instance)
{
KoikatuAPI.Logger.LogDebug($"Character card load: {GetLogName(__instance)} {(MakerAPI.CharaListIsLoading ? "inside CharaList" : string.Empty)}");
KoikatuAPI.Logger.LogDebug($"Character card load: {GetLogName(__instance?.chaFile)} {(MakerAPI.CharaListIsLoading ? "inside CharaList" : string.Empty)}");

ChaControls.Add(__instance);

Expand Down

0 comments on commit dcb18bf

Please sign in to comment.