diff --git a/GameData/ConformalDecals/Plugins/ConformalDecals.dll b/GameData/ConformalDecals/Plugins/ConformalDecals.dll index 489ec7f..33734ea 100644 Binary files a/GameData/ConformalDecals/Plugins/ConformalDecals.dll and b/GameData/ConformalDecals/Plugins/ConformalDecals.dll differ diff --git a/GameData/ConformalDecals/Resources/ConformalDecals.cfg b/GameData/ConformalDecals/Resources/ConformalDecals.cfg index a2ddad2..0057e17 100644 --- a/GameData/ConformalDecals/Resources/ConformalDecals.cfg +++ b/GameData/ConformalDecals/Resources/ConformalDecals.cfg @@ -21,8 +21,6 @@ CONFORMALDECALS { shader = Solid Color (Alpha) } - fallbackFont = NotoSans-Regular SDF - FONT { name = LiberationSans SDF title = Liberation Sans diff --git a/Source/ConformalDecals/DecalConfig.cs b/Source/ConformalDecals/DecalConfig.cs index ec66d63..b681d8e 100644 --- a/Source/ConformalDecals/DecalConfig.cs +++ b/Source/ConformalDecals/DecalConfig.cs @@ -13,7 +13,6 @@ namespace ConformalDecals { private static Dictionary _fontList; private static int _decalLayer = 31; private static bool _selectableInFlight; - private static string _fallbackFontName = "NotoSans-Regular SDF"; private struct LegacyShaderEntry { public string name; @@ -51,8 +50,8 @@ namespace ConformalDecals { public static bool SelectableInFlight => _selectableInFlight; public static IEnumerable Fonts => _fontList.Values; - - public static TMP_FontAsset FallbackFont { get; private set; } + + public static DecalFont FallbackFont { get; private set; } public static bool IsBlacklisted(Shader shader) { return IsBlacklisted(shader.name); @@ -95,27 +94,14 @@ namespace ConformalDecals { } var allFonts = Resources.FindObjectsOfTypeAll(); - ParseUtil.ParseStringIndirect(ref _fallbackFontName, node, "fallbackFont"); - FallbackFont = allFonts.First(o => o.name == _fallbackFontName); - if (FallbackFont == null) Logging.LogError($"could not find find fallback font asset named {_fallbackFontName}"); - + foreach (var fontNode in node.GetNodes("FONT")) { try { - var name = ParseUtil.ParseString(fontNode, "name"); - if (string.IsNullOrEmpty(name)) throw new FormatException(); - - var fontAsset = allFonts.First(o => o.name == name); - if (fontAsset == null) throw new FormatException($"Could not find font asset named {name}"); - - if (!fontAsset.fallbackFontAssets.Contains(FallbackFont)) { - fontAsset.fallbackFontAssets.Add(FallbackFont); - } - - var font = new DecalFont(name, fontNode, fontAsset); + var font = new DecalFont(fontNode, allFonts); _fontList.Add(font.Name, font); } catch (Exception e) { - Logging.LogException($"Exception parsing font node:\n{fontNode.ToString()}\n", e); + Debug.LogException(e); } } } diff --git a/Source/ConformalDecals/Text/DecalFont.cs b/Source/ConformalDecals/Text/DecalFont.cs index 206dfa9..efa0b6e 100644 --- a/Source/ConformalDecals/Text/DecalFont.cs +++ b/Source/ConformalDecals/Text/DecalFont.cs @@ -40,15 +40,19 @@ namespace ConformalDecals.Text { public bool SmallCapsMask => (FontStyleMask & FontStyles.SmallCaps) != 0; - public DecalFont(string name, ConfigNode node, TMP_FontAsset font) { - if (name == null) throw new ArgumentNullException(nameof(name)); + public DecalFont(ConfigNode node, IEnumerable fontAssets) { if (node == null) throw new ArgumentNullException(nameof(node)); - if (font == null) throw new ArgumentNullException(nameof(font)); + if (fontAssets == null) throw new ArgumentNullException(nameof(fontAssets)); + + var name = ParseUtil.ParseString(node, "name"); + FontAsset = fontAssets.First(o => o.name == name); + if (FontAsset == null) { + throw new FormatException($"Could not find font asset named {name}"); + } Title = ParseUtil.ParseString(node, "title", true, name); FontStyle = (FontStyles) ParseUtil.ParseInt(node, "style", true); FontStyleMask = (FontStyles) ParseUtil.ParseInt(node, "styleMask", true); - FontAsset = font; } diff --git a/Source/ConformalDecals/Text/FontLoader.cs b/Source/ConformalDecals/Text/FontLoader.cs index 9ab93a5..01f16ad 100644 --- a/Source/ConformalDecals/Text/FontLoader.cs +++ b/Source/ConformalDecals/Text/FontLoader.cs @@ -11,13 +11,12 @@ namespace ConformalDecals.Text { [DatabaseLoaderAttrib(new[] {"decalfont"})] public class FontLoader : DatabaseLoader { private const string FallbackName = "NotoSans-Regular SDF"; - - public static TMP_FontAsset FallbackFont { get; private set; } + private static TMP_FontAsset _fallbackFont; public override IEnumerator Load(UrlDir.UrlFile urlFile, FileInfo fileInfo) { - if (FallbackFont == null) { - FallbackFont = Resources.FindObjectsOfTypeAll().First(o => o.name == FallbackName); - if (FallbackFont == null) Logging.LogError($"Could not find fallback font '{FallbackName}'"); + if (_fallbackFont == null) { + _fallbackFont = Resources.FindObjectsOfTypeAll().First(o => o.name == FallbackName); + if (_fallbackFont == null) Logging.LogError($"Could not find fallback font '{FallbackName}'"); } Logging.Log($"Loading font file '{urlFile.fullPath}'"); @@ -29,6 +28,7 @@ namespace ConformalDecals.Text { var loadedFonts = bundle.LoadAllAssets(); foreach (var font in loadedFonts) { Logging.Log($"Adding font {font.name}"); + font.fallbackFontAssets.Add(_fallbackFont); } }