diff --git a/Assets/Scripts/Game/Items/DaggerfallUnityItemMCP.cs b/Assets/Scripts/Game/Items/DaggerfallUnityItemMCP.cs index e1f05f66f0..4799fc3d48 100644 --- a/Assets/Scripts/Game/Items/DaggerfallUnityItemMCP.cs +++ b/Assets/Scripts/Game/Items/DaggerfallUnityItemMCP.cs @@ -153,9 +153,15 @@ public override string ArmourMod() public override string BookAuthor() { // %ba - BookFile bookFile = new BookFile(); + // Get book author from localized book file as first preference string name = GameManager.Instance.ItemHelper.GetBookFileName(parent.message); + LocalizedBook localizedBook = new LocalizedBook(); + if (localizedBook.OpenLocalizedBookFile(name)) + return localizedBook.Author; + + // Fallback to legacy book data + BookFile bookFile = new BookFile(); if (name != null) { if (!BookReplacement.TryImportBook(name, bookFile)) diff --git a/Assets/Scripts/Game/Items/ItemHelper.cs b/Assets/Scripts/Game/Items/ItemHelper.cs index 0a05b50e43..712477cf19 100644 --- a/Assets/Scripts/Game/Items/ItemHelper.cs +++ b/Assets/Scripts/Game/Items/ItemHelper.cs @@ -61,6 +61,7 @@ public class ItemHelper readonly Dictionary itemImages = new Dictionary(); readonly Dictionary containerImages = new Dictionary(); readonly Dictionary bookIDNameMapping = new Dictionary(); + readonly Dictionary localizedBookIDNameMapping = new Dictionary(); public delegate bool ItemUseHandler(DaggerfallUnityItem item, ItemCollection collection); Dictionary itemUseHandlers = new Dictionary(); @@ -550,6 +551,21 @@ public static ArtifactsSubTypes GetArtifactSubType(string itemShortName) /// The title of the bookd or defaultBookName if no name was found. public string GetBookTitle(int id, string defaultBookTitle) { + // Get cached localized book title if previously read + if (localizedBookIDNameMapping.ContainsKey(id)) + return localizedBookIDNameMapping[id]; + + // Get book title from localized book file as first preference + // Localized title will be cached so file is only read once + string filename = GetBookFileName(id); + LocalizedBook localizedBook = new LocalizedBook(); + if (localizedBook.OpenLocalizedBookFile(filename)) + { + localizedBookIDNameMapping.Add(id, localizedBook.Title); + return localizedBook.Title; + } + + // Fallback to legacy data string title; return bookIDNameMapping.TryGetValue(id, out title) ? title : defaultBookTitle; }