Skip to content

Commit

Permalink
fix terminal bug, allow OTF fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
katycat5e committed Aug 22, 2023
1 parent a9b53d2 commit b794b2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
14 changes: 11 additions & 3 deletions NumberManager.Editor/SystemFontLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,25 @@ private static IEnumerable<SystemFontInfo> GetFontValues(RegistryKey key)
foreach (string valueName in key.GetValueNames())
{
string fontPath = key.GetValue(valueName) as string;
if (string.IsNullOrEmpty(fontPath) || (Path.GetExtension(fontPath).ToLower() != ".ttf"))
if (string.IsNullOrEmpty(fontPath))
{
continue;
}

string extension = Path.GetExtension(fontPath).ToLower();
if (!(extension == ".ttf" || extension == ".otf"))
{
continue;
}

if (!Path.IsPathRooted(fontPath))
{
fontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), fontPath);
}

string fontName = valueName.Replace(" (TrueType)", string.Empty);

string assetPath = Path.Combine("Assets", FONTS_FOLDER, $"{fontName}.ttf");
string assetPath = Path.Combine("Assets", FONTS_FOLDER, $"{fontName}{extension}");
var fontAsset = AssetDatabase.LoadAssetAtPath<Font>(assetPath);

yield return new SystemFontInfo(fontName, fontPath, fontAsset);
Expand Down Expand Up @@ -139,7 +146,8 @@ private void ImportSelectedFont(SystemFontInfo selection)
return;
}

string fontAssetPath = Path.Combine("_FONTS", $"{selection.Name}.ttf");
string extension = Path.GetExtension(selection.Path).ToLower();
string fontAssetPath = Path.Combine("_FONTS", $"{selection.Name}{extension}");
string targetPath = Path.Combine(Application.dataPath, fontAssetPath);

File.Copy(selection.Path, targetPath, true);
Expand Down
23 changes: 4 additions & 19 deletions NumberManager.Mod/NumberManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,6 @@ public static bool Load( UnityModManager.ModEntry entry )

ReloadConfigs();

try
{
var command = new CommandInfo()
{
name = "NM.ReloadConfig",
proc = ReloadConfigs,
min_arg_count = 0,
max_arg_count = 0,
help = "Reload all number configs",
};
Terminal.Shell.AddCommand(command);
Terminal.Autocomplete.Register(command);
}
catch (Exception ex)
{
modEntry.Logger.Error("Failed to register terminal commands: " + ex.ToString());
}

var harmony = new Harmony("cc.foxden.number_manager");
harmony.PatchAll(System.Reflection.Assembly.GetExecutingAssembly());

Expand All @@ -138,6 +120,8 @@ private static void ReloadConfigs(bool reapply)

private static void ReloadConfigs() => ReloadConfigs(true);


[RegisterCommand("NM.ReloadConfig", Help = "Reload all number configs", MinArgCount = 0, MaxArgCount = 0)]
private static void ReloadConfigs(CommandArg[] args) => ReloadConfigs();

private static void ReapplyNumbers()
Expand All @@ -162,7 +146,7 @@ private static void ReloadNumbersForSkin(SkinConfig skin)
{
ReapplyNumbersForUsers(newConfig);
}
modEntry.Logger.Log($"Reloaded number config for {skin.Name} {skin.CarId}");
modEntry.Logger.Log($"Loaded number config for {skin.Name} {skin.CarId}");
}

private static void ReapplyNumbersForUsers(NumberConfig config)
Expand Down Expand Up @@ -192,6 +176,7 @@ private static void LoadSchemes()
foreach (var skin in group.Skins.Where(s => !s.IsDefault))
{
LoadSchemeFromSkin(group.TrainCarType, skin);
modEntry.Logger.Log($"Loaded number config for {skin.Name} {skin.LiveryId}");
}
}
}
Expand Down

0 comments on commit b794b2b

Please sign in to comment.