Skip to content

Commit

Permalink
Hide janitor button on versions of KK where janitor doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
DeathWeasel1337 committed Jan 6, 2020
1 parent 2b35153 commit 02958df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/Shared/CharacterReplacer.Hooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ internal static bool LoadFromAssetBundle(ChaFileControl __instance, string asset
__instance.LoadCharaFile(CardPathDefaultM.Value);
return false;
}
#if !EC
else if (assetName == AssetOther)
else if (assetName == AssetOther && CardPathOther != null)
{
if (!VerifyCard(ReplacementCardType.Other)) return true;
Logger.LogDebug($"Replacing {CardNameOther} with card: {CardPathOther.Value}");
__instance.LoadCharaFile(CardPathOther.Value);
return false;
}
#endif

return true;
}
Expand Down
30 changes: 20 additions & 10 deletions src/Shared/CharacterReplacer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using KKAPI.Utilities;
using Shared;
using System;
Expand All @@ -16,7 +17,7 @@ public partial class CharacterReplacer
{
public const string GUID = "IllusionMods.CharacterReplacer";
public const string PluginName = "Character Replacer";
public const string Version = "1.6.1";
public const string Version = "1.6.2";
internal static new ManualLogSource Logger;

public const string FileExtension = ".png";
Expand All @@ -29,9 +30,7 @@ public partial class CharacterReplacer
public static ConfigEntry<bool> Enabled { get; private set; }
public static ConfigEntry<string> CardPathDefaultF { get; private set; }
public static ConfigEntry<string> CardPathDefaultM { get; private set; }
#if !EC
public static ConfigEntry<string> CardPathOther { get; private set; }
#endif

internal void Awake()
{
Expand All @@ -42,7 +41,22 @@ internal void Awake()
CardPathDefaultF = Config.Bind("Config", $"{CardNameDefaultF} Card Path", "", new ConfigDescription("Path of the replacement card on disk.", null, new ConfigurationManagerAttributes { Order = 8 }));
Config.Bind("Config", $"{CardNameDefaultM} Card Replacement", "", new ConfigDescription("Browse for a card.", null, new ConfigurationManagerAttributes { Order = 7, HideDefaultButton = true, CustomDrawer = new Action<ConfigEntryBase>(CardButtonDrawer) }));
CardPathDefaultM = Config.Bind("Config", $"{CardNameDefaultM} Card Path", "", new ConfigDescription("Path of the replacement card on disk.", null, new ConfigurationManagerAttributes { Order = 6 }));
#if !EC

AddOtherConfig();
}

/// <summary>
/// Only show the janitor/merchant stuff in games where it exists and in versions of KK where it exists
/// </summary>
private void AddOtherConfig()
{
#if EC
//EC has no Merchant or Janitor
#else
#if KK
//KK Party and KK without Darkness don't have Janitor
if (typeof(ChaControl).GetProperty("exType", AccessTools.all) == null) return;
#endif
Config.Bind("Config", $"{CardNameOther} Card Replacement", "", new ConfigDescription("Browse for a card.", null, new ConfigurationManagerAttributes { Order = 5, HideDefaultButton = true, CustomDrawer = new Action<ConfigEntryBase>(CardButtonDrawer) }));
CardPathOther = Config.Bind("Config", $"{CardNameOther} Card Path", "", new ConfigDescription("Path of the replacement card on disk.", null, new ConfigurationManagerAttributes { Order = 4 }));
#endif
Expand Down Expand Up @@ -74,10 +88,8 @@ private void OnCardAccept(string key, string[] path)
CardPathDefaultF.Value = path[0];
else if (key.StartsWith(CardNameDefaultM))
CardPathDefaultM.Value = path[0];
#if !EC
else if (key.StartsWith(CardNameOther))
else if (key.StartsWith(CardNameOther) && CardPathOther != null)
CardPathOther.Value = path[0];
#endif
break;
case CardType.None:
Logger.LogMessage("Error! Not a card.");
Expand All @@ -104,13 +116,11 @@ internal static bool VerifyCard(ReplacementCardType replacementCardType)
configEntry = CardPathDefaultF;
else if (replacementCardType == ReplacementCardType.DefaultMale)
configEntry = CardPathDefaultM;
#if !EC
else if (replacementCardType == ReplacementCardType.Other)
else if (replacementCardType == ReplacementCardType.Other && CardPathOther != null)
{
configEntry = CardPathOther;
text = $" {CardNameOther}";
}
#endif
else return false;

if (configEntry.Value.IsNullOrEmpty()) return false;
Expand Down

0 comments on commit 02958df

Please sign in to comment.